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.
76 lines
1.9 KiB
TypeScript
76 lines
1.9 KiB
TypeScript
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
|
|
import {
|
|
fetchMediaStatus,
|
|
buildMediaIndex,
|
|
queryMedia,
|
|
stopMediaIndexBuild,
|
|
forceStopMediaIndexBuild,
|
|
} from "../api/client";
|
|
|
|
export function useMediaStatus(jellyfinServiceId?: string) {
|
|
return useQuery({
|
|
queryKey: ["media", "status", jellyfinServiceId ?? "default"],
|
|
queryFn: () => fetchMediaStatus(jellyfinServiceId),
|
|
staleTime: 5_000,
|
|
refetchInterval: (query) =>
|
|
query.state.data?.build_running ? 1000 : false,
|
|
refetchIntervalInBackground: true,
|
|
});
|
|
}
|
|
|
|
export function useMediaQuery(params: {
|
|
libraries?: string;
|
|
types?: string;
|
|
search?: string;
|
|
hdr_filter?: string;
|
|
sort_key?: string;
|
|
sort_order?: string;
|
|
limit?: number;
|
|
offset?: number;
|
|
jellyfinServiceId?: string;
|
|
enabled?: boolean;
|
|
}) {
|
|
const { enabled = true, ...queryParams } = params;
|
|
|
|
return useQuery({
|
|
queryKey: ["media", "query", queryParams],
|
|
queryFn: () => queryMedia(queryParams),
|
|
enabled,
|
|
staleTime: 30_000,
|
|
});
|
|
}
|
|
|
|
function invalidateMedia(queryClient: ReturnType<typeof useQueryClient>) {
|
|
queryClient.invalidateQueries({ queryKey: ["media"] });
|
|
}
|
|
|
|
export function useBuildIndex(jellyfinServiceId?: string) {
|
|
const queryClient = useQueryClient();
|
|
return useMutation({
|
|
mutationFn: () => buildMediaIndex(jellyfinServiceId),
|
|
onSuccess: () => {
|
|
invalidateMedia(queryClient);
|
|
},
|
|
});
|
|
}
|
|
|
|
export function useStopBuildIndex(jellyfinServiceId?: string) {
|
|
const queryClient = useQueryClient();
|
|
return useMutation({
|
|
mutationFn: () => stopMediaIndexBuild(jellyfinServiceId),
|
|
onSuccess: () => {
|
|
invalidateMedia(queryClient);
|
|
},
|
|
});
|
|
}
|
|
|
|
export function useForceStopBuildIndex(jellyfinServiceId?: string) {
|
|
const queryClient = useQueryClient();
|
|
return useMutation({
|
|
mutationFn: () => forceStopMediaIndexBuild(jellyfinServiceId),
|
|
onSuccess: () => {
|
|
invalidateMedia(queryClient);
|
|
},
|
|
});
|
|
}
|