| @@ -1,12 +1,10 @@ | |||||
| import axios from 'axios' | |||||
| import toCamel from 'camelcase-keys' | |||||
| import { useEffect, useState } from 'react' | import { useEffect, useState } from 'react' | ||||
| import PostFormTagsArea from '@/components/PostFormTagsArea' | import PostFormTagsArea from '@/components/PostFormTagsArea' | ||||
| import PostOriginalCreatedTimeField from '@/components/PostOriginalCreatedTimeField' | import PostOriginalCreatedTimeField from '@/components/PostOriginalCreatedTimeField' | ||||
| import Label from '@/components/common/Label' | import Label from '@/components/common/Label' | ||||
| import { Button } from '@/components/ui/button' | import { Button } from '@/components/ui/button' | ||||
| import { API_BASE_URL } from '@/config' | |||||
| import { apiPut } from '@/lib/api' | |||||
| import type { FC } from 'react' | import type { FC } from 'react' | ||||
| @@ -41,14 +39,11 @@ export default (({ post, onSave }: Props) => { | |||||
| const [tags, setTags] = useState<string> ('') | const [tags, setTags] = useState<string> ('') | ||||
| const handleSubmit = async () => { | const handleSubmit = async () => { | ||||
| const res = await axios.put ( | |||||
| `${ API_BASE_URL }/posts/${ post.id }`, | |||||
| { title, tags, | |||||
| original_created_from: originalCreatedFrom, | |||||
| const data = await apiPut<Post> ( | |||||
| `/posts/${ post.id }`, | |||||
| { title, tags, original_created_from: originalCreatedFrom, | |||||
| original_created_before: originalCreatedBefore }, | original_created_before: originalCreatedBefore }, | ||||
| { headers: { 'Content-Type': 'multipart/form-data', | |||||
| 'X-Transfer-Code': localStorage.getItem ('user_code') ?? '' } }) | |||||
| const data = toCamel (res.data as any, { deep: true }) as Post | |||||
| { headers: { 'Content-Type': 'multipart/form-data' } }) | |||||
| onSave ({ ...post, | onSave ({ ...post, | ||||
| title: data.title, | title: data.title, | ||||
| tags: data.tags, | tags: data.tags, | ||||
| @@ -1,4 +1,3 @@ | |||||
| import axios from 'axios' | |||||
| import MarkdownIt from 'markdown-it' | import MarkdownIt from 'markdown-it' | ||||
| import { useState } from 'react' | import { useState } from 'react' | ||||
| import { Helmet } from 'react-helmet-async' | import { Helmet } from 'react-helmet-async' | ||||
| @@ -7,7 +6,8 @@ import { useLocation, useNavigate } from 'react-router-dom' | |||||
| import MainArea from '@/components/layout/MainArea' | import MainArea from '@/components/layout/MainArea' | ||||
| import { toast } from '@/components/ui/use-toast' | import { toast } from '@/components/ui/use-toast' | ||||
| import { API_BASE_URL, SITE_TITLE } from '@/config' | |||||
| import { SITE_TITLE } from '@/config' | |||||
| import { apiPost } from '@/lib/api' | |||||
| import Forbidden from '@/pages/Forbidden' | import Forbidden from '@/pages/Forbidden' | ||||
| import 'react-markdown-editor-lite/lib/index.css' | import 'react-markdown-editor-lite/lib/index.css' | ||||
| @@ -39,10 +39,8 @@ export default ({ user }: Props) => { | |||||
| try | try | ||||
| { | { | ||||
| const res = await axios.post (`${ API_BASE_URL }/wiki`, formData, { headers: { | |||||
| 'Content-Type': 'multipart/form-data', | |||||
| 'X-Transfer-Code': localStorage.getItem ('user_code') || '' } }) | |||||
| const data = res.data as WikiPage | |||||
| const data = await apiPost<WikiPage> ('/wiki', formData, | |||||
| { headers: { 'Content-Type': 'multipart/form-data' } }) | |||||
| toast ({ title: '投稿成功!' }) | toast ({ title: '投稿成功!' }) | ||||
| navigate (`/wiki/${ data.title }`) | navigate (`/wiki/${ data.title }`) | ||||
| } | } | ||||
| @@ -1,12 +1,11 @@ | |||||
| import axios from 'axios' | |||||
| import toCamel from 'camelcase-keys' | |||||
| import React, { useEffect, useState } from 'react' | import React, { useEffect, useState } from 'react' | ||||
| import { Helmet } from 'react-helmet-async' | import { Helmet } from 'react-helmet-async' | ||||
| import PrefetchLink from '@/components/PrefetchLink' | import PrefetchLink from '@/components/PrefetchLink' | ||||
| import SectionTitle from '@/components/common/SectionTitle' | import SectionTitle from '@/components/common/SectionTitle' | ||||
| import MainArea from '@/components/layout/MainArea' | import MainArea from '@/components/layout/MainArea' | ||||
| import { API_BASE_URL, SITE_TITLE } from '@/config' | |||||
| import { SITE_TITLE } from '@/config' | |||||
| import { apiGet } from '@/lib/api' | |||||
| import type { WikiPage } from '@/types' | import type { WikiPage } from '@/types' | ||||
| @@ -17,8 +16,7 @@ export default () => { | |||||
| const [results, setResults] = useState<WikiPage[]> ([]) | const [results, setResults] = useState<WikiPage[]> ([]) | ||||
| const search = async () => { | const search = async () => { | ||||
| const res = await axios.get (`${ API_BASE_URL }/wiki/search`, { params: { title } }) | |||||
| setResults (toCamel (res.data as any, { deep: true }) as WikiPage[]) | |||||
| setResults (await apiGet ('/wiki', { params: { title } })) | |||||
| } | } | ||||
| const handleSearch = (ev: React.FormEvent) => { | const handleSearch = (ev: React.FormEvent) => { | ||||