Refactor UI imports and update component paths
Some checks failed
Build Frontend / build (push) Failing after 7s
Some checks failed
Build Frontend / build (push) Failing after 7s
Replaces imports from 'components/ui' with 'components/common' across the app and dashboard pages, and updates model and API imports to use new paths under 'lib'. Removes redundant authentication checks from several dashboard pages. Adds new dashboard components and utility files, and reorganizes hooks and services into the 'lib' directory for improved structure.
This commit is contained in:
57
lib/hooks/useKeepOnline.ts
Normal file
57
lib/hooks/useKeepOnline.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
import { useEffect, useRef } from "react";
|
||||
import { clientFetch } from "@/lib/api";
|
||||
|
||||
interface UseKeepOnlineOptions {
|
||||
interval?: number; // in milliseconds
|
||||
enabled?: boolean;
|
||||
onError?: (error: any) => void;
|
||||
}
|
||||
|
||||
export const useKeepOnline = (options: UseKeepOnlineOptions = {}) => {
|
||||
const {
|
||||
interval = 1000 * 60 * 1,
|
||||
enabled = true,
|
||||
onError
|
||||
} = options;
|
||||
|
||||
const intervalRef = useRef<NodeJS.Timeout | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (!enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
const updateOnlineStatus = async () => {
|
||||
try {
|
||||
console.log("Updating online status...");
|
||||
await clientFetch('/auth/me');
|
||||
} catch (error) {
|
||||
console.error("Failed to update online status:", error);
|
||||
onError?.(error);
|
||||
}
|
||||
};
|
||||
|
||||
// Initial call
|
||||
updateOnlineStatus();
|
||||
|
||||
// Set up interval
|
||||
intervalRef.current = setInterval(updateOnlineStatus, interval);
|
||||
|
||||
return () => {
|
||||
if (intervalRef.current) {
|
||||
clearInterval(intervalRef.current);
|
||||
intervalRef.current = null;
|
||||
}
|
||||
};
|
||||
}, [enabled, interval, onError]);
|
||||
|
||||
return {
|
||||
isActive: enabled && intervalRef.current !== null,
|
||||
stop: () => {
|
||||
if (intervalRef.current) {
|
||||
clearInterval(intervalRef.current);
|
||||
intervalRef.current = null;
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user