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

Merged
みてるぞ merged 2 commits from feature/190 into main 2 weeks ago
  1. +4
    -0
      frontend/src/components/TagDetailSidebar.tsx
  2. +24
    -10
      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 { AnimatePresence, motion } from 'framer-motion'
import { useEffect, useState } from 'react' import { useEffect, useState } from 'react'
import { Link } from 'react-router-dom'


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


+ 24
- 10
frontend/src/pages/posts/PostHistoryPage.tsx View File

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


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

useEffect (() => { useEffect (() => {
void (async () => { void (async () => {
const res = await axios.get (`${ API_BASE_URL }/posts/changes`, 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 { const data = toCamel (res.data as any, { deep: true }) as {
changes: PostTagChange[] changes: PostTagChange[]
count: number } count: number }
setChanges (data.changes) setChanges (data.changes)
setTotalPages (Math.trunc ((data.count - 1) / limit))
setTotalPages (Math.ceil (data.count / limit))
}) () }) ()
}, [location.search])
}, [id, page, limit])


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


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


<table className="table-auto w-full border-collapse"> <table className="table-auto w-full border-collapse">
@@ -59,16 +60,28 @@ export default (() => {
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{changes.map (change => (
{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 }`}> <tr key={`${ change.timestamp }-${ change.post.id }-${ change.tag.id }`}>
<td>
{withPost && (
<td className="align-top" rowSpan={rowsCnt}>
<Link to={`/posts/${ change.post.id }`}> <Link to={`/posts/${ change.post.id }`}>
<img src={change.post.thumbnail || change.post.thumbnailBase || undefined} <img src={change.post.thumbnail || change.post.thumbnailBase || undefined}
alt={change.post.title || change.post.url} alt={change.post.title || change.post.url}
title={change.post.title || change.post.url || undefined} title={change.post.title || change.post.url || undefined}
className="w-40"/> className="w-40"/>
</Link> </Link>
</td>
</td>)}
<td> <td>
<TagLink tag={change.tag} withWiki={false} withCount={false}/> <TagLink tag={change.tag} withWiki={false} withCount={false}/>
{`を${ change.changeType === 'add' ? '追加' : '削除' }`} {`を${ change.changeType === 'add' ? '追加' : '削除' }`}
@@ -81,7 +94,8 @@ export default (() => {
<br/> <br/>
{change.timestamp} {change.timestamp}
</td> </td>
</tr>))}
</tr>)
})}
</tbody> </tbody>
</table> </table>




Loading…
Cancel
Save