Skip to content

Commit

Permalink
Fix: Link
Browse files Browse the repository at this point in the history
  • Loading branch information
Hayao0819 committed Jun 15, 2024
1 parent 001cd88 commit 69074c1
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions src/app/(hayao)/playground/niconico/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,38 @@ interface Video {

type VideoList = Map<string, Video>;

type ClickList = { [key: string]: boolean };

export default function Niconico() {
const [info, setInfo] = useState<VideoList | null>(null);
const [error, setError] = useState<Error | null>(null);
const [search, setSearch] = useState<string>("");
const [status, setStatus] = useState<ClickList | null>(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<string, Video>();

Object.keys(json).forEach((key) => {
videoMap.set(key, json[key]);
});

setInfo(videoMap);

const initClickList: ClickList = {};
videoMap.forEach((v, k) => {
initClickList[k] = false;
});

setStatus(initClickList);
})();
}, []);

Expand All @@ -66,12 +77,24 @@ export default function Niconico() {
return (
<li key={v.id} className="">
<a
href={`https://www.nicovideo.jp/watch/${v.id}`}
//href={`https://www.nicovideo.jp/watch_tmp/${v.id}`}
target="_blank"
rel="noreferrer"
className="flex"
className="flex cursor-pointer"
onClick={(e) => {
e.preventDefault();
if (status && status[v.id]) {
window.open(`https://www.nicovideo.jp/watch_tmp/${v.id}`, "_blank");
}
setStatus({ ...(status ?? {}), [v.id]: true });
}}
>
{/* <img src={v.thumbnail} alt={v.title} className="size-20" /> */}
{status && status[v.id] ? (
<img src={v.thumbnail} alt={v.title} className="size-20" />
) : (
<></>
)}
<span className=" flex items-center p-3 align-middle">{v.title}</span>
</a>
</li>
Expand Down

0 comments on commit 69074c1

Please sign in to comment.