From fbc0da6016d8d65b023ab4ef38b49dcf59a40cf5 Mon Sep 17 00:00:00 2001 From: Josh Hawkins <32435876+hawkeye217@users.noreply.github.com> Date: Thu, 4 Apr 2024 10:09:19 -0500 Subject: [PATCH] Optimistic UI (#10825) * debounce motion only button * implement custom hook * optimistic severity toggle * optimistic reviewed switch --- .../components/filter/ReviewFilterGroup.tsx | 21 +++++---- web/src/hooks/use-optimistic-state.ts | 43 +++++++++++++++++++ web/src/views/events/EventView.tsx | 16 ++++--- 3 files changed, 67 insertions(+), 13 deletions(-) create mode 100644 web/src/hooks/use-optimistic-state.ts diff --git a/web/src/components/filter/ReviewFilterGroup.tsx b/web/src/components/filter/ReviewFilterGroup.tsx index 4d2e1db8e..9cfe7ed5f 100644 --- a/web/src/components/filter/ReviewFilterGroup.tsx +++ b/web/src/components/filter/ReviewFilterGroup.tsx @@ -2,7 +2,7 @@ import { Button } from "../ui/button"; import { Popover, PopoverContent, PopoverTrigger } from "../ui/popover"; import useSWR from "swr"; import { CameraGroupConfig, FrigateConfig } from "@/types/frigateConfig"; -import { useCallback, useEffect, useMemo, useState } from "react"; +import { useCallback, useMemo, useState } from "react"; import { DropdownMenu, DropdownMenuContent, @@ -29,6 +29,7 @@ import ReviewActivityCalendar from "../overlay/ReviewActivityCalendar"; import MobileReviewSettingsDrawer, { DrawerFeatures, } from "../overlay/MobileReviewSettingsDrawer"; +import useOptimisticState from "@/hooks/use-optimistic-state"; const REVIEW_FILTERS = [ "cameras", @@ -361,13 +362,19 @@ function ShowReviewFilter({ showReviewed, setShowReviewed, }: ShowReviewedFilterProps) { + const [showReviewedSwitch, setShowReviewedSwitch] = useOptimisticState( + showReviewed, + setShowReviewed, + ); return ( <>
setShowReviewed(showReviewed == 0 ? 1 : 0)} + checked={showReviewedSwitch == 1} + onCheckedChange={() => + setShowReviewedSwitch(showReviewedSwitch == 0 ? 1 : 0) + } />
@@ -242,7 +248,7 @@ export default function EventView({