From 3495cd38b50128606fcec8ff8de8676d1dec6c6c Mon Sep 17 00:00:00 2001 From: Nik Afiq Date: Wed, 5 Nov 2025 17:19:40 +0900 Subject: [PATCH] Added page redirect after set show --- frontend/src/pages/ShowsPage.tsx | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/frontend/src/pages/ShowsPage.tsx b/frontend/src/pages/ShowsPage.tsx index ce9054d..551046f 100644 --- a/frontend/src/pages/ShowsPage.tsx +++ b/frontend/src/pages/ShowsPage.tsx @@ -1,4 +1,5 @@ -import { useEffect, useMemo, useState } from "react"; +import { useEffect, useMemo, useState, useRef } from "react"; +import { useNavigate } from "react-router-dom"; type Show = { id: number; @@ -12,6 +13,7 @@ type Show = { const GET_URL = "/api/v1/shows"; const POST_URL = "/api/v1/current"; +const REDIRECT_DELAY_MS = 1200; const HHMM = /^(\d{1,2}):([0-5]\d)$/; @@ -36,6 +38,8 @@ export default function ShowsPage() { const [loading, setLoading] = useState(true); const [posting, setPosting] = useState(false); const [error, setError] = useState(null); + const navigate = useNavigate(); + const redirectTid = useRef(null); // フォーム状態 const [selectedId, setSelectedId] = useState(null); @@ -82,6 +86,10 @@ export default function ShowsPage() { const current = useMemo(() => shows.find(s => s.id === selectedId) || null, [shows, selectedId]); + useEffect(() => { + return () => { if (redirectTid.current) window.clearTimeout(redirectTid.current); }; + }, []); + async function submit() { setError(null); if (!selectedId) { setError("エピソードを選択してください。"); return; } @@ -107,6 +115,11 @@ export default function ShowsPage() { body: JSON.stringify(payload), }); if (!res.ok) throw new Error(`POST 失敗 (${res.status})`); + setError("設定しました。少々お待ちください…"); + redirectTid.current = window.setTimeout( + () => navigate("/", { replace: true }), + REDIRECT_DELAY_MS + ); } catch (e: any) { setError(e.message || "現在のエピソード設定に失敗しました。"); } finally {