Build & Deploy (Nix) / build-and-deploy (backend) (push) Successful in 2m56s
Build & Deploy (Nix) / build-and-deploy (discord-gateway) (push) Successful in 3m42s
Build & Deploy (Nix) / build-and-deploy (proxy) (push) Successful in 3m59s
Rombak data layer frontend: - Hapus @tanstack/react-query (package.json, lockfile, provider di dashboard layout) — ganti SWR 2.4.2 + SWRConfig (revalidateOnFocus false, deduping 10s, no retry on 404) - Semua hooks data ditulis ulang ke useSWR; useAction() helper baru pengganti useMutation dengan surface kompatibel (mutate/mutateAsync/ isPending/error) - useMessages + useMessagesHasMore share satu SWR key — probe cursor yang tadinya dobel fetch API sekarang deduped - WS sync (messages/media/recordings) pindah dari queryClient ke SWR mutate dengan filter key + revalidate:false - useMessageSearch() dipakai search-panel & search-overlay; search overlay backdrop div -> button (fix a11y lint) Rapikan UI + isi data: - Tab stats recordings: placeholder 'coming soon' diganti stat asli (total, ukuran, speaker unik, top speakers) - Empty states konsisten via EmptyState (images/review/recordings), EmptyState terima className - biome check --write: 0 error, 8 warning pre-existing - Verifikasi: tsc --noEmit PASS, next build PASS (11 halaman static), API live dicek — semua endpoint dashboard/messages/guilds/config/ voice/media/recordings/review balikin data
56 lines
1.6 KiB
TypeScript
56 lines
1.6 KiB
TypeScript
import { useCallback, useRef, useState } from "react";
|
|
|
|
export interface UseActionState {
|
|
isPending: boolean;
|
|
error: Error | null;
|
|
}
|
|
|
|
/**
|
|
* A lightweight mutation hook with a TanStack-compatible surface
|
|
* ({ mutate, mutateAsync, isPending, error }) built on plain state —
|
|
* the SWR replacement for useMutation. Fire-and-forget via `mutate`,
|
|
* await the result via `mutateAsync`.
|
|
*
|
|
* `onSuccess` receives (data, args) and may perform SWR cache updates
|
|
* (e.g. `mutate(key, data, { revalidate: false })`).
|
|
*/
|
|
export function useAction<TArgs = void, TResult = unknown>(
|
|
fn: (args: TArgs) => Promise<TResult>,
|
|
options?: {
|
|
onSuccess?: (data: TResult, args: TArgs) => void | Promise<void>;
|
|
},
|
|
) {
|
|
const [state, setState] = useState<UseActionState>({
|
|
isPending: false,
|
|
error: null,
|
|
});
|
|
|
|
const fnRef = useRef(fn);
|
|
fnRef.current = fn;
|
|
const onSuccessRef = useRef(options?.onSuccess);
|
|
onSuccessRef.current = options?.onSuccess;
|
|
|
|
const run = useCallback(async (args?: TArgs): Promise<TResult> => {
|
|
setState({ isPending: true, error: null });
|
|
try {
|
|
const data = await fnRef.current(args as TArgs);
|
|
await onSuccessRef.current?.(data, args as TArgs);
|
|
setState({ isPending: false, error: null });
|
|
return data;
|
|
} catch (err) {
|
|
setState({ isPending: false, error: err as Error });
|
|
throw err;
|
|
}
|
|
}, []);
|
|
|
|
return {
|
|
mutate: (args?: TArgs) => {
|
|
void run(args);
|
|
},
|
|
mutateAsync: run,
|
|
isPending: state.isPending,
|
|
error: state.error,
|
|
reset: () => setState({ isPending: false, error: null }),
|
|
};
|
|
}
|