ぼざクリタグ広場 https://hub.nizika.monster
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

117 lines
3.6 KiB

  1. import { useQuery } from '@tanstack/react-query'
  2. import { motion } from 'framer-motion'
  3. import { useEffect } from 'react'
  4. import { Helmet } from 'react-helmet-async'
  5. import { useLocation } from 'react-router-dom'
  6. import TagLink from '@/components/TagLink'
  7. import PrefetchLink from '@/components/PrefetchLink'
  8. import PageTitle from '@/components/common/PageTitle'
  9. import Pagination from '@/components/common/Pagination'
  10. import MainArea from '@/components/layout/MainArea'
  11. import { SITE_TITLE } from '@/config'
  12. import { fetchPostChanges } from '@/lib/posts'
  13. import { postsKeys } from '@/lib/queryKeys'
  14. import { cn, dateString } from '@/lib/utils'
  15. import type { FC } from 'react'
  16. export default (() => {
  17. const location = useLocation ()
  18. const query = new URLSearchParams (location.search)
  19. const id = query.get ('id')
  20. const page = Number (query.get ('page') ?? 1)
  21. const limit = Number (query.get ('limit') ?? 20)
  22. // 投稿列の結合で使用
  23. let rowsCnt: number
  24. const { data, isLoading: loading } = useQuery ({
  25. queryKey: postsKeys.changes ({ ...(id && { id }), page, limit }),
  26. queryFn: () => fetchPostChanges ({ ...(id && { id }), page, limit }) })
  27. const changes = data?.changes ?? []
  28. const totalPages = data ? Math.ceil (data.count / limit) : 0
  29. useEffect (() => {
  30. document.querySelector ('table')?.scrollIntoView ({ behavior: 'smooth' })
  31. }, [location.search])
  32. return (
  33. <MainArea>
  34. <Helmet>
  35. <title>{`耕作履歴 | ${ SITE_TITLE }`}</title>
  36. </Helmet>
  37. <PageTitle>
  38. 耕作履歴
  39. {id && <>: 投稿 {<PrefetchLink to={`/posts/${ id }`}>#{id}</PrefetchLink>}</>}
  40. </PageTitle>
  41. {loading ? 'Loading...' : (
  42. <>
  43. <table className="table-auto w-full border-collapse">
  44. <thead className="border-b-2 border-black dark:border-white">
  45. <tr>
  46. <th className="p-2 text-left">投稿</th>
  47. <th className="p-2 text-left">変更</th>
  48. <th className="p-2 text-left">日時</th>
  49. </tr>
  50. </thead>
  51. <tbody>
  52. {changes.map ((change, i) => {
  53. let withPost = i === 0 || change.post.id !== changes[i - 1].post.id
  54. if (withPost)
  55. {
  56. rowsCnt = 1
  57. for (let j = i + 1;
  58. (j < changes.length
  59. && change.post.id === changes[j].post.id);
  60. ++j)
  61. ++rowsCnt
  62. }
  63. return (
  64. <tr key={`${ change.timestamp }-${ change.post.id }-${ change.tag.id }`}
  65. className={cn ('even:bg-gray-100 dark:even:bg-gray-700',
  66. withPost && 'border-t')}>
  67. {withPost && (
  68. <td className="align-top p-2 bg-white dark:bg-[#242424] border-r"
  69. rowSpan={rowsCnt}>
  70. <PrefetchLink to={`/posts/${ change.post.id }`}>
  71. <motion.div
  72. layoutId={`page-${ change.post.id }`}
  73. transition={{ type: 'spring',
  74. stiffness: 500,
  75. damping: 40,
  76. mass: .5 }}>
  77. <img src={change.post.thumbnail || change.post.thumbnailBase || undefined}
  78. alt={change.post.title || change.post.url}
  79. title={change.post.title || change.post.url || undefined}
  80. className="w-40"/>
  81. </motion.div>
  82. </PrefetchLink>
  83. </td>)}
  84. <td className="p-2">
  85. <TagLink tag={change.tag} withWiki={false} withCount={false}/>
  86. {`を${ change.changeType === 'add' ? '記載' : '消除' }`}
  87. </td>
  88. <td className="p-2">
  89. {change.user
  90. ? (
  91. <PrefetchLink to={`/users/${ change.user.id }`}>
  92. {change.user.name}
  93. </PrefetchLink>)
  94. : 'bot 操作'}
  95. <br/>
  96. {dateString (change.timestamp)}
  97. </td>
  98. </tr>)
  99. })}
  100. </tbody>
  101. </table>
  102. <Pagination page={page} totalPages={totalPages}/>
  103. </>)}
  104. </MainArea>)
  105. }) satisfies FC