From 69074c1652ea583f2fe140efc780004c22e6cc8d Mon Sep 17 00:00:00 2001 From: hayao Date: Sat, 15 Jun 2024 10:01:37 +0900 Subject: [PATCH] Fix: Link --- src/app/(hayao)/playground/niconico/page.tsx | 29 ++++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/app/(hayao)/playground/niconico/page.tsx b/src/app/(hayao)/playground/niconico/page.tsx index a07d308..54379e1 100644 --- a/src/app/(hayao)/playground/niconico/page.tsx +++ b/src/app/(hayao)/playground/niconico/page.tsx @@ -19,20 +19,24 @@ interface Video { type VideoList = Map; +type ClickList = { [key: string]: boolean }; + export default function Niconico() { const [info, setInfo] = useState(null); const [error, setError] = useState(null); const [search, setSearch] = useState(""); + const [status, setStatus] = useState(null); useEffect(() => { (async () => { - console.log(apiUrl); + //console.log(apiUrl); const res = await fetch(apiUrl); if (!res.ok) { setError(new Error(res.statusText)); throw new Error(res.statusText); } const json = await res.json(); + const videoMap = new Map(); Object.keys(json).forEach((key) => { @@ -40,6 +44,13 @@ export default function Niconico() { }); setInfo(videoMap); + + const initClickList: ClickList = {}; + videoMap.forEach((v, k) => { + initClickList[k] = false; + }); + + setStatus(initClickList); })(); }, []); @@ -66,12 +77,24 @@ export default function Niconico() { return (
  • { + e.preventDefault(); + if (status && status[v.id]) { + window.open(`https://www.nicovideo.jp/watch_tmp/${v.id}`, "_blank"); + } + setStatus({ ...(status ?? {}), [v.id]: true }); + }} > {/* {v.title} */} + {status && status[v.id] ? ( + {v.title} + ) : ( + <> + )} {v.title}