-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fcc4514
commit ff50240
Showing
20 changed files
with
722 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,3 +44,4 @@ hot-module-replacement@0.5.3 | |
dev-error-overlay@0.1.2 | ||
http | ||
ostrio:files | ||
webapp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import '../imports/startup/client/Startup'; | ||
import 'bootstrap/dist/css/bootstrap.min.css'; | ||
import './style.css'; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,4 @@ | |
|
||
.landing-white-background img { | ||
margin-bottom: 50px; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Mongo } from 'meteor/mongo'; | ||
import SimpleSchema from 'simpl-schema'; | ||
|
||
class ModCardsCollection { | ||
constructor() { | ||
this.name = 'ModCardsCollection'; | ||
this.collection = new Mongo.Collection(this.name); | ||
this.schema = new SimpleSchema({ | ||
type: String, | ||
image: { type: String, optional: true }, | ||
cost: String, | ||
detail: String, | ||
address: String, | ||
createdAt: Date, | ||
owner: String, | ||
}); | ||
this.collection.attachSchema(this.schema); | ||
this.userPublicationName = `${this.name}.publication.user`; | ||
} | ||
} | ||
|
||
export const ModCards = new ModCardsCollection(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import React, { useState } from 'react'; | ||
import { Button, Card, Col, ListGroup, OverlayTrigger, Popover } from 'react-bootstrap'; | ||
import PropTypes from 'prop-types'; | ||
|
||
const ModCard = ({ modCard, onImageClick }) => { | ||
const [show, setShow] = useState(false); | ||
const detailLengthLimit = 55; | ||
|
||
const renderPopover = ( | ||
<Popover id="popover-basic"> | ||
<Popover.Body> | ||
{modCard.detail} | ||
</Popover.Body> | ||
</Popover> | ||
); | ||
|
||
const detailDisplay = modCard.detail.length > detailLengthLimit | ||
? `${modCard.detail.substring(0, detailLengthLimit)}...` | ||
: modCard.detail; | ||
|
||
return ( | ||
<Col> | ||
<Card style={{ width: '100%' }}> | ||
<Card.Body> | ||
<Card.Title style={{ fontSize: '1.1rem' }}>{modCard.type}</Card.Title> | ||
</Card.Body> | ||
<ListGroup className="list-group-flush"> | ||
<ListGroup.Item>Cost: {modCard.cost}</ListGroup.Item> | ||
{modCard.image && ( | ||
<Button style={{ background: 'white', color: 'black' }} onClick={() => onImageClick(modCard.image)}> | ||
Show Image | ||
</Button> | ||
)} | ||
<ListGroup.Item> | ||
Details: { /* space */} | ||
{modCard.detail.length > detailLengthLimit ? ( | ||
<OverlayTrigger | ||
trigger={['hover', 'focus']} | ||
placement="right" | ||
overlay={renderPopover} | ||
show={show} | ||
onToggle={(nextShow) => setShow(nextShow)} | ||
> | ||
<span style={{ cursor: 'pointer' }}> | ||
{detailDisplay} | ||
</span> | ||
</OverlayTrigger> | ||
) : ( | ||
detailDisplay | ||
)} | ||
<p className="p-2" style={{ fontSize: '0.6rem', color: '#6c757d' }}> | ||
{modCard.owner} @ {modCard.createdAt.toLocaleDateString('en-US')} | ||
</p> | ||
</ListGroup.Item> | ||
</ListGroup> | ||
</Card> | ||
</Col> | ||
); | ||
}; | ||
|
||
ModCard.propTypes = { | ||
modCard: PropTypes.shape({ | ||
type: PropTypes.string.isRequired, | ||
cost: PropTypes.string.isRequired, | ||
image: PropTypes.string, | ||
detail: PropTypes.string.isRequired, | ||
createdAt: PropTypes.instanceOf(Date).isRequired, | ||
owner: PropTypes.string.isRequired, | ||
_id: PropTypes.string.isRequired, | ||
}).isRequired, | ||
onImageClick: PropTypes.func.isRequired, | ||
}; | ||
|
||
export default ModCard; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import React, { useState } from 'react'; | ||
import { useLocation } from 'react-router-dom'; | ||
import { Meteor } from 'meteor/meteor'; | ||
import { Container, Row, Col, Card } from 'react-bootstrap'; | ||
import { AutoForm, TextField, LongTextField, SubmitField, ErrorsField, HiddenField } from 'uniforms-bootstrap5'; | ||
import swal from 'sweetalert'; | ||
import SimpleSchema2Bridge from 'uniforms-bridge-simple-schema-2'; | ||
import { ModCards } from '../../api/modcard/modcard'; | ||
import FileField from '../components/FileField'; | ||
|
||
const bridge = new SimpleSchema2Bridge(ModCards.schema); | ||
|
||
const AddModCard = () => { | ||
const [imageFile, setImageFile] = useState(null); | ||
let fRef = null; | ||
const user = Meteor.user(); | ||
|
||
const location = useLocation(); | ||
const currentAddress = location.state?.formattedAddress || ''; | ||
|
||
const handleImageChange = (file) => { | ||
setImageFile(file); | ||
}; | ||
|
||
const submit = (data) => { | ||
const { image, ...modCardData } = data; | ||
modCardData.address = currentAddress; | ||
|
||
// eslint-disable-next-line no-shadow | ||
const insertModCard = (modCardData) => { | ||
ModCards.collection.insert(modCardData, (error) => { | ||
if (error) { | ||
swal('Error', error.message, 'error'); | ||
} else { | ||
swal('Success', 'ModCard added successfully', 'success'); | ||
fRef.reset(); | ||
} | ||
}); | ||
}; | ||
|
||
if (imageFile) { | ||
const reader = new FileReader(); | ||
reader.onloadend = function () { | ||
const fileData = reader.result; | ||
|
||
Meteor.call('uploadImage', fileData, (error, imageUrl) => { | ||
if (error) { | ||
swal('Error', 'Failed to upload image.', 'error'); | ||
} else { | ||
modCardData.image = imageUrl; | ||
insertModCard(modCardData); | ||
} | ||
}); | ||
}; | ||
reader.readAsDataURL(imageFile); | ||
} else { | ||
insertModCard(modCardData); | ||
} | ||
}; | ||
|
||
return ( | ||
<Container className="py-3"> | ||
<Row className="justify-content-center"> | ||
<Col xs={6}> | ||
<Col className="text-center"><h2>Add ModCard</h2></Col> | ||
<AutoForm ref={ref => { fRef = ref; }} schema={bridge} onSubmit={submit}> | ||
<Card> | ||
<Card.Body> | ||
<TextField name="type" /> | ||
<div className="mb-3"> | ||
<FileField name="image" onChange={handleImageChange} /> | ||
</div> | ||
<TextField name="cost" /> | ||
<LongTextField name="detail" /> | ||
<ErrorsField /> | ||
<SubmitField value="Submit" /> | ||
<HiddenField name="createdAt" value={new Date()} /> | ||
<HiddenField name="address" value={currentAddress} /> | ||
{user ? <HiddenField name="owner" value={user.username} /> : null} | ||
</Card.Body> | ||
</Card> | ||
</AutoForm> | ||
</Col> | ||
</Row> | ||
</Container> | ||
); | ||
}; | ||
|
||
export default AddModCard; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.