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

74 lines
2.5 KiB

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