refactor: streamline data fetching in various hooks and components
Deploy to VPS / deploy (push) Successful in 2m39s

This commit is contained in:
asepharyana
2026-07-26 16:46:53 +07:00
parent 1021301656
commit 323fa207af
8 changed files with 26 additions and 15 deletions
@@ -121,8 +121,6 @@ export default function DashboardPage() {
function StatsSection() {
const { stats, loading, error, refetch } = useStats();
if (error) return <ErrorState message={error} onRetry={refetch} />;
if (loading || !stats) {
return (
<div className="space-y-5 animate-fade-in-up">
@@ -16,10 +16,6 @@ export default function MediaPage() {
const { mediaState, refresh, queue, skip, stop, setVolume } = useMediaState();
const [queueUrl, setQueueUrl] = useState("");
useEffect(() => {
refresh();
}, [refresh]);
// WS subscription for real-time media state
useEffect(() => {
const unsub = ws.on("media_state", () => refresh());
@@ -13,11 +13,7 @@ import { useWebSocket } from "@/lib/ws/context";
export default function RecordingsPage() {
const ws = useWebSocket();
const { recordings, loading, refresh, remove, prepend } = useRecordings();
useEffect(() => {
refresh();
}, [refresh]);
const { recordings, loading, remove, prepend } = useRecordings();
// WS subscription for real-time updates
useEffect(() => {
+5 -1
View File
@@ -1,4 +1,4 @@
import { useCallback, useState } from "react";
import { useCallback, useEffect, useState } from "react";
import { dashboardApi } from "@/lib/api";
import type {
@@ -36,6 +36,10 @@ export function useStats(): UseStatsReturn {
}
}, []);
useEffect(() => {
fetch();
}, [fetch]);
return { stats, loading, error, refetch: fetch };
}
+5 -1
View File
@@ -1,4 +1,4 @@
import { useCallback, useState } from "react";
import { useCallback, useEffect, useState } from "react";
import { voiceApi } from "@/lib/api";
import type { MediaState } from "@/lib/types";
@@ -69,6 +69,10 @@ export function useMediaState(): UseMediaStateReturn {
}
}, []);
useEffect(() => {
refresh();
}, [refresh]);
return { mediaState, refresh, queue, skip, stop, setVolume };
}
@@ -77,6 +77,11 @@ export function useMessages(
}
}, [cursor, loadingMore, guildId, channelId]);
// Auto-fetch when guildId/channelId changes
useEffect(() => {
fetch();
}, [fetch]);
const prepend = useCallback((msg: MessageRecord) => {
setMessages((prev) => [msg, ...prev]);
}, []);
@@ -1,4 +1,4 @@
import { useCallback, useState } from "react";
import { useCallback, useEffect, useState } from "react";
import { recordingsApi } from "@/lib/api";
import type { VoiceRecording } from "@/lib/types";
@@ -35,6 +35,10 @@ export function useRecordings(): UseRecordingsReturn {
}
}, []);
useEffect(() => {
refresh();
}, [refresh]);
const remove = useCallback(async (id: string) => {
try {
await recordingsApi.delete(id);
+5 -1
View File
@@ -1,4 +1,4 @@
import { useCallback, useState } from "react";
import { useCallback, useEffect, useState } from "react";
import { voiceApi } from "@/lib/api";
import type { ActiveSpeaker, VoiceStatus } from "@/lib/types";
@@ -28,6 +28,10 @@ export function useVoiceStatus(): UseVoiceStatusReturn {
}
}, []);
useEffect(() => {
refresh();
}, [refresh]);
return { voiceStatus, refresh };
}