|
|
|
@@ -1,3 +1,4 @@ |
|
|
|
import { useQueryClient } from '@tanstack/react-query' |
|
|
|
import MarkdownIt from 'markdown-it' |
|
|
|
import { useEffect, useState } from 'react' |
|
|
|
import { Helmet } from 'react-helmet-async' |
|
|
|
@@ -8,6 +9,7 @@ import MainArea from '@/components/layout/MainArea' |
|
|
|
import { toast } from '@/components/ui/use-toast' |
|
|
|
import { SITE_TITLE } from '@/config' |
|
|
|
import { apiGet, apiPut } from '@/lib/api' |
|
|
|
import { wikiKeys } from '@/lib/queryKeys' |
|
|
|
import Forbidden from '@/pages/Forbidden' |
|
|
|
|
|
|
|
import 'react-markdown-editor-lite/lib/index.css' |
|
|
|
@@ -29,6 +31,8 @@ export default (({ user }: Props) => { |
|
|
|
|
|
|
|
const navigate = useNavigate () |
|
|
|
|
|
|
|
const qc = useQueryClient () |
|
|
|
|
|
|
|
const [body, setBody] = useState ('') |
|
|
|
const [loading, setLoading] = useState (true) |
|
|
|
const [title, setTitle] = useState ('') |
|
|
|
@@ -42,6 +46,9 @@ export default (({ user }: Props) => { |
|
|
|
{ |
|
|
|
await apiPut (`/wiki/${ id }`, formData, |
|
|
|
{ headers: { 'Content-Type': 'multipart/form-data' } }) |
|
|
|
qc.setQueryData (wikiKeys.show (title, { }), |
|
|
|
(prev: WikiPage) => ({ ...prev, title, body })) |
|
|
|
qc.invalidateQueries ({ queryKey: wikiKeys.root }) |
|
|
|
toast ({ title: '投稿成功!' }) |
|
|
|
navigate (`/wiki/${ title }`) |
|
|
|
} |
|
|
|
|