2019-10-26 23:58:20 +02:00
|
|
|
import React, { useState } from 'react'
|
2019-10-27 12:10:03 +01:00
|
|
|
import { openBoard } from '../../../../components/system'
|
|
|
|
import Router from 'next/router'
|
|
|
|
import { makeStyles } from '@material-ui/core/styles'
|
|
|
|
import { Card, CardHeader, CardContent, TextField, Button, Avatar } from '@material-ui/core'
|
2019-10-26 23:58:20 +02:00
|
|
|
import SendIcon from '@material-ui/icons/Send'
|
2019-10-27 12:10:03 +01:00
|
|
|
import AddIcon from '@material-ui/icons/Add'
|
2019-10-26 23:58:20 +02:00
|
|
|
|
2019-10-27 12:10:03 +01:00
|
|
|
const useStyles = makeStyles(theme => ({
|
|
|
|
card: {
|
|
|
|
maxWidth: 600,
|
|
|
|
margin: theme.spacing(2),
|
|
|
|
marginLeft: 'auto',
|
|
|
|
marginRight: 'auto'
|
|
|
|
},
|
|
|
|
field: {
|
|
|
|
marginTop: theme.spacing(2),
|
|
|
|
marginBottom: theme.spacing(2),
|
|
|
|
},
|
|
|
|
secondaryButton: {
|
|
|
|
marginLeft: theme.spacing(2)
|
|
|
|
},
|
|
|
|
buttonIcon: {
|
|
|
|
marginLeft: theme.spacing(1)
|
|
|
|
}
|
|
|
|
}))
|
|
|
|
|
|
|
|
async function createPost(boardId, postData) {
|
|
|
|
const board = await openBoard(boardId)
|
|
|
|
await board.addPost(postData)
|
|
|
|
Router.push(`/b/${boardId}`)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default function CreatePost({ boardId }) {
|
|
|
|
const classes = useStyles()
|
2019-10-26 23:58:20 +02:00
|
|
|
const [title, setTitle] = useState('')
|
2019-10-27 12:10:03 +01:00
|
|
|
return <Card className={classes.card}>
|
|
|
|
<CardHeader
|
|
|
|
avatar={<Avatar><AddIcon /></Avatar>}
|
|
|
|
title="Post Something"
|
|
|
|
subheader={<React.Fragment>
|
|
|
|
Your post will be published to the <b>{boardId}</b> board
|
|
|
|
</React.Fragment>}
|
|
|
|
/>
|
2019-10-26 23:58:20 +02:00
|
|
|
<CardContent>
|
|
|
|
<TextField
|
2019-10-27 12:10:03 +01:00
|
|
|
className={classes.field}
|
|
|
|
variant="outlined"
|
2019-10-26 23:58:20 +02:00
|
|
|
label="Title"
|
|
|
|
placeholder="What is your Post about?"
|
|
|
|
value={title}
|
|
|
|
onChange={e => setTitle(e.target.value)}
|
|
|
|
autoFocus
|
2019-10-27 12:10:03 +01:00
|
|
|
fullWidth
|
|
|
|
/>
|
|
|
|
<TextField
|
|
|
|
className={classes.field}
|
|
|
|
variant="filled"
|
|
|
|
label="CID"
|
|
|
|
placeholder="Paste the IPFS CID or your post content (WIP)"
|
|
|
|
value={title}
|
|
|
|
onChange={e => setTitle(e.target.value)}
|
|
|
|
fullWidth
|
2019-10-26 23:58:20 +02:00
|
|
|
/>
|
2019-10-27 12:10:03 +01:00
|
|
|
<Button variant="contained" color="primary" onClick={() => createPost(boardId, { title })}>
|
|
|
|
Submit <SendIcon className={classes.buttonIcon} />
|
|
|
|
</Button>
|
|
|
|
<Button className={classes.secondaryButton} onClick={() => Router.push(`/b/${boardId}`)}>
|
|
|
|
Cancel
|
2019-10-26 23:58:20 +02:00
|
|
|
</Button>
|
|
|
|
</CardContent>
|
|
|
|
</Card>
|
|
|
|
}
|
2019-10-27 12:10:03 +01:00
|
|
|
|
|
|
|
CreatePost.getInitialProps = ({ query }) => {
|
|
|
|
return { boardId: query.board }
|
|
|
|
}
|