import axios from 'axios' import toCamel from 'camelcase-keys' import { useEffect, useState } from 'react' import { Accordion, AccordionItem, AccordionItemButton, AccordionItemHeading, AccordionItemPanel } from 'react-accessible-accordion' import { FaChevronDown, FaChevronUp } from 'react-icons/fa' import { Link } from 'react-router-dom' import ThreadNewForm from '@/components/threads/ThreadNewForm' import { API_BASE_URL } from '@/config' import type { Thread } from '@/types' export default () => { const [formOpen, setFormOpen] = useState (false) const [loading, setLoading] = useState (true) const [threads, setThreads] = useState ([]) const fetchThreads = async () => { setLoading (true) try { const res = await axios.get (`${ API_BASE_URL }/threads`) const data = toCamel (res.data as any, { deep: true }) as Thread[] const threads = data.filter (t => t.id !== 2) setThreads (threads.map (t => ({ ...t, createdAt: (new Date (t.createdAt)).toLocaleString ('ja-JP-u-ca-japanese'), updatedAt: (new Date (t.updatedAt)).toLocaleString ('ja-JP-u-ca-japanese') }))) } catch { ; } setLoading (false) } useEffect (() => { document.title = 'キケッツチャンネル お絵描き掲示板' fetchThreads () }, []) return ( <> setFormOpen (!formOpen)} className="mb-4 mx-auto"> {formOpen ? : } 新規スレッド
{loading ? 'Loading...' : ( threads.length > 0 ? threads.map (thread => (

{thread.name}

{thread.description?.replaceAll ('\r\n', '\n') .replaceAll ('\r', '\n') .split ('\n') .map ((l, i) =>

{l}

)}
{thread.postCount} レス {thread.updatedAt} 更新 {thread.createdAt} 作成
)) : 'スレないよ(笑).')}
) }