import axios from 'axios' import { useState } from 'react' import TextArea from '@/components/common/TextArea' import { Button } from '@/components/ui/button' import { API_BASE_URL } from '@/config' import type { Post } from '@/types' type Props = { post: Post onSave: (newPost: Post) => void } export default ({ post, onSave }: Props) => { const [title, setTitle] = useState (post.title) const [tags, setTags] = useState (post.tags .filter (t => t.category !== 'nico') .map (t => t.name) .join (' ')) const handleSubmit = async () => { const res = await axios.put (`${ API_BASE_URL }/posts/${ post.id }`, { title, tags }, { headers: { 'Content-Type': 'multipart/form-data', 'X-Transfer-Code': localStorage.getItem ('user_code') || '' } } ) const data = res.data as Post onSave ({ ...post, title: data.title, tags: data.tags } as Post) } return (
{/* タイトル */}
setTitle (e.target.value)} />
{/* タグ */}