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

41 lines
1.0 KiB

  1. import { useParams } from 'react-router-dom'
  2. import { useEffect, useState } from 'react'
  3. import axios from 'axios'
  4. const WikiEditPage = () => {
  5. const { name } = useParams<{ name: string }> ()
  6. const [html, setHtml] = useState('')
  7. const [loading, setLoading] = useState(true)
  8. useEffect(() => {
  9. const link = document.createElement('link')
  10. link.rel = 'stylesheet'
  11. link.href = '/wiki/custom.css' // Gollum の静的 CSS にアクセスできるようにしとく
  12. document.head.appendChild(link)
  13. return () => {
  14. document.head.removeChild(link)
  15. }
  16. }, [])
  17. useEffect(() => {
  18. setLoading(true)
  19. axios
  20. .get(`/api/wiki/edit/${encodeURIComponent(name)}`, {
  21. headers: { 'X-Transfer-Code': localStorage.getItem('user_code') || '' }
  22. })
  23. .then((res) => setHtml(res.data))
  24. .finally(() => setLoading(false))
  25. }, [name])
  26. return loading ? (
  27. <p>読み込み中...</p>
  28. ) : (
  29. <div dangerouslySetInnerHTML={{ __html: html }} />
  30. )
  31. }
  32. export default WikiEditPage