Area 1 (tv/page.tsx 964→423 lines): - hooks: use-fullscreen, use-idle, use-volume, use-quality, use-subtitles, use-channel-input, use-channel-passwords, use-tv-keyboard - components: SubtitlePicker, VolumeControl, QualityPicker, TopControlBar, LogoWatermark, AutoplayPrompt, ChannelNumberOverlay, TvBaseLayer Area 2 (edit-channel-sheet.tsx 1244→678 lines): - hooks: use-channel-form (all form state + reset logic) - lib/schemas.ts: extracted Zod schemas + extractErrors - components: AlgorithmicFilterEditor, RecyclePolicyEditor, WebhookEditor, AccessSettingsEditor, LogoEditor Area 3 (dashboard/page.tsx 406→261 lines): - hooks: use-channel-order, use-import-channel, use-regenerate-all - lib/channel-export.ts: pure export utility - components: DashboardHeader
35 lines
1.0 KiB
TypeScript
35 lines
1.0 KiB
TypeScript
"use client";
|
|
|
|
import { useState } from "react";
|
|
import { useQueryClient } from "@tanstack/react-query";
|
|
import { toast } from "sonner";
|
|
import { api } from "@/lib/api";
|
|
import type { ChannelResponse } from "@/lib/types";
|
|
|
|
export function useRegenerateAllSchedules(
|
|
channels: ChannelResponse[] | undefined,
|
|
token: string | null,
|
|
) {
|
|
const queryClient = useQueryClient();
|
|
const [isRegeneratingAll, setIsRegeneratingAll] = useState(false);
|
|
|
|
const handleRegenerateAll = async () => {
|
|
if (!token || !channels || channels.length === 0) return;
|
|
setIsRegeneratingAll(true);
|
|
let failed = 0;
|
|
for (const ch of channels) {
|
|
try {
|
|
await api.schedule.generate(ch.id, token);
|
|
queryClient.invalidateQueries({ queryKey: ["schedule", ch.id] });
|
|
} catch {
|
|
failed++;
|
|
}
|
|
}
|
|
setIsRegeneratingAll(false);
|
|
if (failed === 0) toast.success(`All ${channels.length} schedules regenerated`);
|
|
else toast.error(`${failed} schedule(s) failed to generate`);
|
|
};
|
|
|
|
return { isRegeneratingAll, handleRegenerateAll };
|
|
}
|