From 7c21ccf8d8e92d4a9d56a451fa283ac71ed88fd8 Mon Sep 17 00:00:00 2001 From: takecchi Date: Wed, 20 Dec 2023 17:57:34 +0900 Subject: [PATCH] =?UTF-8?q?=E6=8A=95=E7=A8=BF=E3=81=97=E3=81=9F=E5=BE=8C?= =?UTF-8?q?=E8=87=AA=E5=8B=95=E7=9A=84=E3=81=AB=E3=83=9B=E3=83=BC=E3=83=A0?= =?UTF-8?q?=E3=82=BF=E3=82=A4=E3=83=A0=E3=83=A9=E3=82=A4=E3=83=B3=E3=82=92?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/_components/post/PostDialog.tsx | 3 +++ src/swr/client/timeline.ts | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/app/_components/post/PostDialog.tsx b/src/app/_components/post/PostDialog.tsx index 105802fda..b526b8b35 100644 --- a/src/app/_components/post/PostDialog.tsx +++ b/src/app/_components/post/PostDialog.tsx @@ -16,6 +16,7 @@ import { styled, } from '@mui/material'; import { useState } from 'react'; +import { useHomeTimelineImmutable } from '@/swr/client/timeline'; const Flex = styled('div')` display: flex; @@ -50,6 +51,7 @@ export default function PostDialog({ open, close }: Props) { useState(false); const [getErrorMessage, setErrorMesssage] = useState(''); const [getSucceedMessage, setSucceedMessage] = useState(''); + const { mutateLatest } = useHomeTimelineImmutable(); // NOTE: 閉じきる前に微妙に空になるのが見えるので // それが嫌ならsetTimeout(unmount時にcb呼ぶ方法あるならそっち)で包む @@ -87,6 +89,7 @@ export default function PostDialog({ open, close }: Props) { onSucceed={() => { setSucceedMessage('送信しました。'); clearContent(); + void mutateLatest(); close(); }} onError={(e) => { diff --git a/src/swr/client/timeline.ts b/src/swr/client/timeline.ts index ac168f8ef..c1922d527 100644 --- a/src/swr/client/timeline.ts +++ b/src/swr/client/timeline.ts @@ -52,3 +52,15 @@ export const useHomeTimeline = () => { enableQueue: true, }); }; + +/** + * メインとなるタイムライン + * 自動更新OFF + */ +export const useHomeTimelineImmutable = () => { + const { data: authId } = useAuth(); + const swrKey = authId ? getKey('useHomeTimeline', authId) : () => null; + return useSWRTimeline(swrKey, fetcher, { + enableQueue: true, + }); +};