1
0
mirror of https://github.com/fazo96/ipfs-boards synced 2025-01-30 15:44:20 +01:00
ipfs-boards/pages/b/[board]/p/new.js

78 lines
2.2 KiB
JavaScript
Raw Normal View History

2019-10-26 23:58:20 +02:00
import React, { useState } from 'react'
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'
import AddIcon from '@material-ui/icons/Add'
2019-10-26 23:58:20 +02: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('')
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
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
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
/>
<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>
}
CreatePost.getInitialProps = ({ query }) => {
return { boardId: query.board }
}