diff --git a/web-new/src/components/card/HistoryCard.tsx b/web-new/src/components/card/HistoryCard.tsx index faad096b7..ddf77e47f 100644 --- a/web-new/src/components/card/HistoryCard.tsx +++ b/web-new/src/components/card/HistoryCard.tsx @@ -22,11 +22,13 @@ import { formatUnixTimestampToDateTime } from "@/utils/dateUtil"; type HistoryCardProps = { timeline: Card; relevantPreview?: Preview; + shouldAutoPlay: boolean; }; export default function HistoryCard({ relevantPreview, timeline, + shouldAutoPlay, }: HistoryCardProps) { const { data: config } = useSWR("config"); @@ -41,6 +43,7 @@ export default function HistoryCard({ relevantPreview={relevantPreview} startTs={Object.values(timeline.entries)[0].timestamp} eventId={Object.values(timeline.entries)[0].source_id} + shouldAutoPlay={shouldAutoPlay} />
diff --git a/web-new/src/components/player/PreviewThumbnailPlayer.tsx b/web-new/src/components/player/PreviewThumbnailPlayer.tsx index 6e86d6f71..725e83376 100644 --- a/web-new/src/components/player/PreviewThumbnailPlayer.tsx +++ b/web-new/src/components/player/PreviewThumbnailPlayer.tsx @@ -11,6 +11,7 @@ type PreviewPlayerProps = { relevantPreview?: Preview; startTs: number; eventId: string; + shouldAutoPlay: boolean; }; type Preview = { @@ -26,12 +27,13 @@ export default function PreviewThumbnailPlayer({ relevantPreview, startTs, eventId, + shouldAutoPlay, }: PreviewPlayerProps) { const { data: config } = useSWR("config"); const playerRef = useRef(null); const apiHost = useApiHost(); - const onHover = useCallback( + const onPlayback = useCallback( (isHovered: Boolean) => { if (!relevantPreview || !playerRef.current) { return; @@ -47,6 +49,32 @@ export default function PreviewThumbnailPlayer({ [relevantPreview, startTs] ); + const observer = useRef(); + const inViewRef = useCallback( + (node: HTMLElement | null) => { + if (!shouldAutoPlay || observer.current) { + return; + } + + try { + observer.current = new IntersectionObserver( + (entries) => { + if (entries[0].isIntersecting) { + onPlayback(true); + } else { + onPlayback(false); + } + }, + { threshold: 1.0 } + ); + if (node) observer.current.observe(node); + } catch (e) { + // no op + } + }, + [observer, onPlayback] + ); + if (!relevantPreview) { if (isCurrentHour(startTs)) { return ( @@ -56,6 +84,7 @@ export default function PreviewThumbnailPlayer({ > @@ -69,6 +98,7 @@ export default function PreviewThumbnailPlayer({ > @@ -77,10 +107,11 @@ export default function PreviewThumbnailPlayer({ return ( onHover(true)} - onMouseLeave={() => onHover(false)} + onMouseEnter={() => onPlayback(true)} + onMouseLeave={() => onPlayback(false)} >
{ onReady && onReady(player); diff --git a/web-new/src/pages/History.tsx b/web-new/src/pages/History.tsx index 4427446df..cdba3dd69 100644 --- a/web-new/src/pages/History.tsx +++ b/web-new/src/pages/History.tsx @@ -5,11 +5,10 @@ import { FrigateConfig } from "@/types/frigateConfig"; import Heading from "@/components/ui/heading"; import ActivityIndicator from "@/components/ui/activity-indicator"; import HistoryCard from "@/components/card/HistoryCard"; -import { ScrollArea, ScrollBar } from "@/components/ui/scroll-area"; import { formatUnixTimestampToDateTime } from "@/utils/dateUtil"; import axios from "axios"; -const API_LIMIT = 200; +const API_LIMIT = 100; function History() { const { data: config } = useSWR("config"); @@ -26,11 +25,15 @@ function History() { const getKey = useCallback((index: number, prevData: HourlyTimeline) => { if (index > 0) { const lastDate = prevData.end; - const pagedParams = { before: lastDate, timezone }; + const pagedParams = { before: lastDate, timezone, limit: API_LIMIT }; return ["timeline/hourly", pagedParams]; } - return ["timeline/hourly", { timezone }]; + return ["timeline/hourly", { timezone, limit: API_LIMIT }]; + }, []); + + const shouldAutoPlay = useMemo(() => { + return window.innerWidth < 480; }, []); const { @@ -207,6 +210,7 @@ function History() {