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

96 lines
2.3 KiB

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