diff --git a/frontend/src/app/dashboard/components/RequestHistory.tsx b/frontend/src/app/dashboard/components/RequestHistory.tsx index acb40a5..b7f5373 100644 --- a/frontend/src/app/dashboard/components/RequestHistory.tsx +++ b/frontend/src/app/dashboard/components/RequestHistory.tsx @@ -7,30 +7,21 @@ import { Button } from "@/components/ui/button"; import { Card, CardContent } from "@/components/ui/card"; import { Input } from "@/components/ui/input"; import { userApi } from "@/lib/api"; -import { useSocket } from "@/lib/socket"; -export function RequestHistory() { +export function RequestHistory({ onRefresh }: { onRefresh?: () => void }) { const [requests, setRequests] = useState([]); const [status, setStatus] = useState(""); const [query, setQuery] = useState(""); - const socket = useSocket(); const load = async () => { const res = await userApi.getRequests(1, 50, status || undefined); setRequests(res.data.requests || []); + onRefresh?.(); }; useEffect(() => { load(); }, [status]); - useEffect(() => { - if (!socket) return; - const refresh = () => load(); - socket.on("request_updated", refresh); - return () => { - socket.off("request_updated", refresh); - }; - }, [socket, status]); const filtered = requests.filter( (r) => diff --git a/frontend/src/app/dashboard/page.tsx b/frontend/src/app/dashboard/page.tsx index 45c759a..dea2978 100644 --- a/frontend/src/app/dashboard/page.tsx +++ b/frontend/src/app/dashboard/page.tsx @@ -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([]); 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
Loading...
; @@ -176,7 +157,7 @@ export default function DashboardPage() { - +