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

51 lines
1.4 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 { useLocation, useParams } from 'react-router-dom'
  6. import PageTitle from '@/components/common/PageTitle'
  7. import MainArea from '@/components/layout/MainArea'
  8. import { API_BASE_URL, SITE_TITLE } from '@/config'
  9. import { cn } from '@/lib/utils'
  10. import type { WikiPageDiff } from '@/types'
  11. export default () => {
  12. const { id } = useParams ()
  13. const location = useLocation ()
  14. const [diff, setDiff] = useState<WikiPageDiff | null> (null)
  15. const query = new URLSearchParams (location.search)
  16. const from = query.get ('from')
  17. const to = query.get ('to')
  18. useEffect (() => {
  19. void (async () => {
  20. const res = await axios.get (`${ API_BASE_URL }/wiki/${ id }/diff`, { params: { from, to } })
  21. setDiff (toCamel (res.data as any, { deep: true }) as WikiPageDiff)
  22. }) ()
  23. }, [])
  24. return (
  25. <MainArea>
  26. <Helmet>
  27. <title>{`Wiki 差分: ${ diff?.title } | ${ SITE_TITLE }`}</title>
  28. </Helmet>
  29. <PageTitle>{diff?.title}</PageTitle>
  30. <div className="prose mx-auto p-4">
  31. {diff
  32. ? (
  33. diff.diff.map (d => (
  34. <span className={cn (d.type === 'added' && 'bg-green-200 dark:bg-green-800',
  35. d.type === 'removed' && 'bg-red-200 dark:bg-red-800')}>
  36. {d.content == '\n' ? <br /> : d.content}
  37. </span>)))
  38. : 'Loading...'}
  39. </div>
  40. </MainArea>)
  41. }