Refactor KeepOnline logic and add useKeepOnline hook
Moved dashboard path check from KeepOnline to a new KeepOnlineWrapper component for cleaner separation of concerns. Introduced a reusable useKeepOnline hook to encapsulate the online status update logic. Updated layout to use KeepOnlineWrapper and simplified KeepOnline. Minor cleanup in broadcast-dialog.tsx.
This commit is contained in:
@@ -1,21 +1,15 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect } from "react";
|
||||
import { clientFetch } from "@/lib/api";
|
||||
import { useKeepOnline } from "@/hooks/useKeepOnline";
|
||||
|
||||
const KeepOnline = () => {
|
||||
useEffect(() => {
|
||||
if(window.location.pathname.includes("/dashboard")){
|
||||
const updateOnlineStatus = () => {
|
||||
console.log("Updating online status...");
|
||||
clientFetch('/auth/me');
|
||||
}
|
||||
|
||||
const interval = setInterval(updateOnlineStatus, 1000*60*1);
|
||||
|
||||
return () => clearInterval(interval);
|
||||
useKeepOnline({
|
||||
interval: 1000 * 60 * 1, // 1 minute
|
||||
enabled: true,
|
||||
onError: (error) => {
|
||||
console.error("Keep online error:", error);
|
||||
}
|
||||
}, []);
|
||||
});
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user