Browse Source

feat: #112 の修正(#190) (#191)

Merge branch 'main' into feature/190

#190

Co-authored-by: miteruzo <miteruzo@naver.com>
Reviewed-on: https://git.miteruzo.com/miteruzo/btrc-hub/pulls/191
pull/192/head
みてるぞ 1 week ago
parent
commit
c93f8585a1
2 changed files with 47 additions and 29 deletions
  1. +4
    -0
      frontend/src/components/TagDetailSidebar.tsx
  2. +43
    -29
      frontend/src/pages/posts/PostHistoryPage.tsx

+ 4
- 0
frontend/src/components/TagDetailSidebar.tsx View File

@@ -1,5 +1,6 @@
import { AnimatePresence, motion } from 'framer-motion'
import { useEffect, useState } from 'react'
import { Link } from 'react-router-dom'

import TagLink from '@/components/TagLink'
import TagSearch from '@/components/TagSearch'
@@ -128,6 +129,9 @@ export default (({ post }: Props) => {
&& `${ (new Date (post.originalCreatedBefore)).toLocaleString () } より前`}
</>)}
</li>
<li>
<Link to={`/posts/changes?id=${ post.id }`}>履歴</Link>
</li>
</ul>
</div>)}
</motion.div>


+ 43
- 29
frontend/src/pages/posts/PostHistoryPage.tsx View File

@@ -25,19 +25,20 @@ export default (() => {
const page = Number (query.get ('page') ?? 1)
const limit = Number (query.get ('limit') ?? 20)

// 投稿列の結合で使用
let rowsCnt: number

useEffect (() => {
void (async () => {
const res = await axios.get (`${ API_BASE_URL }/posts/changes`,
{ params: { ...(id && { id }),
...(page && { page }),
...(limit && { limit }) } })
{ params: { ...(id && { id }), page, 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))
setTotalPages (Math.ceil (data.count / limit))
}) ()
}, [location.search])
}, [id, page, limit])

return (
<MainArea>
@@ -47,7 +48,7 @@ export default (() => {

<PageTitle>
耕作履歴
{Boolean (id) && <>: 投稿 {<Link to={`/posts/${ id }`}>#{id}</Link>}</>}
{id && <>: 投稿 {<Link to={`/posts/${ id }`}>#{id}</Link>}</>}
</PageTitle>

<table className="table-auto w-full border-collapse">
@@ -59,29 +60,42 @@ export default (() => {
</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>))}
{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 (
<tr key={`${ change.timestamp }-${ change.post.id }-${ change.tag.id }`}>
{withPost && (
<td className="align-top" rowSpan={rowsCnt}>
<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>



Loading…
Cancel
Save