"use client"; import { useState } from "react"; import { Center, Divider, Group, Pagination, SegmentedControl, Stack, Text } from "@mantine/core"; import type { TablerIcon } from "@tabler/icons-react"; import { IconClipboardList, IconCpu2, IconReportAnalytics } from "@tabler/icons-react"; import { clientApi } from "@homarr/api/client"; import { useI18n } from "@homarr/translation/client"; import { views } from "."; import type { WidgetComponentProps } from "../definition"; import { HealthCheckStatus } from "./health-check-status"; import { QueuePanel } from "./panels/queue.panel"; import { StatisticsPanel } from "./panels/statistics.panel"; import { WorkersPanel } from "./panels/workers.panel"; type View = (typeof views)[number]; const viewIcons = { workers: IconCpu2, queue: IconClipboardList, statistics: IconReportAnalytics, } satisfies Record; export default function MediaTranscodingWidget({ integrationIds, options, width, }: WidgetComponentProps<"mediaTranscoding">) { const [queuePage, setQueuePage] = useState(1); const queuePageSize = 10; const [transcodingData] = clientApi.widget.mediaTranscoding.getDataAsync.useSuspenseQuery( { integrationId: integrationIds[0] ?? "", pageSize: queuePageSize, page: queuePage, }, { refetchOnMount: false, refetchOnWindowFocus: false, refetchOnReconnect: false, }, ); const [view, setView] = useState(options.defaultView); const totalQueuePages = Math.ceil((transcodingData.data.queue.totalCount || 1) / queuePageSize); const t = useI18n("widget.mediaTranscoding"); const isTiny = width < 256; return ( {view === "workers" ? ( ) : view === "queue" ? ( ) : ( )} { const Icon = viewIcons[value]; return { label: (
{!isTiny && ( {t(`tab.${value}`)} )}
), value, }; })} value={view} onChange={(value) => setView(value as View)} size="xs" /> {view === "queue" && ( <> {!isTiny && } {!isTiny && } {t("currentIndex", { start: String(transcodingData.data.queue.startIndex + 1), end: String(transcodingData.data.queue.endIndex + 1), total: String(transcodingData.data.queue.totalCount), })} )}
); }