Add video feed feature with related components and hooks
- Implemented VideoFeed component to display sightings. - Created useSightingList and useVideoFeed hooks for data fetching and state management. - Added AppProviders for context management. - Updated Dashboard to include VideoFeed. - Introduced types for sightings in utils/types.tsx. - Added Header and Footer components for layout. - Configured React Query for data handling.
This commit is contained in:
32
src/features/dashboard/hooks/useVideoFeed.ts
Normal file
32
src/features/dashboard/hooks/useVideoFeed.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { cambase } from "../../../app/config";
|
||||
import { useEffect, useRef } from "react";
|
||||
|
||||
const fetchVideoFeed = async (refId: number) => {
|
||||
const response = await fetch(`${cambase}/mergedHistory/sightingSummary?mostRecentRef=${refId}`);
|
||||
if (!response.ok) {
|
||||
throw new Error("Network response was not ok");
|
||||
}
|
||||
return response.json();
|
||||
};
|
||||
|
||||
export const useVideoFeed = () => {
|
||||
const currentRefId = useRef<number>(-1);
|
||||
|
||||
const videoFeedQuery = useQuery({
|
||||
queryKey: ["videoFeed"],
|
||||
queryFn: () => fetchVideoFeed(currentRefId.current),
|
||||
refetchInterval: 1000,
|
||||
refetchOnWindowFocus: false,
|
||||
retry: false,
|
||||
staleTime: 0,
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (videoFeedQuery.data?.ref !== -1) {
|
||||
currentRefId.current = videoFeedQuery?.data?.ref;
|
||||
}
|
||||
}, [videoFeedQuery.data]);
|
||||
|
||||
return { videoFeedQuery };
|
||||
};
|
||||
Reference in New Issue
Block a user