diff --git a/web/ui/src/pages/detail/Detail.tsx b/web/ui/src/pages/detail/Detail.tsx index 179fbf1f..6f87f86c 100644 --- a/web/ui/src/pages/detail/Detail.tsx +++ b/web/ui/src/pages/detail/Detail.tsx @@ -31,10 +31,34 @@ const ScreenshotDetailPage = () => { const { id } = useParams<{ id: string; }>(); if (!id) throw new Error("Somehow, detail id is not defined"); + const currentId: number = parseInt(id, 10); + useEffect(() => { getData(setLoading, setDetail, setWappalyzer, setDuration, id); }, [id]); + // handle arrowleft and arrowright events + useEffect(() => { + const handleKeyDown = (event: KeyboardEvent) => { + if (event.key === 'ArrowLeft') { + if (currentId > 1) { + navigate(`/screenshot/${currentId - 1}`); + } + } + + if (event.key === 'ArrowRight') { + navigate(`/screenshot/${currentId + 1}`); + } + }; + + window.addEventListener('keydown', handleKeyDown); + + // cleanup when this component is no longer mounted + return () => { + window.removeEventListener('keydown', handleKeyDown); + }; + }, [currentId, navigate]); + const getLogTypeColor = (type: string) => { if (type === 'console.warning' || type === 'console.warn') return "bg-yellow-500 text-black"; return "bg-blue-500 text-white"; @@ -76,17 +100,17 @@ const ScreenshotDetailPage = () => { const timeAgo = formatDistanceToNow(probedDate, { addSuffix: true }); const rawDate = format(probedDate, "PPpp"); - const getNavigation = (id: string) => { + const getNavigation = () => { return (