fix: remove dashboard auto-refresh churn
This commit is contained in:
@@ -13,7 +13,6 @@ import {
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
|
||||
import { api, authApi, overseerApi, userApi } from "@/lib/api";
|
||||
import { useSocket } from "@/lib/socket";
|
||||
import { useStore } from "@/lib/store";
|
||||
import { formatNumber } from "@/lib/utils";
|
||||
import { ActivityFeed } from "./components/ActivityFeed";
|
||||
@@ -36,7 +35,6 @@ export default function DashboardPage() {
|
||||
const [pendingRequests, setPendingRequests] = useState<any[]>([]);
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
const [isSearchModalOpen, setIsSearchModalOpen] = useState(false);
|
||||
const socket = useSocket();
|
||||
|
||||
useEffect(() => {
|
||||
if (!isAuthenticated) {
|
||||
@@ -46,26 +44,6 @@ export default function DashboardPage() {
|
||||
loadWalletAndPending();
|
||||
loadCosts();
|
||||
}, [isAuthenticated, router]);
|
||||
useEffect(() => {
|
||||
const id = setInterval(() => {
|
||||
if (isAuthenticated) loadWalletAndPending();
|
||||
}, 30000);
|
||||
return () => clearInterval(id);
|
||||
}, [isAuthenticated]);
|
||||
useEffect(() => {
|
||||
if (!socket) return;
|
||||
const refresh = () => loadWalletAndPending();
|
||||
socket.on("credits_earned", refresh);
|
||||
socket.on("bonus_received", refresh);
|
||||
socket.on("credits_spent", refresh);
|
||||
socket.on("request_updated", refresh);
|
||||
return () => {
|
||||
socket.off("credits_earned", refresh);
|
||||
socket.off("bonus_received", refresh);
|
||||
socket.off("credits_spent", refresh);
|
||||
socket.off("request_updated", refresh);
|
||||
};
|
||||
}, [socket]);
|
||||
|
||||
const loadWalletAndPending = async () => {
|
||||
try {
|
||||
@@ -94,6 +72,9 @@ export default function DashboardPage() {
|
||||
logout();
|
||||
router.push("/login");
|
||||
};
|
||||
const handleRefresh = () => {
|
||||
loadWalletAndPending();
|
||||
};
|
||||
|
||||
if (isLoading) return <div className="p-8">Loading...</div>;
|
||||
|
||||
@@ -176,7 +157,7 @@ export default function DashboardPage() {
|
||||
<WatchHistory />
|
||||
</TabsContent>
|
||||
<TabsContent value="requests">
|
||||
<RequestHistory />
|
||||
<RequestHistory onRefresh={handleRefresh} />
|
||||
</TabsContent>
|
||||
<TabsContent value="leaderboard">
|
||||
<Leaderboard />
|
||||
|
||||
Reference in New Issue
Block a user