feat(frontend): config history and schedule rollback hooks
This commit is contained in:
@@ -117,3 +117,69 @@ export function useEpg(channelId: string, from?: string, until?: string, channel
|
|||||||
enabled: !!channelId,
|
enabled: !!channelId,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function useConfigHistory(channelId: string) {
|
||||||
|
const { token } = useAuthContext();
|
||||||
|
return useQuery({
|
||||||
|
queryKey: ["config-history", channelId],
|
||||||
|
queryFn: () => api.channels.listConfigHistory(channelId, token!),
|
||||||
|
enabled: !!token && !!channelId,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function usePinSnapshot() {
|
||||||
|
const { token } = useAuthContext();
|
||||||
|
const qc = useQueryClient();
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: ({ channelId, snapId, label }: { channelId: string; snapId: string; label: string | null }) =>
|
||||||
|
api.channels.patchConfigSnapshot(channelId, snapId, label, token!),
|
||||||
|
onSuccess: (_, { channelId }) => qc.invalidateQueries({ queryKey: ["config-history", channelId] }),
|
||||||
|
onError: (e: Error) => toast.error(e.message),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useRestoreConfig() {
|
||||||
|
const { token } = useAuthContext();
|
||||||
|
const qc = useQueryClient();
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: ({ channelId, snapId }: { channelId: string; snapId: string }) =>
|
||||||
|
api.channels.restoreConfigSnapshot(channelId, snapId, token!),
|
||||||
|
onSuccess: (_, { channelId }) => {
|
||||||
|
qc.invalidateQueries({ queryKey: ["channels"] });
|
||||||
|
qc.invalidateQueries({ queryKey: ["config-history", channelId] });
|
||||||
|
},
|
||||||
|
onError: (e: Error) => toast.error(e.message),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useScheduleHistory(channelId: string) {
|
||||||
|
const { token } = useAuthContext();
|
||||||
|
return useQuery({
|
||||||
|
queryKey: ["schedule-history", channelId],
|
||||||
|
queryFn: () => api.channels.listScheduleHistory(channelId, token!),
|
||||||
|
enabled: !!token && !!channelId,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useScheduleGeneration(channelId: string, genId: string | null) {
|
||||||
|
const { token } = useAuthContext();
|
||||||
|
return useQuery({
|
||||||
|
queryKey: ["schedule-generation", channelId, genId],
|
||||||
|
queryFn: () => api.channels.getScheduleGeneration(channelId, genId!, token!),
|
||||||
|
enabled: !!token && !!channelId && genId !== null,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useRollbackSchedule() {
|
||||||
|
const { token } = useAuthContext();
|
||||||
|
const qc = useQueryClient();
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: ({ channelId, genId }: { channelId: string; genId: string }) =>
|
||||||
|
api.channels.rollbackSchedule(channelId, genId, token!),
|
||||||
|
onSuccess: (_, { channelId }) => {
|
||||||
|
qc.invalidateQueries({ queryKey: ["schedule-history", channelId] });
|
||||||
|
qc.invalidateQueries({ queryKey: ["schedule", channelId] });
|
||||||
|
},
|
||||||
|
onError: (e: Error) => toast.error(e.message),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ import type {
|
|||||||
ActivityEvent,
|
ActivityEvent,
|
||||||
ProviderConfig,
|
ProviderConfig,
|
||||||
ProviderTestResult,
|
ProviderTestResult,
|
||||||
|
ConfigSnapshot,
|
||||||
|
ScheduleHistoryEntry,
|
||||||
} from "@/lib/types";
|
} from "@/lib/types";
|
||||||
|
|
||||||
const API_BASE =
|
const API_BASE =
|
||||||
@@ -110,6 +112,34 @@ export const api = {
|
|||||||
|
|
||||||
delete: (id: string, token: string) =>
|
delete: (id: string, token: string) =>
|
||||||
request<void>(`/channels/${id}`, { method: "DELETE", token }),
|
request<void>(`/channels/${id}`, { method: "DELETE", token }),
|
||||||
|
|
||||||
|
listConfigHistory: (channelId: string, token: string) =>
|
||||||
|
request<ConfigSnapshot[]>(`/channels/${channelId}/config/history`, { token }),
|
||||||
|
|
||||||
|
patchConfigSnapshot: (channelId: string, snapId: string, label: string | null, token: string) =>
|
||||||
|
request<ConfigSnapshot>(`/channels/${channelId}/config/history/${snapId}`, {
|
||||||
|
method: "PATCH",
|
||||||
|
body: JSON.stringify({ label }),
|
||||||
|
token,
|
||||||
|
}),
|
||||||
|
|
||||||
|
restoreConfigSnapshot: (channelId: string, snapId: string, token: string) =>
|
||||||
|
request<ChannelResponse>(`/channels/${channelId}/config/history/${snapId}/restore`, {
|
||||||
|
method: "POST",
|
||||||
|
token,
|
||||||
|
}),
|
||||||
|
|
||||||
|
listScheduleHistory: (channelId: string, token: string) =>
|
||||||
|
request<ScheduleHistoryEntry[]>(`/channels/${channelId}/schedule/history`, { token }),
|
||||||
|
|
||||||
|
getScheduleGeneration: (channelId: string, genId: string, token: string) =>
|
||||||
|
request<ScheduleResponse>(`/channels/${channelId}/schedule/history/${genId}`, { token }),
|
||||||
|
|
||||||
|
rollbackSchedule: (channelId: string, genId: string, token: string) =>
|
||||||
|
request<ScheduleResponse>(`/channels/${channelId}/schedule/history/${genId}/rollback`, {
|
||||||
|
method: "POST",
|
||||||
|
token,
|
||||||
|
}),
|
||||||
},
|
},
|
||||||
|
|
||||||
library: {
|
library: {
|
||||||
|
|||||||
Reference in New Issue
Block a user