import React, { useState } from 'react' import { openBoard } from '../../../../components/system' import Router from 'next/router' import { makeStyles } from '@material-ui/core/styles' import { Typography, Box, Card, CardHeader, Divider, CardActions, CardContent, TextField, Button, Avatar, Tabs, Tab } from '@material-ui/core' import SendIcon from '@material-ui/icons/Send' import AddIcon from '@material-ui/icons/Add' function TabPanel(props) { const { children, value, index, ...other } = props return ( ) } 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) }, tabContainer: { flexGrow: 1, backgroundColor: theme.palette.background.paper, display: 'flex', }, tabPanel: { flexGrow: 1 }, tabs: { borderRight: `1px solid ${theme.palette.divider}`, }, })) 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() // State const [title, setTitle] = useState('') const [cid, setCID] = useState('') const [content, setContent] = useState('') const [tab, setTab] = useState(0) // Actions const submitPost = () => { const payload = { title } if (tab === 0) payload.text = content if (tab === 2) payload.multihash = cid return createPost(boardId, payload) } return } title="Post Something" subheader={ Your post will be published to the {boardId} board } /> setTitle(e.target.value)} autoFocus fullWidth />
setTab(value)} className={classes.tabs} > setContent(event.target.value)} /> WIP setCID(e.target.value)} helperText="Enter the CID or Multihash of existing IPFS content" fullWidth />
} CreatePost.getInitialProps = ({ query }) => { return { boardId: query.board } }