"use client"; import { useState } from "react"; import { Plus } from "lucide-react"; import { Button } from "@/components/ui/button"; import { useChannels, useCreateChannel, useUpdateChannel, useDeleteChannel, useGenerateSchedule, } from "@/hooks/use-channels"; import { ChannelCard } from "./components/channel-card"; import { CreateChannelDialog } from "./components/create-channel-dialog"; import { DeleteChannelDialog } from "./components/delete-channel-dialog"; import { EditChannelSheet } from "./components/edit-channel-sheet"; import { ScheduleSheet } from "./components/schedule-sheet"; import type { ChannelResponse, ProgrammingBlock, RecyclePolicy } from "@/lib/types"; export default function DashboardPage() { const { data: channels, isLoading, error } = useChannels(); const createChannel = useCreateChannel(); const updateChannel = useUpdateChannel(); const deleteChannel = useDeleteChannel(); const generateSchedule = useGenerateSchedule(); const [createOpen, setCreateOpen] = useState(false); const [editChannel, setEditChannel] = useState(null); const [deleteTarget, setDeleteTarget] = useState(null); const [scheduleChannel, setScheduleChannel] = useState(null); const handleCreate = (data: { name: string; timezone: string; description: string; }) => { createChannel.mutate( { name: data.name, timezone: data.timezone, description: data.description || undefined }, { onSuccess: () => setCreateOpen(false) }, ); }; const handleEdit = ( id: string, data: { name: string; description: string; timezone: string; schedule_config: { blocks: ProgrammingBlock[] }; recycle_policy: RecyclePolicy; }, ) => { updateChannel.mutate( { id, data }, { onSuccess: () => setEditChannel(null) }, ); }; const handleDelete = () => { if (!deleteTarget) return; deleteChannel.mutate(deleteTarget.id, { onSuccess: () => setDeleteTarget(null), }); }; return (
{/* Header */}

My Channels

Build your broadcast lineup

{/* Content */} {isLoading && (
)} {error && (
{error.message}
)} {channels && channels.length === 0 && (

No channels yet

)} {channels && channels.length > 0 && (
{channels.map((channel) => ( setEditChannel(channel)} onDelete={() => setDeleteTarget(channel)} onGenerateSchedule={() => generateSchedule.mutate(channel.id)} onViewSchedule={() => setScheduleChannel(channel)} /> ))}
)} {/* Dialogs / sheets */} { if (!open) setEditChannel(null); }} onSubmit={handleEdit} isPending={updateChannel.isPending} error={updateChannel.error?.message} /> { if (!open) setScheduleChannel(null); }} /> {deleteTarget && ( { if (!open) setDeleteTarget(null); }} onConfirm={handleDelete} isPending={deleteChannel.isPending} /> )}
); }