mirror of
https://github.com/blakeblackshear/frigate.git
synced 2025-10-04 11:15:55 +02:00
Use persistence for live layout (#10114)
* Use persistence for live layout * Fix typing * Fix persistence typing * remove type * More type fixing
This commit is contained in:
parent
485057abc1
commit
8072ce25c6
@ -22,7 +22,7 @@ export default function DebugCameraImage({
|
|||||||
cameraConfig,
|
cameraConfig,
|
||||||
}: DebugCameraImageProps) {
|
}: DebugCameraImageProps) {
|
||||||
const [showSettings, setShowSettings] = useState(false);
|
const [showSettings, setShowSettings] = useState(false);
|
||||||
const [options, setOptions] = usePersistence(
|
const [options, setOptions] = usePersistence<Options>(
|
||||||
`${cameraConfig?.name}-feed`,
|
`${cameraConfig?.name}-feed`,
|
||||||
emptyObject
|
emptyObject
|
||||||
);
|
);
|
||||||
@ -36,7 +36,7 @@ export default function DebugCameraImage({
|
|||||||
const searchParams = useMemo(
|
const searchParams = useMemo(
|
||||||
() =>
|
() =>
|
||||||
new URLSearchParams(
|
new URLSearchParams(
|
||||||
Object.keys(options).reduce((memo, key) => {
|
Object.keys(options || {}).reduce((memo, key) => {
|
||||||
//@ts-ignore we know this is correct
|
//@ts-ignore we know this is correct
|
||||||
memo.push([key, options[key] === true ? "1" : "0"]);
|
memo.push([key, options[key] === true ? "1" : "0"]);
|
||||||
return memo;
|
return memo;
|
||||||
@ -68,7 +68,7 @@ export default function DebugCameraImage({
|
|||||||
<CardContent>
|
<CardContent>
|
||||||
<DebugSettings
|
<DebugSettings
|
||||||
handleSetOption={handleSetOption}
|
handleSetOption={handleSetOption}
|
||||||
options={options}
|
options={options || {}}
|
||||||
/>
|
/>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
|
@ -7,7 +7,7 @@ import { LivePlayerMode } from "@/types/live";
|
|||||||
export default function useCameraLiveMode(
|
export default function useCameraLiveMode(
|
||||||
cameraConfig: CameraConfig,
|
cameraConfig: CameraConfig,
|
||||||
preferredMode?: string
|
preferredMode?: string
|
||||||
): LivePlayerMode {
|
): LivePlayerMode | undefined {
|
||||||
const { data: config } = useSWR<FrigateConfig>("config");
|
const { data: config } = useSWR<FrigateConfig>("config");
|
||||||
|
|
||||||
const restreamEnabled = useMemo(() => {
|
const restreamEnabled = useMemo(() => {
|
||||||
@ -22,10 +22,10 @@ export default function useCameraLiveMode(
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
}, [config, cameraConfig]);
|
}, [config, cameraConfig]);
|
||||||
const defaultLiveMode = useMemo(() => {
|
const defaultLiveMode = useMemo<LivePlayerMode | undefined>(() => {
|
||||||
if (config && cameraConfig) {
|
if (config && cameraConfig) {
|
||||||
if (restreamEnabled) {
|
if (restreamEnabled) {
|
||||||
return cameraConfig.ui.live_mode || config?.ui.live_mode;
|
return cameraConfig.ui.live_mode || config.ui.live_mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
return "jsmpeg";
|
return "jsmpeg";
|
||||||
@ -33,7 +33,7 @@ export default function useCameraLiveMode(
|
|||||||
|
|
||||||
return undefined;
|
return undefined;
|
||||||
}, [cameraConfig, restreamEnabled]);
|
}, [cameraConfig, restreamEnabled]);
|
||||||
const [viewSource] = usePersistence(
|
const [viewSource] = usePersistence<LivePlayerMode>(
|
||||||
`${cameraConfig.name}-source`,
|
`${cameraConfig.name}-source`,
|
||||||
defaultLiveMode
|
defaultLiveMode
|
||||||
);
|
);
|
||||||
|
@ -1,21 +1,21 @@
|
|||||||
import { useEffect, useState, useCallback } from "react";
|
import { useEffect, useState, useCallback } from "react";
|
||||||
import { get as getData, set as setData } from "idb-keyval";
|
import { get as getData, set as setData } from "idb-keyval";
|
||||||
|
|
||||||
type usePersistenceReturn = [
|
type usePersistenceReturn<S> = [
|
||||||
value: any | undefined,
|
value: S | undefined,
|
||||||
setValue: (value: string | boolean) => void,
|
setValue: (value: S) => void,
|
||||||
loaded: boolean,
|
loaded: boolean,
|
||||||
];
|
];
|
||||||
|
|
||||||
export function usePersistence(
|
export function usePersistence<S>(
|
||||||
key: string,
|
key: string,
|
||||||
defaultValue: any | undefined = undefined
|
defaultValue: S | undefined = undefined
|
||||||
): usePersistenceReturn {
|
): usePersistenceReturn<S> {
|
||||||
const [value, setInternalValue] = useState<any | undefined>(defaultValue);
|
const [value, setInternalValue] = useState<S | undefined>(defaultValue);
|
||||||
const [loaded, setLoaded] = useState<boolean>(false);
|
const [loaded, setLoaded] = useState<boolean>(false);
|
||||||
|
|
||||||
const setValue = useCallback(
|
const setValue = useCallback(
|
||||||
(value: string | boolean) => {
|
(value: S) => {
|
||||||
setInternalValue(value);
|
setInternalValue(value);
|
||||||
async function update() {
|
async function update() {
|
||||||
await setData(key, value);
|
await setData(key, value);
|
||||||
|
@ -5,6 +5,7 @@ import LivePlayer from "@/components/player/LivePlayer";
|
|||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { ScrollArea, ScrollBar } from "@/components/ui/scroll-area";
|
import { ScrollArea, ScrollBar } from "@/components/ui/scroll-area";
|
||||||
import { TooltipProvider } from "@/components/ui/tooltip";
|
import { TooltipProvider } from "@/components/ui/tooltip";
|
||||||
|
import { usePersistence } from "@/hooks/use-persistence";
|
||||||
import { Event as FrigateEvent } from "@/types/event";
|
import { Event as FrigateEvent } from "@/types/event";
|
||||||
import { FrigateConfig } from "@/types/frigateConfig";
|
import { FrigateConfig } from "@/types/frigateConfig";
|
||||||
import { useCallback, useEffect, useMemo, useState } from "react";
|
import { useCallback, useEffect, useMemo, useState } from "react";
|
||||||
@ -17,7 +18,8 @@ function Live() {
|
|||||||
|
|
||||||
// layout
|
// layout
|
||||||
|
|
||||||
const [layout, setLayout] = useState<"grid" | "list">(
|
const [layout, setLayout] = usePersistence<"grid" | "list">(
|
||||||
|
"live-layout",
|
||||||
isDesktop ? "grid" : "list"
|
isDesktop ? "grid" : "list"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
|
import { LivePlayerMode } from "./live";
|
||||||
|
|
||||||
export interface UiConfig {
|
export interface UiConfig {
|
||||||
timezone?: string;
|
timezone?: string;
|
||||||
time_format?: "browser" | "12hour" | "24hour";
|
time_format?: "browser" | "12hour" | "24hour";
|
||||||
date_style?: "full" | "long" | "medium" | "short";
|
date_style?: "full" | "long" | "medium" | "short";
|
||||||
time_style?: "full" | "long" | "medium" | "short";
|
time_style?: "full" | "long" | "medium" | "short";
|
||||||
strftime_fmt?: string;
|
strftime_fmt?: string;
|
||||||
live_mode?: string;
|
live_mode?: LivePlayerMode;
|
||||||
use_experimental?: boolean;
|
use_experimental?: boolean;
|
||||||
dashboard: boolean;
|
dashboard: boolean;
|
||||||
order: number;
|
order: number;
|
||||||
|
Loading…
Reference in New Issue
Block a user