fixes and improvements
This commit is contained in:
@@ -1,10 +1,14 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import {
|
||||
deleteDashboardShortcut,
|
||||
fetchActivity,
|
||||
fetchCounts,
|
||||
fetchDashboardShortcuts,
|
||||
fetchLibraries,
|
||||
fetchMonitoringOverview,
|
||||
saveDashboardShortcut,
|
||||
} from "../api/client";
|
||||
import type { DashboardShortcutInput } from "../types";
|
||||
|
||||
export function useCounts(machineId?: string) {
|
||||
return useQuery({
|
||||
@@ -40,3 +44,32 @@ export function useMonitoringOverview() {
|
||||
|
||||
// Backward-compatible alias used by older code.
|
||||
export const useNowPlaying = useActivity;
|
||||
|
||||
export function useDashboardShortcuts() {
|
||||
return useQuery({
|
||||
queryKey: ["dashboard", "shortcuts"],
|
||||
queryFn: fetchDashboardShortcuts,
|
||||
refetchInterval: 30_000,
|
||||
});
|
||||
}
|
||||
|
||||
export function useSaveDashboardShortcut() {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (shortcut: DashboardShortcutInput) =>
|
||||
saveDashboardShortcut(shortcut),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ["dashboard", "shortcuts"] });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useDeleteDashboardShortcut() {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (shortcutId: string) => deleteDashboardShortcut(shortcutId),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ["dashboard", "shortcuts"] });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user