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

94 lines
2.2 KiB

  1. import { useEffect, useState } from 'react'
  2. import { Helmet } from 'react-helmet-async'
  3. import PrefetchLink from '@/components/PrefetchLink'
  4. import SectionTitle from '@/components/common/SectionTitle'
  5. import MainArea from '@/components/layout/MainArea'
  6. import { SITE_TITLE } from '@/config'
  7. import { apiGet } from '@/lib/api'
  8. import type { FormEvent } from 'react'
  9. import type { WikiPage } from '@/types'
  10. export default () => {
  11. const [title, setTitle] = useState ('')
  12. const [text, setText] = useState ('')
  13. const [results, setResults] = useState<WikiPage[]> ([])
  14. const search = async () => {
  15. setResults (await apiGet ('/wiki', { params: { title } }))
  16. }
  17. const handleSearch = (ev: FormEvent) => {
  18. ev.preventDefault ()
  19. search ()
  20. }
  21. useEffect (() => {
  22. search ()
  23. }, [])
  24. return (
  25. <MainArea>
  26. <Helmet>
  27. <title>Wiki | {SITE_TITLE}</title>
  28. </Helmet>
  29. <div className="max-w-xl">
  30. <SectionTitle>Wiki</SectionTitle>
  31. <form onSubmit={handleSearch} className="space-y-2">
  32. {/* タイトル */}
  33. <div>
  34. <label>タイトル:</label><br />
  35. <input type="text"
  36. value={title}
  37. onChange={e => setTitle (e.target.value)}
  38. className="border p-1 w-full" />
  39. </div>
  40. {/* 内容 */}
  41. <div>
  42. <label>内容:</label><br />
  43. <input type="text"
  44. value={text}
  45. onChange={e => setText (e.target.value)}
  46. className="border p-1 w-full" />
  47. </div>
  48. {/* 検索 */}
  49. <div className="py-3">
  50. <button type="submit"
  51. className="bg-blue-500 text-white px-4 py-2 rounded">
  52. 検索
  53. </button>
  54. </div>
  55. </form>
  56. </div>
  57. <div className="mt-4">
  58. <table className="table-auto w-full border-collapse">
  59. <thead>
  60. <tr>
  61. <th className="p-2 text-left">タイトル</th>
  62. <th className="p-2 text-left">最終更新</th>
  63. </tr>
  64. </thead>
  65. <tbody>
  66. {results.map (page => (
  67. <tr key={page.id}>
  68. <td className="p-2">
  69. <PrefetchLink to={`/wiki/${ encodeURIComponent (page.title) }`}>
  70. {page.title}
  71. </PrefetchLink>
  72. </td>
  73. <td className="p-2 text-gray-100 text-sm">
  74. {page.updatedAt}
  75. </td>
  76. </tr>))}
  77. </tbody>
  78. </table>
  79. </div>
  80. </MainArea>)
  81. }