From 1b797eecaf87f8ab62b0545727f2f94474de641b Mon Sep 17 00:00:00 2001 From: Matt Date: Sat, 4 Jan 2025 00:51:18 -0500 Subject: [PATCH] Reverse feed direction and add navigation arrows --- .../components/dashboard/MiniEventFeed.jsx | 112 +++++++++++++----- 1 file changed, 85 insertions(+), 27 deletions(-) diff --git a/dashboard/src/components/dashboard/MiniEventFeed.jsx b/dashboard/src/components/dashboard/MiniEventFeed.jsx index 4c3f1ad..246a787 100644 --- a/dashboard/src/components/dashboard/MiniEventFeed.jsx +++ b/dashboard/src/components/dashboard/MiniEventFeed.jsx @@ -18,11 +18,14 @@ import { Activity, AlertCircle, FileText, + ChevronLeft, + ChevronRight, } from "lucide-react"; import { format } from "date-fns"; import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"; import { Skeleton } from "@/components/ui/skeleton"; import { EventDialog } from "./EventFeed.jsx"; +import { Button } from "@/components/ui/button"; const METRIC_IDS = { PLACED_ORDER: "Y8cqcF", @@ -319,6 +322,34 @@ const MiniEventFeed = ({ const [error, setError] = useState(null); const [lastUpdate, setLastUpdate] = useState(null); const scrollRef = useRef(null); + const [showLeftArrow, setShowLeftArrow] = useState(false); + const [showRightArrow, setShowRightArrow] = useState(false); + + const handleScroll = () => { + if (scrollRef.current) { + const { scrollLeft, scrollWidth, clientWidth } = scrollRef.current; + setShowLeftArrow(scrollLeft > 0); + setShowRightArrow(scrollLeft < scrollWidth - clientWidth - 1); + } + }; + + const scrollToEnd = () => { + if (scrollRef.current) { + scrollRef.current.scrollTo({ + left: scrollRef.current.scrollWidth, + behavior: 'smooth' + }); + } + }; + + const scrollToStart = () => { + if (scrollRef.current) { + scrollRef.current.scrollTo({ + left: 0, + behavior: 'smooth' + }); + } + }; const fetchEvents = useCallback(async () => { try { @@ -354,6 +385,7 @@ const MiniEventFeed = ({ left: scrollRef.current.scrollWidth, behavior: 'instant' }); + handleScroll(); }, 0); } } catch (error) { @@ -370,37 +402,63 @@ const MiniEventFeed = ({ return () => clearInterval(interval); }, [fetchEvents]); + useEffect(() => { + handleScroll(); + }, [events]); + return (
- -
-
-
- {loading && !events.length ? ( - - ) : error ? ( - - - Error - - Failed to load event feed: {error} - - - ) : !events || events.length === 0 ? ( -
- -
- ) : ( - events.map((event) => ( - - )) - )} + +
+ {showLeftArrow && ( + + )} + {showRightArrow && ( + + )} +
+
+ {loading && !events.length ? ( + + ) : error ? ( + + + Error + + Failed to load event feed: {error} + + + ) : !events || events.length === 0 ? ( +
+ +
+ ) : ( + [...events].reverse().map((event) => ( + + )) + )} +
-
);