mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-04-12 01:57:36 +03:00
use context provider for activity stream
This commit is contained in:
parent
cecbea0faf
commit
ada15e1686
56
web/src/contexts/ActivityStreamContext.tsx
Normal file
56
web/src/contexts/ActivityStreamContext.tsx
Normal file
@ -0,0 +1,56 @@
|
||||
import React, { createContext, useContext, useState } from "react";
|
||||
|
||||
interface ActivityStreamContextType {
|
||||
selectedObjectId: string | undefined;
|
||||
currentTime: number;
|
||||
camera: string;
|
||||
setSelectedObjectId: (id: string | undefined) => void;
|
||||
isActivityMode: boolean;
|
||||
}
|
||||
|
||||
const ActivityStreamContext = createContext<
|
||||
ActivityStreamContextType | undefined
|
||||
>(undefined);
|
||||
|
||||
interface ActivityStreamProviderProps {
|
||||
children: React.ReactNode;
|
||||
isActivityMode: boolean;
|
||||
currentTime: number;
|
||||
camera: string;
|
||||
}
|
||||
|
||||
export function ActivityStreamProvider({
|
||||
children,
|
||||
isActivityMode,
|
||||
currentTime,
|
||||
camera,
|
||||
}: ActivityStreamProviderProps) {
|
||||
const [selectedObjectId, setSelectedObjectId] = useState<
|
||||
string | undefined
|
||||
>();
|
||||
|
||||
const value: ActivityStreamContextType = {
|
||||
selectedObjectId,
|
||||
currentTime,
|
||||
camera,
|
||||
setSelectedObjectId,
|
||||
isActivityMode,
|
||||
};
|
||||
|
||||
return (
|
||||
<ActivityStreamContext.Provider value={value}>
|
||||
{children}
|
||||
</ActivityStreamContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
// eslint-disable-next-line react-refresh/only-export-components
|
||||
export function useActivityStream() {
|
||||
const context = useContext(ActivityStreamContext);
|
||||
if (context === undefined) {
|
||||
throw new Error(
|
||||
"useActivityStream must be used within an ActivityStreamProvider",
|
||||
);
|
||||
}
|
||||
return context;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user