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

93 lines
2.8 KiB

  1. import React, { useEffect, useState } from 'react'
  2. import { Helmet } from 'react-helmet'
  3. import { Link } from 'react-router-dom'
  4. import axios from 'axios'
  5. import MainArea from '@/components/layout/MainArea'
  6. import { API_BASE_URL, SITE_TITLE } from '@/config'
  7. import SectionTitle from '@/components/common/SectionTitle'
  8. import type { Category, WikiPage } from '@/types'
  9. export default () => {
  10. const [title, setTitle] = useState ('')
  11. const [text, setText] = useState ('')
  12. const [category, setCategory] = useState<Category | null> (null)
  13. const [results, setResults] = useState<WikiPage[]> ([])
  14. const search = () => {
  15. void (axios.get (`${ API_BASE_URL }/wiki/search`, { params: { title } })
  16. .then (res => setResults (res.data)))
  17. }
  18. const handleSearch = (e: React.FormEvent) => {
  19. e.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. <SectionTitle className="text-xl mb-4">Wiki</SectionTitle>
  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>
  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}>
  69. <td className="p-2">
  70. <Link to={`/wiki/${ encodeURIComponent (page.title) }`}>
  71. {page.title}
  72. </Link>
  73. </td>
  74. <td className="p-2 text-gray-100 text-sm">
  75. {page.updated_at}
  76. </td>
  77. </tr>))}
  78. </tbody>
  79. </table>
  80. </div>
  81. </MainArea>)
  82. }