cbb703341e
Slice 4b frontend half. Jellyfin-touching pages now select a Jellyfin service instance instead of a machine. - api/client.ts: Jellyfin-backed calls (counts/libraries/activity/users, media status/build/stop/force-stop, queryMedia) send jellyfin_service_id. - hooks/useDashboard, useUsers, useMedia: selector param renamed to jellyfinServiceId. - pages/Media + Applications: list jellyfin service instances and persist jellyfin_service_id in the URL. - Dashboard (widgets) and Users (default instance) need no selector change. - Update Applications + Media tests for the new hook/param. Files/SSH transport keeps machine_id. Verification: frontend lint 0 errors, build success, 70 tests; backend ruff clean, 222 tests.
67 lines
1.8 KiB
TypeScript
67 lines
1.8 KiB
TypeScript
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
import {
|
|
deleteDashboardShortcut,
|
|
fetchActivity,
|
|
fetchCounts,
|
|
fetchDashboardShortcuts,
|
|
fetchLibraries,
|
|
saveDashboardShortcut,
|
|
} from "../api/client";
|
|
import type { DashboardShortcutInput } from "../types";
|
|
|
|
export function useCounts(jellyfinServiceId?: string) {
|
|
return useQuery({
|
|
queryKey: ["dashboard", "counts", jellyfinServiceId ?? "default"],
|
|
queryFn: () => fetchCounts(jellyfinServiceId),
|
|
staleTime: 5 * 60 * 1000,
|
|
});
|
|
}
|
|
|
|
export function useLibraries(jellyfinServiceId?: string) {
|
|
return useQuery({
|
|
queryKey: ["dashboard", "libraries", jellyfinServiceId ?? "default"],
|
|
queryFn: () => fetchLibraries(jellyfinServiceId),
|
|
staleTime: 5 * 60 * 1000,
|
|
});
|
|
}
|
|
|
|
export function useActivity(jellyfinServiceId?: string) {
|
|
return useQuery({
|
|
queryKey: ["dashboard", "activity", jellyfinServiceId ?? "default"],
|
|
queryFn: () => fetchActivity(jellyfinServiceId),
|
|
refetchInterval: 15_000,
|
|
});
|
|
}
|
|
|
|
// 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"] });
|
|
},
|
|
});
|
|
}
|