import React, { useState } from 'react'; import { useLocation, useHistory } from 'react-router-dom'; import qs from 'qs'; import Button from './Button'; import MessageInput from './MessageInput'; import { post, update } from '../api'; /** * @param {{visitor: import('../api').User}} props */ export default function Post({ visitor }) { const location = useLocation(); const history = useHistory(); let draftMessage = (location.state || {}).draft || {}; 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; history.push(`/${visitor.uname}/${msg.mid}`); } }).catch(console.log); }; let appendTag = (tag) => { setDraft(prevDraft => { return `${prevDraft || ''} *${tag} `; }); }; return (
*weather It is very cold today! { visitor.tagStats &&

Tags:

{ visitor.tagStats.map(t => { return (); }) }
}
); }