Explore UI tweaks (#13679)

* Loading indicators and filter bar tweaks

* remove unnecessary bits from search thumbnail

* simplify

* add video loading indicator

* clean up
This commit is contained in:
Josh Hawkins 2024-09-11 12:32:45 -05:00 committed by GitHub
parent 22ee6bb137
commit 863f51363a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 93 additions and 111 deletions

View File

@ -1,14 +1,13 @@
import React, { useCallback, useEffect, useMemo, useState } from "react"; import { useCallback } from "react";
import { useApiHost } from "@/api"; import { useApiHost } from "@/api";
import { getIconForLabel } from "@/utils/iconUtil"; import { getIconForLabel } from "@/utils/iconUtil";
import TimeAgo from "../dynamic/TimeAgo"; import TimeAgo from "../dynamic/TimeAgo";
import useSWR from "swr"; import useSWR from "swr";
import { FrigateConfig } from "@/types/frigateConfig"; import { FrigateConfig } from "@/types/frigateConfig";
import { isIOS, isMobile, isSafari } from "react-device-detect"; import { isIOS, isSafari } from "react-device-detect";
import Chip from "@/components/indicators/Chip"; import Chip from "@/components/indicators/Chip";
import { useFormattedTimestamp } from "@/hooks/use-date-utils"; import { useFormattedTimestamp } from "@/hooks/use-date-utils";
import useImageLoaded from "@/hooks/use-image-loaded"; import useImageLoaded from "@/hooks/use-image-loaded";
import { useSwipeable } from "react-swipeable";
import { Tooltip, TooltipContent, TooltipTrigger } from "../ui/tooltip"; import { Tooltip, TooltipContent, TooltipTrigger } from "../ui/tooltip";
import ImageLoadingIndicator from "../indicators/ImageLoadingIndicator"; import ImageLoadingIndicator from "../indicators/ImageLoadingIndicator";
import ActivityIndicator from "../indicators/activity-indicator"; import ActivityIndicator from "../indicators/activity-indicator";
@ -19,14 +18,12 @@ import { cn } from "@/lib/utils";
type SearchThumbnailProps = { type SearchThumbnailProps = {
searchResult: SearchResult; searchResult: SearchResult;
scrollLock?: boolean;
findSimilar: () => void; findSimilar: () => void;
onClick: (searchResult: SearchResult, detail: boolean) => void; onClick: (searchResult: SearchResult) => void;
}; };
export default function SearchThumbnail({ export default function SearchThumbnail({
searchResult, searchResult,
scrollLock = false,
findSimilar, findSimilar,
onClick, onClick,
}: SearchThumbnailProps) { }: SearchThumbnailProps) {
@ -34,58 +31,11 @@ export default function SearchThumbnail({
const { data: config } = useSWR<FrigateConfig>("config"); const { data: config } = useSWR<FrigateConfig>("config");
const [imgRef, imgLoaded, onImgLoad] = useImageLoaded(); const [imgRef, imgLoaded, onImgLoad] = useImageLoaded();
// interaction
const swipeHandlers = useSwipeable({
onSwipedLeft: () => setDetails(false),
onSwipedRight: () => setDetails(true),
preventScrollOnSwipe: true,
});
useContextMenu(imgRef, findSimilar); useContextMenu(imgRef, findSimilar);
// Hover Details const handleOnClick = useCallback(() => {
onClick(searchResult);
const [hoverTimeout, setHoverTimeout] = useState<NodeJS.Timeout | null>(); }, [searchResult, onClick]);
const [details, setDetails] = useState(false);
const [tooltipHovering, setTooltipHovering] = useState(false);
const showingMoreDetail = useMemo(
() => details && !tooltipHovering,
[details, tooltipHovering],
);
const [isHovered, setIsHovered] = useState(false);
const handleOnClick = useCallback(
(e: React.MouseEvent<HTMLDivElement>) => {
if (!showingMoreDetail) {
onClick(searchResult, e.metaKey);
}
},
[searchResult, showingMoreDetail, onClick],
);
useEffect(() => {
if (isHovered && scrollLock) {
return;
}
if (isHovered && !tooltipHovering) {
setHoverTimeout(
setTimeout(() => {
setDetails(true);
setHoverTimeout(null);
}, 500),
);
} else {
if (hoverTimeout) {
clearTimeout(hoverTimeout);
}
setDetails(false);
}
// we know that these deps are correct
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isHovered, scrollLock, tooltipHovering]);
// date // date
@ -95,13 +45,7 @@ export default function SearchThumbnail({
); );
return ( return (
<div <div className="relative size-full cursor-pointer" onClick={handleOnClick}>
className="relative size-full cursor-pointer"
onMouseOver={isMobile ? undefined : () => setIsHovered(true)}
onMouseLeave={isMobile ? undefined : () => setIsHovered(false)}
onClick={handleOnClick}
{...swipeHandlers}
>
<ImageLoadingIndicator <ImageLoadingIndicator
className="absolute inset-0" className="absolute inset-0"
imgLoaded={imgLoaded} imgLoaded={imgLoaded}
@ -131,18 +75,14 @@ export default function SearchThumbnail({
<div className="absolute left-0 top-2 z-40"> <div className="absolute left-0 top-2 z-40">
<Tooltip> <Tooltip>
<div <div className="flex">
className="flex"
onMouseEnter={() => setTooltipHovering(true)}
onMouseLeave={() => setTooltipHovering(false)}
>
<TooltipTrigger asChild> <TooltipTrigger asChild>
<div className="mx-3 pb-1 text-sm text-white"> <div className="mx-3 pb-1 text-sm text-white">
{ {
<> <>
<Chip <Chip
className={`z-0 flex items-start justify-between space-x-1 bg-gray-500 bg-gradient-to-br from-gray-400 to-gray-500`} className={`z-0 flex items-start justify-between space-x-1 bg-gray-500 bg-gradient-to-br from-gray-400 to-gray-500`}
onClick={() => onClick(searchResult, true)} onClick={() => onClick(searchResult)}
> >
{getIconForLabel( {getIconForLabel(
searchResult.label, searchResult.label,

View File

@ -32,6 +32,7 @@ import { Event } from "@/types/event";
import HlsVideoPlayer from "@/components/player/HlsVideoPlayer"; import HlsVideoPlayer from "@/components/player/HlsVideoPlayer";
import { baseUrl } from "@/api/baseUrl"; import { baseUrl } from "@/api/baseUrl";
import { cn } from "@/lib/utils"; import { cn } from "@/lib/utils";
import ActivityIndicator from "@/components/indicators/activity-indicator";
const SEARCH_TABS = ["details", "Frigate+", "video"] as const; const SEARCH_TABS = ["details", "Frigate+", "video"] as const;
type SearchTab = (typeof SEARCH_TABS)[number]; type SearchTab = (typeof SEARCH_TABS)[number];
@ -312,11 +313,16 @@ type VideoTabProps = {
search: SearchResult; search: SearchResult;
}; };
function VideoTab({ search }: VideoTabProps) { function VideoTab({ search }: VideoTabProps) {
const [isLoading, setIsLoading] = useState(true);
const videoRef = useRef<HTMLVideoElement | null>(null); const videoRef = useRef<HTMLVideoElement | null>(null);
const endTime = useMemo(() => search.end_time ?? Date.now() / 1000, [search]); const endTime = useMemo(() => search.end_time ?? Date.now() / 1000, [search]);
return ( return (
<>
{isLoading && (
<ActivityIndicator className="absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2" />
)}
<HlsVideoPlayer <HlsVideoPlayer
videoRef={videoRef} videoRef={videoRef}
currentSource={`${baseUrl}vod/${search.camera}/start/${search.start_time}/end/${endTime}/index.m3u8`} currentSource={`${baseUrl}vod/${search.camera}/start/${search.start_time}/end/${endTime}/index.m3u8`}
@ -325,6 +331,8 @@ function VideoTab({ search }: VideoTabProps) {
frigateControls={false} frigateControls={false}
fullscreen={false} fullscreen={false}
supportsFullscreen={false} supportsFullscreen={false}
onPlaying={() => setIsLoading(false)}
/> />
</>
); );
} }

View File

@ -1,5 +1,5 @@
import { useEffect, useMemo } from "react"; import { useEffect, useMemo } from "react";
import { isIOS, isMobileOnly } from "react-device-detect"; import { isIOS, isMobileOnly, isSafari } from "react-device-detect";
import useSWR from "swr"; import useSWR from "swr";
import { useApiHost } from "@/api"; import { useApiHost } from "@/api";
import { cn } from "@/lib/utils"; import { cn } from "@/lib/utils";
@ -12,9 +12,12 @@ import {
} from "@/components/ui/tooltip"; } from "@/components/ui/tooltip";
import { TooltipPortal } from "@radix-ui/react-tooltip"; import { TooltipPortal } from "@radix-ui/react-tooltip";
import { SearchResult } from "@/types/search"; import { SearchResult } from "@/types/search";
import ImageLoadingIndicator from "@/components/indicators/ImageLoadingIndicator";
import useImageLoaded from "@/hooks/use-image-loaded";
import ActivityIndicator from "@/components/indicators/activity-indicator";
type ExploreViewProps = { type ExploreViewProps = {
onSelectSearch: (searchResult: SearchResult, detail: boolean) => void; onSelectSearch: (searchResult: SearchResult) => void;
}; };
export default function ExploreView({ onSelectSearch }: ExploreViewProps) { export default function ExploreView({ onSelectSearch }: ExploreViewProps) {
@ -50,8 +53,14 @@ export default function ExploreView({ onSelectSearch }: ExploreViewProps) {
}, {}); }, {});
}, [events]); }, [events]);
if (!events) {
return ( return (
<div className="space-y-4 overflow-x-hidden p-2"> <ActivityIndicator className="absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2" />
);
}
return (
<div className="scrollbar-container mx-2 space-y-4 overflow-x-hidden">
{Object.entries(eventsByLabel).map(([label, filteredEvents]) => ( {Object.entries(eventsByLabel).map(([label, filteredEvents]) => (
<ThumbnailRow <ThumbnailRow
key={label} key={label}
@ -67,7 +76,7 @@ export default function ExploreView({ onSelectSearch }: ExploreViewProps) {
type ThumbnailRowType = { type ThumbnailRowType = {
objectType: string; objectType: string;
searchResults?: SearchResult[]; searchResults?: SearchResult[];
onSelectSearch: (searchResult: SearchResult, detail: boolean) => void; onSelectSearch: (searchResult: SearchResult) => void;
}; };
function ThumbnailRow({ function ThumbnailRow({
@ -75,7 +84,6 @@ function ThumbnailRow({
searchResults, searchResults,
onSelectSearch, onSelectSearch,
}: ThumbnailRowType) { }: ThumbnailRowType) {
const apiHost = useApiHost();
const navigate = useNavigate(); const navigate = useNavigate();
const handleSearch = (label: string) => { const handleSearch = (label: string) => {
@ -106,22 +114,9 @@ function ThumbnailRow({
key={event.id} key={event.id}
className="relative aspect-square h-auto max-w-[20%] flex-grow md:max-w-[10%]" className="relative aspect-square h-auto max-w-[20%] flex-grow md:max-w-[10%]"
> >
<img <ExploreThumbnailImage
className={cn( event={event}
"absolute h-full w-full cursor-pointer rounded-lg object-cover transition-all duration-300 ease-in-out md:rounded-2xl", onSelectSearch={onSelectSearch}
)}
style={
isIOS
? {
WebkitUserSelect: "none",
WebkitTouchCallout: "none",
}
: undefined
}
draggable={false}
src={`${apiHost}api/events/${event.id}/thumbnail.jpg`}
alt={`${objectType} snapshot`}
onClick={() => onSelectSearch(event, true)}
/> />
</div> </div>
))} ))}
@ -148,6 +143,48 @@ function ThumbnailRow({
); );
} }
type ExploreThumbnailImageProps = {
event: SearchResult;
onSelectSearch: (searchResult: SearchResult) => void;
};
function ExploreThumbnailImage({
event,
onSelectSearch,
}: ExploreThumbnailImageProps) {
const apiHost = useApiHost();
const [imgRef, imgLoaded, onImgLoad] = useImageLoaded();
return (
<>
<ImageLoadingIndicator
className="absolute inset-0"
imgLoaded={imgLoaded}
/>
<img
ref={imgRef}
className={cn(
"absolute h-full w-full cursor-pointer rounded-lg object-cover transition-all duration-300 ease-in-out md:rounded-2xl",
)}
style={
isIOS
? {
WebkitUserSelect: "none",
WebkitTouchCallout: "none",
}
: undefined
}
loading={isSafari ? "eager" : "lazy"}
draggable={false}
src={`${apiHost}api/events/${event.id}/thumbnail.jpg`}
onClick={() => onSelectSearch(event)}
onLoad={() => {
onImgLoad();
}}
/>
</>
);
}
function ExploreMoreLink({ objectType }: { objectType: string }) { function ExploreMoreLink({ objectType }: { objectType: string }) {
const formattedType = objectType.replaceAll("_", " "); const formattedType = objectType.replaceAll("_", " ");
const label = formattedType.endsWith("s") const label = formattedType.endsWith("s")

View File

@ -65,12 +65,8 @@ export default function SearchView({
// search interaction // search interaction
const onSelectSearch = useCallback((item: SearchResult, detail: boolean) => { const onSelectSearch = useCallback((item: SearchResult) => {
if (detail) {
setSearchDetail(item); setSearchDetail(item);
} else {
setSearchDetail(item);
}
}, []); }, []);
// confidence score - probably needs tweaking // confidence score - probably needs tweaking
@ -110,18 +106,18 @@ export default function SearchView({
<div <div
className={cn( className={cn(
"flex h-11 items-center pl-2 pr-2 md:pl-3", "flex flex-col items-start space-y-2 pl-2 pr-2 md:mb-2 md:pl-3 lg:h-10 lg:flex-row lg:items-center lg:space-y-0",
config?.semantic_search?.enabled config?.semantic_search?.enabled
? "justify-between" ? "justify-between"
: "justify-center", : "justify-center",
isMobileOnly && "mb-3 h-auto flex-wrap gap-2", isMobileOnly && "mb-2 h-auto flex-wrap gap-2 space-y-0",
)} )}
> >
{config?.semantic_search?.enabled && ( {config?.semantic_search?.enabled && (
<div <div
className={cn( className={cn(
"relative w-full", "relative w-full",
hasExistingSearch ? "md:mr-3 md:w-1/3" : "md:ml-[25%] md:w-1/2", hasExistingSearch ? "lg:mr-3 lg:w-1/3" : "lg:ml-[25%] lg:w-1/2",
)} )}
> >
<Input <Input
@ -141,7 +137,9 @@ export default function SearchView({
{hasExistingSearch && ( {hasExistingSearch && (
<SearchFilterGroup <SearchFilterGroup
className={cn("", isMobileOnly && "w-full justify-between")} className={cn(
"w-full justify-between md:justify-start lg:justify-end",
)}
filter={searchFilter} filter={searchFilter}
onUpdateFilter={onUpdateFilter} onUpdateFilter={onUpdateFilter}
/> />
@ -179,9 +177,8 @@ export default function SearchView({
> >
<SearchThumbnail <SearchThumbnail
searchResult={value} searchResult={value}
scrollLock={false}
findSimilar={() => setSimilaritySearch(value)} findSimilar={() => setSimilaritySearch(value)}
onClick={onSelectSearch} onClick={() => onSelectSearch(value)}
/> />
{(searchTerm || similaritySearch) && ( {(searchTerm || similaritySearch) && (
<div className={cn("absolute right-2 top-2 z-40")}> <div className={cn("absolute right-2 top-2 z-40")}>