import { useState } from 'react'; import { useLocation, useNavigate } from 'react-router-dom'; import qs from 'qs'; import Button from './Button'; import MessageInput from './MessageInput'; import { post, update } from '../api'; import { useVisitor } from './VisitorContext'; import { Helmet } from 'react-helmet'; /** * */ export default function Post() { const location = useLocation(); const navigate = useNavigate(); const [visitor] = useVisitor(); let draftMessage = (location.state || {}).data || {}; let [draft, setDraft] = useState(draftMessage.body); let params = qs.parse(window.location.search.substring(1)); let postMessage = (template) => { const { attach, body } = template; const postAction = draftMessage.mid ? update(draftMessage.mid, 0, body) : post(body, attach); postAction .then(response => { if (response.status === 200) { const msg = response.data.newMessage; navigate(`/${visitor.uname}/${msg.mid}`); } }).catch(console.log); }; let appendTag = (tag) => { setDraft(prevDraft => { return `${prevDraft || ''} *${tag} `; }); }; return (
Tags:
{ visitor.tagStats.map(t => { return (); }) }