feat!: release v2 (#6545)
Co-authored-by: Artur <145776561+arturict@users.noreply.github.com> Co-authored-by: arturict <arturict@users.noreply.github.com> Co-authored-by: Thomas <thomas@ajnart.fr> Co-authored-by: Afonso Jorge Ramos <afonsojorgeramos@gmail.com> Co-authored-by: Danura30082 <danura30082+github@gmail.com> Co-authored-by: Kushie <122986913+kushiemoon-dev@users.noreply.github.com> Co-authored-by: ajnart <thomas@ajnart.fr> Co-authored-by: ajnart <thomas@ajnart.dev> Co-authored-by: chenjun <chenjun@foxmail.com> Co-authored-by: Wikibear <wikibear@users.noreply.github.com> Co-authored-by: Bergasha <bergasha@gmail.com> Co-authored-by: leafyelin <43306196+leafyelin@users.noreply.github.com> Co-authored-by: Lucas Araujo <lucas.lra@gmail.com> Co-authored-by: GreenMonito <86085570+GreenMonito@users.noreply.github.com> Co-authored-by: Nerdy-Technician <roffo@nerdy-technician.social> Co-authored-by: Jun <34545896+jcstrong@users.noreply.github.com> Co-authored-by: Edmond Abraham <54119952+gitedmond@users.noreply.github.com> Co-authored-by: thrawnx <tight.bulb9384@fastmail.com> Co-authored-by: Chris <58918656+nordada@users.noreply.github.com> Co-authored-by: yi111 <153097222+Yi-111-a@users.noreply.github.com> Co-authored-by: Yanis <naamaneyanis@gmail.com> Co-authored-by: Wikibear <me@sej.de> Co-authored-by: alessiottavo <93441886+alessiottavo@users.noreply.github.com>
This commit is contained in:
3286 files changed
+284386
-139176
No files matched your search
@@ -4,35 +4,32 @@
|
||||
display: flex;
|
||||
text-decoration: none;
|
||||
color: inherit;
|
||||
border: 1px solid var(--border-color);
|
||||
border: 1px solid rgb(from var(--mantine-color-default-border) r g b / calc(var(--opacity, 1) * 0.45));
|
||||
background-color: transparent;
|
||||
transition:
|
||||
border-color 120ms ease,
|
||||
transform 120ms ease,
|
||||
box-shadow 120ms ease;
|
||||
background-color 120ms ease;
|
||||
|
||||
@mixin dark {
|
||||
--border-color: var(--mantine-color-dark-4);
|
||||
}
|
||||
@mixin light {
|
||||
--border-color: var(--mantine-color-gray-3);
|
||||
}
|
||||
|
||||
&:hover {
|
||||
&:hover,
|
||||
&:focus-visible {
|
||||
border-color: var(--mantine-primary-color-filled);
|
||||
transform: translateY(-1px);
|
||||
box-shadow: var(--mantine-shadow-sm);
|
||||
background-color: rgb(from var(--mantine-color-default-hover) r g b / calc(var(--opacity, 1) * 0.14));
|
||||
}
|
||||
|
||||
&:focus-visible {
|
||||
outline: 2px solid var(--mantine-primary-color-filled);
|
||||
outline-offset: -2px;
|
||||
}
|
||||
}
|
||||
|
||||
.backdrop {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
background-size: cover;
|
||||
background-position: center;
|
||||
filter: blur(20px) saturate(1.2);
|
||||
transform: scale(1.3);
|
||||
opacity: 0.16;
|
||||
pointer-events: none;
|
||||
:global(.mediaMissing-wrapper) :global(.mantine-SimpleGrid-root) > :global(.mantine-Paper-root) {
|
||||
border-color: rgb(from var(--mantine-color-default-border) r g b / calc(var(--opacity, 1) * 0.45));
|
||||
background-color: transparent;
|
||||
}
|
||||
|
||||
:global(.mediaMissing-wrapper) :global(.mantine-Tabs-list) {
|
||||
--tab-border-color: rgb(from var(--mantine-color-default-border) r g b / calc(var(--opacity, 1) * 0.45));
|
||||
--tab-hover-color: rgb(from var(--mantine-color-default-hover) r g b / calc(var(--opacity, 1) * 0.14));
|
||||
}
|
||||
|
||||
.content {
|
||||
@@ -47,3 +44,9 @@
|
||||
object-fit: cover;
|
||||
box-shadow: var(--mantine-shadow-sm);
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.card {
|
||||
transition: none;
|
||||
}
|
||||
}
|
||||
@@ -1,29 +1,108 @@
|
||||
"use client";
|
||||
|
||||
import type { ReactNode } from "react";
|
||||
import { Badge, Box, Center, Group, Image, Paper, RingProgress, ScrollArea, SimpleGrid, Stack, Tabs, Text, ThemeIcon } from "@mantine/core";
|
||||
import { IconDownload, IconMovie, IconQuestionMark, IconVideo } from "@tabler/icons-react";
|
||||
import type { CSSProperties, ReactNode } from "react";
|
||||
import { useEffect, useMemo, useRef, useState } from "react";
|
||||
import {
|
||||
Badge,
|
||||
Box,
|
||||
Center,
|
||||
Group,
|
||||
Image,
|
||||
Paper,
|
||||
RingProgress,
|
||||
ScrollArea,
|
||||
SimpleGrid,
|
||||
Stack,
|
||||
Tabs,
|
||||
Text,
|
||||
ThemeIcon,
|
||||
Tooltip,
|
||||
} from "@mantine/core";
|
||||
import { IconBook, IconDownload, IconMovie, IconQuestionMark, IconVideo } from "@tabler/icons-react";
|
||||
import { getQueryKey } from "@trpc/react-query";
|
||||
|
||||
import { clientApi } from "@homarr/api/client";
|
||||
import type { MissingMediaItem, QueuedMediaItem } from "@homarr/integrations/types";
|
||||
import { useScopedI18n } from "@homarr/translation/client";
|
||||
import { useI18n } from "@homarr/translation/client";
|
||||
import { zoomCompensatedSize } from "@homarr/ui";
|
||||
|
||||
import { WidgetEmptyState } from "../common/empty-state";
|
||||
import { getSafeApplicationUrl, SAFE_NEW_TAB_REL } from "../common/application-url";
|
||||
import { getUsableWidgetQueryData } from "../common/query-state";
|
||||
import type { WidgetComponentProps } from "../definition";
|
||||
import { useWidgetRuntimeQueries } from "../runtime-hooks";
|
||||
import { NoIntegrationDataError } from "../errors/no-data-integration";
|
||||
import classes from "./component.module.css";
|
||||
import type { MediaMissingTab } from "./tabs";
|
||||
import { resolveMediaMissingTab } from "./tabs";
|
||||
|
||||
export default function MediaMissingWidget({ integrationIds, options, width, height }: WidgetComponentProps<"mediaMissing">) {
|
||||
const t = useScopedI18n("widget.mediaMissing");
|
||||
const pageSize = Number(options.pageSize);
|
||||
const { data } = clientApi.widget.mediaOrganizer.getData.useQuery(
|
||||
{ integrationIds, pageSize },
|
||||
{ staleTime: 60 * 1000, refetchOnWindowFocus: false, refetchOnReconnect: false },
|
||||
);
|
||||
type Density = "thin" | "compact" | "comfortable";
|
||||
|
||||
const MIN_CARD_WIDTH = 280;
|
||||
const MAX_COLUMNS = 4;
|
||||
const GRID_HORIZONTAL_PADDING = 20;
|
||||
const GRID_COLUMN_GAP = 10;
|
||||
|
||||
const columnBreakpoints = Array.from({ length: MAX_COLUMNS }, (_, index) => {
|
||||
const columns = MAX_COLUMNS - index;
|
||||
return {
|
||||
columns,
|
||||
minimumWidth: columns * MIN_CARD_WIDTH + (columns - 1) * GRID_COLUMN_GAP,
|
||||
};
|
||||
});
|
||||
|
||||
const getMediaMissingGridLayout = (panelWidth: number) => {
|
||||
const contentWidth = Math.max(0, panelWidth - GRID_HORIZONTAL_PADDING);
|
||||
const breakpoint = columnBreakpoints.find((candidate) => contentWidth >= candidate.minimumWidth);
|
||||
return { columns: breakpoint?.columns ?? 1, contentWidth };
|
||||
};
|
||||
|
||||
const getMediaMissingDensity = (contentWidth: number, columns: number, isThin: boolean): Density => {
|
||||
if (isThin) return "thin";
|
||||
if (contentWidth > 0 && contentWidth / columns < 180) return "compact";
|
||||
return "comfortable";
|
||||
};
|
||||
|
||||
export default function MediaMissingWidget({
|
||||
integrationIds,
|
||||
options,
|
||||
width,
|
||||
displayMode,
|
||||
widgetRuntimeRef,
|
||||
}: WidgetComponentProps<"mediaMissing">) {
|
||||
const t = useI18n("widget.mediaMissing");
|
||||
const isAdvanced = displayMode === "advanced";
|
||||
const showMissing = isAdvanced || options.showMissing;
|
||||
const showQueued = isAdvanced || options.showQueued;
|
||||
const pageSize = isAdvanced ? Math.max(Number(options.pageSize), 50) : Number(options.pageSize);
|
||||
const input = { integrationIds, pageSize };
|
||||
useWidgetRuntimeQueries(widgetRuntimeRef, [getQueryKey(clientApi.widget.mediaOrganizer.getData, input, "query")]);
|
||||
const mediaQuery = clientApi.widget.mediaOrganizer.getData.useQuery(input, {
|
||||
staleTime: 60 * 1000,
|
||||
refetchOnWindowFocus: false,
|
||||
refetchOnReconnect: false,
|
||||
});
|
||||
const data = getUsableWidgetQueryData(mediaQuery);
|
||||
const [selectedTab, setSelectedTab] = useState<MediaMissingTab>(showMissing ? "missing" : "queued");
|
||||
const tabScrollPositionsRef = useRef<Record<MediaMissingTab, { x: number; y: number }>>({
|
||||
missing: { x: 0, y: 0 },
|
||||
queued: { x: 0, y: 0 },
|
||||
});
|
||||
const activeTab = resolveMediaMissingTab(selectedTab, showMissing, showQueued);
|
||||
|
||||
useEffect(() => {
|
||||
if (activeTab !== null && activeTab !== selectedTab) setSelectedTab(activeTab);
|
||||
}, [activeTab, selectedTab]);
|
||||
|
||||
const enabledPanelCount = Number(showMissing) + Number(showQueued);
|
||||
const panelWidth = isAdvanced && enabledPanelCount > 1 ? width / enabledPanelCount : width;
|
||||
const isThin = !isAdvanced && panelWidth > 0 && panelWidth < 160;
|
||||
const gridLayout = useMemo(() => getMediaMissingGridLayout(panelWidth), [panelWidth]);
|
||||
const density = getMediaMissingDensity(gridLayout.contentWidth, gridLayout.columns, isThin);
|
||||
|
||||
if (!data) return <WidgetEmptyState />;
|
||||
if (data.length === 0) throw new NoIntegrationDataError();
|
||||
if (!options.showMissing && !options.showQueued)
|
||||
if (!showMissing && !showQueued)
|
||||
return (
|
||||
<Center h="100%" p="sm">
|
||||
<Text c="dimmed" size="sm" ta="center">
|
||||
@@ -32,35 +111,40 @@ export default function MediaMissingWidget({ integrationIds, options, width, hei
|
||||
</Center>
|
||||
);
|
||||
|
||||
const missing = data.flatMap((entry) =>
|
||||
entry.missing.map((item) => ({ item, integrationId: entry.integrationId })),
|
||||
);
|
||||
const queued = data.flatMap((entry) =>
|
||||
entry.queued.map((item) => ({ item, integrationId: entry.integrationId })),
|
||||
);
|
||||
const missing = data.flatMap((entry) => entry.missing.map((item) => ({ item, integrationId: entry.integrationId })));
|
||||
const queued = data.flatMap((entry) => entry.queued.map((item) => ({ item, integrationId: entry.integrationId })));
|
||||
const missingCount = data.reduce((sum, entry) => sum + entry.missingCount, 0);
|
||||
const queuedCount = data.reduce((sum, entry) => sum + entry.queuedCount, 0);
|
||||
const failedIntegrations = data.filter((entry): entry is typeof entry & { error: string } => Boolean(entry.error));
|
||||
|
||||
const isThin = width > 0 && width < 160;
|
||||
const isShort = height > 0 && height < 180;
|
||||
const targetCardWidth = isShort ? 130 : 200;
|
||||
const columns = width > 0 ? Math.max(1, Math.min(Math.floor(width / targetCardWidth), 4)) : 1;
|
||||
const density: Density = isThin ? "thin" : width > 0 && width / columns < 180 ? "compact" : "comfortable";
|
||||
const tabLabel = (label: string, shown: number, total: number) => (isThin ? total : `${label} (${shown}/${total})`);
|
||||
|
||||
const tabLabel = (label: string, shown: number, total: number) =>
|
||||
isThin ? total : `${label} (${shown}/${total})`;
|
||||
|
||||
const renderPanel = (entries: { item: MissingMediaItem | QueuedMediaItem; integrationId: string }[], emptyLabel: string) => (
|
||||
<ScrollArea h="100%" scrollbarSize={4}>
|
||||
const renderPanel = (
|
||||
tab: MediaMissingTab,
|
||||
entries: { item: MissingMediaItem | QueuedMediaItem; integrationId: string }[],
|
||||
emptyLabel: string,
|
||||
) => (
|
||||
<ScrollArea
|
||||
h="100%"
|
||||
startScrollPosition={tabScrollPositionsRef.current[tab]}
|
||||
onScrollPositionChange={(position) => {
|
||||
tabScrollPositionsRef.current[tab] = position;
|
||||
}}
|
||||
>
|
||||
<Box p="xs">
|
||||
{entries.length === 0 ? (
|
||||
<Text size="sm" c="dimmed" ta="center" py="md">
|
||||
{emptyLabel}
|
||||
</Text>
|
||||
) : (
|
||||
<SimpleGrid cols={columns} spacing="xs" verticalSpacing="xs">
|
||||
<SimpleGrid cols={Math.min(gridLayout.columns, entries.length)} spacing="xs" verticalSpacing="xs">
|
||||
{entries.map(({ item, integrationId }) => (
|
||||
<MediaCard key={`${integrationId}-${item.type}-${item.id}`} item={item} density={density} />
|
||||
<MediaCard
|
||||
key={`${integrationId}-${item.type}-${item.id}`}
|
||||
item={item}
|
||||
density={density}
|
||||
showQueueDetails={isAdvanced}
|
||||
/>
|
||||
))}
|
||||
</SimpleGrid>
|
||||
)}
|
||||
@@ -68,46 +152,117 @@ export default function MediaMissingWidget({ integrationIds, options, width, hei
|
||||
</ScrollArea>
|
||||
);
|
||||
|
||||
const partialFailures = failedIntegrations.length > 0 && (
|
||||
<Group gap={4} p={4} wrap="wrap">
|
||||
{failedIntegrations.map((entry) => (
|
||||
<Tooltip key={entry.integrationId} label={`${entry.integrationName}: ${t("name")}`}>
|
||||
<Badge size="xs" color="red" variant="light">
|
||||
{entry.integrationName}
|
||||
</Badge>
|
||||
</Tooltip>
|
||||
))}
|
||||
</Group>
|
||||
);
|
||||
if (isAdvanced) {
|
||||
return (
|
||||
<Stack h="100%" gap={0}>
|
||||
{partialFailures}
|
||||
<SimpleGrid cols={enabledPanelCount} spacing="sm" p="sm" style={{ flex: 1, minHeight: 0 }}>
|
||||
{showMissing && (
|
||||
<Paper withBorder radius="sm" style={{ minHeight: 0, overflow: "hidden" }}>
|
||||
<Group p="xs" gap="xs">
|
||||
<IconQuestionMark size="var(--mantine-font-size-md)" />
|
||||
<Text size="sm" fw={600}>
|
||||
{tabLabel(t("tab.missing"), missing.length, missingCount)}
|
||||
</Text>
|
||||
</Group>
|
||||
<Box h="calc(100% - 40px)">{renderPanel("missing", missing, t("empty.missing"))}</Box>
|
||||
</Paper>
|
||||
)}
|
||||
{showQueued && (
|
||||
<Paper withBorder radius="sm" style={{ minHeight: 0, overflow: "hidden" }}>
|
||||
<Group p="xs" gap="xs">
|
||||
<IconDownload size="var(--mantine-font-size-md)" />
|
||||
<Text size="sm" fw={600}>
|
||||
{tabLabel(t("tab.queued"), queued.length, queuedCount)}
|
||||
</Text>
|
||||
</Group>
|
||||
<Box h="calc(100% - 40px)">{renderPanel("queued", queued, t("empty.queued"))}</Box>
|
||||
</Paper>
|
||||
)}
|
||||
</SimpleGrid>
|
||||
</Stack>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Tabs
|
||||
defaultValue={options.showMissing ? "missing" : "queued"}
|
||||
value={activeTab}
|
||||
keepMounted={false}
|
||||
onChange={(value) => {
|
||||
if (value === "missing" || value === "queued") setSelectedTab(value);
|
||||
}}
|
||||
h="100%"
|
||||
style={{ display: "flex", flexDirection: "column" }}
|
||||
>
|
||||
{partialFailures}
|
||||
<Tabs.List grow>
|
||||
{options.showMissing && (
|
||||
<Tabs.Tab value="missing" px={isThin ? 6 : undefined} leftSection={<IconQuestionMark size={14} />}>
|
||||
{showMissing && (
|
||||
<Tabs.Tab
|
||||
value="missing"
|
||||
px={isThin ? 6 : undefined}
|
||||
leftSection={<IconQuestionMark size="var(--mantine-font-size-sm)" />}
|
||||
>
|
||||
{tabLabel(t("tab.missing"), missing.length, missingCount)}
|
||||
</Tabs.Tab>
|
||||
)}
|
||||
{options.showQueued && (
|
||||
<Tabs.Tab value="queued" px={isThin ? 6 : undefined} leftSection={<IconDownload size={14} />}>
|
||||
{showQueued && (
|
||||
<Tabs.Tab
|
||||
value="queued"
|
||||
px={isThin ? 6 : undefined}
|
||||
leftSection={<IconDownload size="var(--mantine-font-size-sm)" />}
|
||||
>
|
||||
{tabLabel(t("tab.queued"), queued.length, queuedCount)}
|
||||
</Tabs.Tab>
|
||||
)}
|
||||
</Tabs.List>
|
||||
|
||||
{options.showMissing && (
|
||||
{showMissing && (
|
||||
<Tabs.Panel value="missing" flex={1} style={{ overflow: "hidden" }}>
|
||||
{renderPanel(missing, t("empty.missing"))}
|
||||
{activeTab === "missing" && renderPanel("missing", missing, t("empty.missing"))}
|
||||
</Tabs.Panel>
|
||||
)}
|
||||
{options.showQueued && (
|
||||
{showQueued && (
|
||||
<Tabs.Panel value="queued" flex={1} style={{ overflow: "hidden" }}>
|
||||
{renderPanel(queued, t("empty.queued"))}
|
||||
{activeTab === "queued" && renderPanel("queued", queued, t("empty.queued"))}
|
||||
</Tabs.Panel>
|
||||
)}
|
||||
</Tabs>
|
||||
);
|
||||
}
|
||||
|
||||
type Density = "thin" | "compact" | "comfortable";
|
||||
|
||||
const CARD_HEIGHT: Record<Density, number> = { thin: 52, compact: 56, comfortable: 68 };
|
||||
|
||||
const posterSizes: Record<Density, number> = { thin: 34, compact: 40, comfortable: 52 };
|
||||
|
||||
const Poster = ({ src, type, density }: { src?: string | null; type: "movie" | "episode"; density: Density }) => {
|
||||
const posterColor = (type: "movie" | "episode" | "book") =>
|
||||
type === "movie" ? "yellow" : type === "book" ? "grape" : "blue";
|
||||
|
||||
const PosterIcon = ({ type, style }: { type: "movie" | "episode" | "book"; style: CSSProperties }) => {
|
||||
if (type === "movie") return <IconMovie style={style} />;
|
||||
if (type === "book") return <IconBook style={style} />;
|
||||
return <IconVideo style={style} />;
|
||||
};
|
||||
|
||||
const Poster = ({
|
||||
src,
|
||||
type,
|
||||
density,
|
||||
}: {
|
||||
src?: string | null;
|
||||
type: "movie" | "episode" | "book";
|
||||
density: Density;
|
||||
}) => {
|
||||
const size = posterSizes[density];
|
||||
const w = Math.round(size * 0.68);
|
||||
|
||||
@@ -116,8 +271,8 @@ const Poster = ({ src, type, density }: { src?: string | null; type: "movie" | "
|
||||
}
|
||||
|
||||
return (
|
||||
<ThemeIcon className={classes.poster} h={size} w={w} radius="sm" variant="light" color={type === "movie" ? "yellow" : "blue"}>
|
||||
{type === "movie" ? <IconMovie size={size * 0.5} /> : <IconVideo size={size * 0.5} />}
|
||||
<ThemeIcon className={classes.poster} h={size} w={w} radius="sm" variant="light" color={posterColor(type)}>
|
||||
<PosterIcon type={type} style={zoomCompensatedSize(size * 0.5)} />
|
||||
</ThemeIcon>
|
||||
);
|
||||
};
|
||||
@@ -128,8 +283,8 @@ const episodeCode = (item: MissingMediaItem | QueuedMediaItem) =>
|
||||
: null;
|
||||
|
||||
const TypeBadge = ({ item, density }: { item: MissingMediaItem | QueuedMediaItem; density: Density }) => {
|
||||
const t = useScopedI18n("widget.mediaMissing");
|
||||
const color = item.type === "movie" ? "yellow" : "blue";
|
||||
const t = useI18n("widget.mediaMissing");
|
||||
const color = posterColor(item.type);
|
||||
const code = episodeCode(item);
|
||||
|
||||
if (density !== "comfortable") {
|
||||
@@ -183,16 +338,41 @@ const ProgressRing = ({ percent, density }: { percent: number; density: Density
|
||||
);
|
||||
};
|
||||
|
||||
const CardShell = ({ item, density, children }: { item: MissingMediaItem | QueuedMediaItem; density: Density; children: ReactNode }) => (
|
||||
<Paper className={classes.card} component="a" href={item.link} target="_blank" rel="noreferrer" radius="sm" p="xs" h={CARD_HEIGHT[density]}>
|
||||
{item.imageUrl && (
|
||||
<span className={classes.backdrop} style={{ backgroundImage: `url("${item.imageUrl}")` }} aria-hidden />
|
||||
)}
|
||||
<div className={classes.content}>{children}</div>
|
||||
</Paper>
|
||||
);
|
||||
const CardShell = ({
|
||||
item,
|
||||
density,
|
||||
children,
|
||||
}: {
|
||||
item: MissingMediaItem | QueuedMediaItem;
|
||||
density: Density;
|
||||
children: ReactNode;
|
||||
}) => {
|
||||
const href = getSafeApplicationUrl(item.link);
|
||||
return (
|
||||
<Paper
|
||||
className={classes.card}
|
||||
component={href ? "a" : "div"}
|
||||
href={href}
|
||||
target={href ? "_blank" : undefined}
|
||||
rel={href ? SAFE_NEW_TAB_REL : undefined}
|
||||
radius="sm"
|
||||
p="xs"
|
||||
h={CARD_HEIGHT[density]}
|
||||
>
|
||||
<div className={classes.content}>{children}</div>
|
||||
</Paper>
|
||||
);
|
||||
};
|
||||
|
||||
const MediaCard = ({ item, density }: { item: MissingMediaItem | QueuedMediaItem; density: Density }) => {
|
||||
const MediaCard = ({
|
||||
item,
|
||||
density,
|
||||
showQueueDetails,
|
||||
}: {
|
||||
item: MissingMediaItem | QueuedMediaItem;
|
||||
density: Density;
|
||||
showQueueDetails: boolean;
|
||||
}) => {
|
||||
const isQueued = "percentComplete" in item;
|
||||
|
||||
return (
|
||||
@@ -206,7 +386,12 @@ const MediaCard = ({ item, density }: { item: MissingMediaItem | QueuedMediaItem
|
||||
</Text>
|
||||
{density === "comfortable" && (
|
||||
<Text fz="xs" c="dimmed" lineClamp={1} lh={1.1}>
|
||||
{item.type === "episode" ? item.title : item.year}
|
||||
{item.type === "episode" ? item.title : item.type === "book" ? item.seriesTitle : item.year}
|
||||
</Text>
|
||||
)}
|
||||
{isQueued && showQueueDetails && (
|
||||
<Text fz="10px" c="dimmed" lineClamp={1} lh={1.1}>
|
||||
{[item.status, item.timeLeft].filter(Boolean).join(" · ")}
|
||||
</Text>
|
||||
)}
|
||||
</Stack>
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
import { IconMovie } from "@tabler/icons-react";
|
||||
|
||||
import { getIntegrationKindsByCategory } from "@homarr/definitions";
|
||||
import { getWidgetIntegrationConfig } from "@homarr/definitions";
|
||||
|
||||
import { createWidgetDefinition } from "../definition";
|
||||
import { createWidgetDefinition, matchesWidgetRuntimeQuery } from "../definition";
|
||||
import { optionsBuilder } from "../options";
|
||||
|
||||
const pageSizeOptions = ["10", "20", "30", "50"] as const;
|
||||
|
||||
export const { componentLoader, definition } = createWidgetDefinition("mediaMissing", {
|
||||
icon: IconMovie,
|
||||
queryKey: [["widget", "mediaOrganizer"]],
|
||||
supportsAdvancedFocus: true,
|
||||
queryKey: [["widget", "mediaOrganizer", "getData"]],
|
||||
queryMatcher: matchesWidgetRuntimeQuery,
|
||||
createOptions() {
|
||||
return optionsBuilder.from((factory) => ({
|
||||
showMissing: factory.switch({ defaultValue: true }),
|
||||
@@ -23,5 +25,5 @@ export const { componentLoader, definition } = createWidgetDefinition("mediaMiss
|
||||
}),
|
||||
}));
|
||||
},
|
||||
supportedIntegrations: getIntegrationKindsByCategory("mediaOrganizer"),
|
||||
...getWidgetIntegrationConfig("mediaMissing"),
|
||||
}).withDynamicImport(() => import("./component"));
|
||||
@@ -0,0 +1,18 @@
|
||||
import { describe, expect, test } from "vitest";
|
||||
|
||||
import { resolveMediaMissingTab } from "./tabs";
|
||||
|
||||
describe("resolveMediaMissingTab", () => {
|
||||
test("preserves the selected tab while it remains enabled", () => {
|
||||
expect(resolveMediaMissingTab("queued", true, true)).toBe("queued");
|
||||
});
|
||||
|
||||
test("falls back when the selected tab is disabled", () => {
|
||||
expect(resolveMediaMissingTab("missing", false, true)).toBe("queued");
|
||||
expect(resolveMediaMissingTab("queued", true, false)).toBe("missing");
|
||||
});
|
||||
|
||||
test("returns no tab when both panels are disabled", () => {
|
||||
expect(resolveMediaMissingTab("missing", false, false)).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,13 @@
|
||||
export type MediaMissingTab = "missing" | "queued";
|
||||
|
||||
export const resolveMediaMissingTab = (
|
||||
current: MediaMissingTab,
|
||||
showMissing: boolean,
|
||||
showQueued: boolean,
|
||||
): MediaMissingTab | null => {
|
||||
if (current === "missing" && showMissing) return current;
|
||||
if (current === "queued" && showQueued) return current;
|
||||
if (showMissing) return "missing";
|
||||
if (showQueued) return "queued";
|
||||
return null;
|
||||
};
|
||||
Reference in new issue
Block a user