feat: 耕作履歴ページ作成(#112) (#177)

#112 現在ページの表示を太く

#112 完了

Co-authored-by: miteruzo <miteruzo@naver.com>
Reviewed-on: #177
This commit was merged in pull request #177.
This commit is contained in:
2025-12-14 03:49:03 +09:00
parent 9a656a9e6e
commit f36837f0d8
7 changed files with 220 additions and 0 deletions
@@ -0,0 +1,90 @@
import axios from 'axios'
import toCamel from 'camelcase-keys'
import { useEffect, useState } from 'react'
import { Helmet } from 'react-helmet-async'
import { Link, useLocation } from 'react-router-dom'
import TagLink from '@/components/TagLink'
import PageTitle from '@/components/common/PageTitle'
import Pagination from '@/components/common/Pagination'
import MainArea from '@/components/layout/MainArea'
import { API_BASE_URL, SITE_TITLE } from '@/config'
import type { FC } from 'react'
import type { PostTagChange } from '@/types'
export default (() => {
const [changes, setChanges] = useState<PostTagChange[]> ([])
const [totalPages, setTotalPages] = useState<number> (0)
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)
useEffect (() => {
void (async () => {
const res = await axios.get (`${ API_BASE_URL }/posts/changes`,
{ params: { ...(id && { id }),
...(page && { page }),
...(limit && { limit }) } })
const data = toCamel (res.data as any, { deep: true }) as {
changes: PostTagChange[]
count: number }
setChanges (data.changes)
setTotalPages (Math.trunc ((data.count - 1) / limit))
}) ()
}, [location.search])
return (
<MainArea>
<Helmet>
<title>{`耕作履歴 | ${ SITE_TITLE }`}</title>
</Helmet>
<PageTitle>
{Boolean (id) && <>: 稿 {<Link to={`/posts/${ id }`}>#{id}</Link>}</>}
</PageTitle>
<table className="table-auto w-full border-collapse">
<thead>
<tr>
<th className="p-2 text-left">稿</th>
<th className="p-2 text-left"></th>
<th className="p-2 text-left"></th>
</tr>
</thead>
<tbody>
{changes.map (change => (
<tr key={`${ change.timestamp }-${ change.post.id }-${ change.tag.id }`}>
<td>
<Link to={`/posts/${ change.post.id }`}>
<img src={change.post.thumbnail || change.post.thumbnailBase || undefined}
alt={change.post.title || change.post.url}
title={change.post.title || change.post.url || undefined}
className="w-40"/>
</Link>
</td>
<td>
<TagLink tag={change.tag} withWiki={false} withCount={false}/>
{`${ change.changeType === 'add' ? '追加' : '削除' }`}
</td>
<td>
{change.user ? (
<Link to={`/users/${ change.user.id }`}>
{change.user.name}
</Link>) : 'bot 操作'}
<br/>
{change.timestamp}
</td>
</tr>))}
</tbody>
</table>
<Pagination page={page} totalPages={totalPages}/>
</MainArea>)
}) satisfies FC