import { useQuery } from '@tanstack/react-query' import { Helmet } from 'react-helmet-async' import { useLocation } from 'react-router-dom' import TagLink from '@/components/TagLink' import PrefetchLink from '@/components/PrefetchLink' import PageTitle from '@/components/common/PageTitle' import Pagination from '@/components/common/Pagination' import MainArea from '@/components/layout/MainArea' import { SITE_TITLE } from '@/config' import { fetchPostChanges } from '@/lib/posts' import { postsKeys } from '@/lib/queryKeys' import { cn } from '@/lib/utils' import type { FC } from 'react' export default (() => { const location = useLocation () const query = new URLSearchParams (location.search) const id = query.get ('id') const page = Number (query.get ('page') ?? 1) const limit = Number (query.get ('limit') ?? 20) // 投稿列の結合で使用 let rowsCnt: number const { data, isLoading: loading } = useQuery ({ queryKey: postsKeys.changes ({ ...(id && { id }), page, limit }), queryFn: () => fetchPostChanges ({ ...(id && { id }), page, limit }) }) const changes = data?.changes ?? [] const totalPages = data ? Math.ceil (data.count / limit) : 0 return ( {`耕作履歴 | ${ SITE_TITLE }`} 耕作履歴 {id && <>: 投稿 {#{id}}} {loading ? 'Loading...' : ( <> {changes.map ((change, i) => { let withPost = i === 0 || change.post.id !== changes[i - 1].post.id if (withPost) { rowsCnt = 1 for (let j = i + 1; (j < changes.length && change.post.id === changes[j].post.id); ++j) ++rowsCnt } return ( {withPost && ( )} ) })}
投稿 変更 日時
{change.post.title {`を${ change.changeType === 'add' ? '記載' : '消除' }`} {change.user ? ( {change.user.name} ) : 'bot 操作'}
{change.timestamp}
)}
) }) satisfies FC