mirror of
https://github.com/getpaseo/paseo.git
synced 2026-10-30 21:23:04 +00:00
* fix(usage): fetch only when shown and add a host-wide off switch * fix(usage): restore policy defaults and isolate usage test state * refactor(usage): give the sidebar footer sole ownership of its summary
27 lines
1.0 KiB
TypeScript
27 lines
1.0 KiB
TypeScript
import { useMutation } from "@tanstack/react-query";
|
|
import { useCallback } from "react";
|
|
import { useDaemonConfig } from "@/hooks/use-daemon-config";
|
|
import { useSessionStore } from "@/stores/session-store";
|
|
|
|
/** Host policy comes from the live daemon config replica. */
|
|
export function useUsageSetting(serverId: string | null) {
|
|
const supported = useSessionStore((state) =>
|
|
Boolean(serverId && state.sessions[serverId]?.serverInfo?.features?.usageSetting),
|
|
);
|
|
const { config, patchConfig } = useDaemonConfig(supported ? serverId : null);
|
|
const mutation = useMutation({
|
|
mutationFn: (enabled: boolean) => patchConfig({ usage: { enabled } }),
|
|
});
|
|
const setEnabled = mutation.mutate;
|
|
const turnOn = useCallback(() => setEnabled(true), [setEnabled]);
|
|
return {
|
|
supported,
|
|
error: mutation.error,
|
|
// COMPAT(usageSetting): added in v0.14, remove after 2027-05-01.
|
|
enabled: !supported || (config !== null && config.usage?.enabled !== false),
|
|
ready: !supported || config !== null,
|
|
setEnabled,
|
|
turnOn,
|
|
};
|
|
}
|