Browse Source

#140

pull/254/head
みてるぞ 1 week ago
parent
commit
a39b86c456
3 changed files with 13 additions and 6 deletions
  1. +3
    -4
      frontend/src/App.tsx
  2. +6
    -0
      frontend/src/lib/api.ts
  3. +4
    -2
      frontend/src/pages/wiki/WikiSearchPage.tsx

+ 3
- 4
frontend/src/App.tsx View File

@@ -1,11 +1,10 @@
import axios from 'axios'
import { useEffect, useState } from 'react'
import { BrowserRouter, Navigate, Route, Routes, useLocation } from 'react-router-dom'

import RouteBlockerOverlay from '@/components/RouteBlockerOverlay'
import TopNav from '@/components/TopNav'
import { Toaster } from '@/components/ui/toaster'
import { apiPost } from '@/lib/api'
import { apiPost, isApiError } from '@/lib/api'
import NicoTagListPage from '@/pages/tags/NicoTagListPage'
import NotFound from '@/pages/NotFound'
import PostDetailPage from '@/pages/posts/PostDetailPage'
@@ -61,8 +60,8 @@ export default (() => {
}
catch (err)
{
if (axios.isAxiosError (err))
setStatus (err.status ?? 200)
if (isApiError (err))
setStatus (err.response?.status ?? 200)
}
}) ()
}


+ 6
- 0
frontend/src/lib/api.ts View File

@@ -3,6 +3,8 @@ import toCamel from 'camelcase-keys'

import { API_BASE_URL } from '@/config'

import type { AxiosError } from 'axios'

type Opt = {
params?: Record<string, unknown>
headers?: Record<string, string>
@@ -64,3 +66,7 @@ export const apiDelete = async (
): Promise<void> => {
await client.delete (path, withUserCode (opt))
}


export const isApiError = (err: unknown): err is AxiosError =>
axios.isAxiosError (err)

+ 4
- 2
frontend/src/pages/wiki/WikiSearchPage.tsx View File

@@ -1,4 +1,4 @@
import React, { useEffect, useState } from 'react'
import { useEffect, useState } from 'react'
import { Helmet } from 'react-helmet-async'

import PrefetchLink from '@/components/PrefetchLink'
@@ -7,6 +7,8 @@ import MainArea from '@/components/layout/MainArea'
import { SITE_TITLE } from '@/config'
import { apiGet } from '@/lib/api'

import type { FormEvent } from 'react'

import type { WikiPage } from '@/types'


@@ -19,7 +21,7 @@ export default () => {
setResults (await apiGet ('/wiki', { params: { title } }))
}

const handleSearch = (ev: React.FormEvent) => {
const handleSearch = (ev: FormEvent) => {
ev.preventDefault ()
search ()
}


Loading…
Cancel
Save