diff --git a/src/app/(app)/thinking/page.tsx b/src/app/(app)/thinking/page.tsx index ba8c3205f4..79e44e513c 100644 --- a/src/app/(app)/thinking/page.tsx +++ b/src/app/(app)/thinking/page.tsx @@ -1,6 +1,10 @@ 'use client' -import { useInfiniteQuery, useQueryClient } from '@tanstack/react-query' +import { + useInfiniteQuery, + useMutation, + useQueryClient, +} from '@tanstack/react-query' import { useEffect, useMemo, useState } from 'react' import clsx from 'clsx' import { stagger, useAnimate } from 'framer-motion' @@ -57,26 +61,29 @@ const PostBox = () => { const [value, setValue] = useState('') const queryClient = useQueryClient() - if (!isLogin) return null - - const handleSend = () => { - apiClient.shorthand.proxy.post({ data: { content: value } }).then((res) => { - setValue('') - - queryClient.setQueryData< - InfiniteData< - RecentlyModel[] & { - comments: number - } - > - >(QUERY_KEY, (old) => { - return produce(old, (draft) => { - draft?.pages[0].unshift(res.$serialized as any) - return draft + const { mutateAsync: handleSend, isPending } = useMutation({ + mutationFn: async () => { + apiClient.shorthand.proxy + .post({ data: { content: value } }) + .then((res) => { + setValue('') + + queryClient.setQueryData< + InfiniteData< + RecentlyModel[] & { + comments: number + } + > + >(QUERY_KEY, (old) => { + return produce(old, (draft) => { + draft?.pages[0].unshift(res.$serialized as any) + return draft + }) + }) }) - }) - }) - } + }, + }) + if (!isLogin) return null return (