Refactor voice page and hooks to use React Query for data fetching
Deploy to VPS / deploy (push) Successful in 2m57s
Deploy to VPS / deploy (push) Successful in 2m57s
- Updated VoicePage component to utilize useVoiceConnect, useVoiceDisconnect, and useMicTransmit mutations. - Replaced local state management with React Query's useQuery for voice status, guilds, and channels. - Removed custom useAsync hook and replaced it with useQuery in useConfig, useStats, useUsers, useChannels, and useMessages hooks. - Simplified useRecordings and useSpeakers hooks to leverage React Query for data fetching and mutations. - Removed deprecated use-async hook and related code. - Enhanced error handling and loading states across various hooks.
This commit is contained in:
@@ -1,21 +1,15 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
|
||||
import { configApi } from "@/lib/api";
|
||||
import type { AppConfig } from "@/lib/types";
|
||||
import { useAsync } from "./use-async";
|
||||
|
||||
interface UseConfigReturn {
|
||||
config: AppConfig | null;
|
||||
loading: boolean;
|
||||
error: string | null;
|
||||
refetch: () => void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the app configuration from the backend.
|
||||
*/
|
||||
export function useConfig(): UseConfigReturn {
|
||||
const { data, loading, error, refetch } = useAsync<AppConfig>(
|
||||
() => configApi.get(),
|
||||
[],
|
||||
);
|
||||
return { config: data, loading, error, refetch };
|
||||
export function useConfig() {
|
||||
return useQuery<AppConfig>({
|
||||
queryKey: ["config"],
|
||||
queryFn: () => configApi.get(),
|
||||
staleTime: 120_000,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user