ぼざクリ タグ広場 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.
 
 
 
 
 
 

78 lines
2.6 KiB

  1. import axios from 'axios'
  2. import toCamel from 'camelcase-keys'
  3. import { useEffect, useState } from 'react'
  4. import { Helmet } from 'react-helmet-async'
  5. import { Link, useLocation, useParams } from 'react-router-dom'
  6. import MainArea from '@/components/layout/MainArea'
  7. import { API_BASE_URL, SITE_TITLE } from '@/config'
  8. import type { WikiPageChange } from '@/types'
  9. export default () => {
  10. const [changes, setChanges] = useState<WikiPageChange[]> ([])
  11. const location = useLocation ()
  12. const query = new URLSearchParams (location.search)
  13. const id = query.get ('id')
  14. useEffect (() => {
  15. void (axios.get (`${ API_BASE_URL }/wiki/changes`, id && { params: { id } })
  16. .then (res => setChanges (toCamel (res.data, { deep: true }))))
  17. }, [location.search])
  18. return (
  19. <MainArea>
  20. <Helmet>
  21. <title>{`Wiki 変更履歴 | ${ SITE_TITLE }`}</title>
  22. </Helmet>
  23. <table className="table-auto w-full border-collapse">
  24. <thead>
  25. <tr>
  26. <th></th>
  27. <th className="p-2 text-left">タイトル</th>
  28. <th className="p-2 text-left">変更</th>
  29. <th className="p-2 text-left">日時</th>
  30. </tr>
  31. </thead>
  32. <tbody>
  33. {changes.map (change => (
  34. <tr key={change.sha}>
  35. <td>
  36. {change.changeType === 'update' && (
  37. <Link to={`/wiki/${ change.wikiPage.id }/diff?from=${ change.pred }&to=${ change.sha }`}>
  38. 差分
  39. </Link>)}
  40. </td>
  41. <td className="p-2">
  42. <Link to={`/wiki/${ encodeURIComponent (change.wikiPage.title) }?version=${ change.sha }`}>
  43. {change.wikiPage.title}
  44. </Link>
  45. </td>
  46. <td className="p-2">
  47. {(() => {
  48. switch (change.changeType)
  49. {
  50. case 'create':
  51. return '新規'
  52. case 'update':
  53. return '更新'
  54. case 'delete':
  55. return '削除'
  56. }
  57. }) ()}
  58. </td>
  59. <td className="p-2">
  60. <Link to={`/users/${ change.user.id }`}>
  61. {change.user.name}
  62. </Link>
  63. <br />
  64. {change.timestamp}
  65. </td>
  66. </tr>))}
  67. </tbody>
  68. </table>
  69. </MainArea>)
  70. }