refactor: streamline data fetching in various hooks and components
Deploy to VPS / deploy (push) Successful in 2m39s
Deploy to VPS / deploy (push) Successful in 2m39s
This commit is contained in:
@@ -121,8 +121,6 @@ export default function DashboardPage() {
|
|||||||
function StatsSection() {
|
function StatsSection() {
|
||||||
const { stats, loading, error, refetch } = useStats();
|
const { stats, loading, error, refetch } = useStats();
|
||||||
|
|
||||||
if (error) return <ErrorState message={error} onRetry={refetch} />;
|
|
||||||
|
|
||||||
if (loading || !stats) {
|
if (loading || !stats) {
|
||||||
return (
|
return (
|
||||||
<div className="space-y-5 animate-fade-in-up">
|
<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 { mediaState, refresh, queue, skip, stop, setVolume } = useMediaState();
|
||||||
const [queueUrl, setQueueUrl] = useState("");
|
const [queueUrl, setQueueUrl] = useState("");
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
refresh();
|
|
||||||
}, [refresh]);
|
|
||||||
|
|
||||||
// WS subscription for real-time media state
|
// WS subscription for real-time media state
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const unsub = ws.on("media_state", () => refresh());
|
const unsub = ws.on("media_state", () => refresh());
|
||||||
|
|||||||
@@ -13,11 +13,7 @@ import { useWebSocket } from "@/lib/ws/context";
|
|||||||
|
|
||||||
export default function RecordingsPage() {
|
export default function RecordingsPage() {
|
||||||
const ws = useWebSocket();
|
const ws = useWebSocket();
|
||||||
const { recordings, loading, refresh, remove, prepend } = useRecordings();
|
const { recordings, loading, remove, prepend } = useRecordings();
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
refresh();
|
|
||||||
}, [refresh]);
|
|
||||||
|
|
||||||
// WS subscription for real-time updates
|
// WS subscription for real-time updates
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { useCallback, useState } from "react";
|
import { useCallback, useEffect, useState } from "react";
|
||||||
|
|
||||||
import { dashboardApi } from "@/lib/api";
|
import { dashboardApi } from "@/lib/api";
|
||||||
import type {
|
import type {
|
||||||
@@ -36,6 +36,10 @@ export function useStats(): UseStatsReturn {
|
|||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
fetch();
|
||||||
|
}, [fetch]);
|
||||||
|
|
||||||
return { stats, loading, error, refetch: fetch };
|
return { stats, loading, error, refetch: fetch };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { useCallback, useState } from "react";
|
import { useCallback, useEffect, useState } from "react";
|
||||||
|
|
||||||
import { voiceApi } from "@/lib/api";
|
import { voiceApi } from "@/lib/api";
|
||||||
import type { MediaState } from "@/lib/types";
|
import type { MediaState } from "@/lib/types";
|
||||||
@@ -69,6 +69,10 @@ export function useMediaState(): UseMediaStateReturn {
|
|||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
refresh();
|
||||||
|
}, [refresh]);
|
||||||
|
|
||||||
return { mediaState, refresh, queue, skip, stop, setVolume };
|
return { mediaState, refresh, queue, skip, stop, setVolume };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -77,6 +77,11 @@ export function useMessages(
|
|||||||
}
|
}
|
||||||
}, [cursor, loadingMore, guildId, channelId]);
|
}, [cursor, loadingMore, guildId, channelId]);
|
||||||
|
|
||||||
|
// Auto-fetch when guildId/channelId changes
|
||||||
|
useEffect(() => {
|
||||||
|
fetch();
|
||||||
|
}, [fetch]);
|
||||||
|
|
||||||
const prepend = useCallback((msg: MessageRecord) => {
|
const prepend = useCallback((msg: MessageRecord) => {
|
||||||
setMessages((prev) => [msg, ...prev]);
|
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 { recordingsApi } from "@/lib/api";
|
||||||
import type { VoiceRecording } from "@/lib/types";
|
import type { VoiceRecording } from "@/lib/types";
|
||||||
@@ -35,6 +35,10 @@ export function useRecordings(): UseRecordingsReturn {
|
|||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
refresh();
|
||||||
|
}, [refresh]);
|
||||||
|
|
||||||
const remove = useCallback(async (id: string) => {
|
const remove = useCallback(async (id: string) => {
|
||||||
try {
|
try {
|
||||||
await recordingsApi.delete(id);
|
await recordingsApi.delete(id);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { useCallback, useState } from "react";
|
import { useCallback, useEffect, useState } from "react";
|
||||||
|
|
||||||
import { voiceApi } from "@/lib/api";
|
import { voiceApi } from "@/lib/api";
|
||||||
import type { ActiveSpeaker, VoiceStatus } from "@/lib/types";
|
import type { ActiveSpeaker, VoiceStatus } from "@/lib/types";
|
||||||
@@ -28,6 +28,10 @@ export function useVoiceStatus(): UseVoiceStatusReturn {
|
|||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
refresh();
|
||||||
|
}, [refresh]);
|
||||||
|
|
||||||
return { voiceStatus, refresh };
|
return { voiceStatus, refresh };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user