import { Box, Center, Image } from "@mantine/core"; import { IconLayoutGrid } from "@tabler/icons-react"; import type { BoardPreviewData } from "@homarr/boards/layout-preview"; import { projectBoardLayout } from "@homarr/boards/layout-preview"; import { boardLanes, getBoardLaneColumnCount, getRootSectionLane } from "@homarr/definitions"; import { widgetCatalogIcons } from "@homarr/widgets/catalog"; import classes from "./board-layout-thumbnail.module.css"; interface BoardLayoutThumbnailProps { preview: BoardPreviewData | null; label: string; } const maxThumbnailRows = 12; export const BoardLayoutThumbnail = ({ preview, label }: BoardLayoutThumbnailProps) => { const layout = preview?.layouts.find((candidate) => candidate.role === "base") ?? preview?.layouts.at(0); if (!preview || !layout) { return (
); } const elements = projectBoardLayout(preview, layout, layout); const roots = preview.sections .filter((section) => section.kind === "empty") .toSorted((first, second) => (first.xOffset ?? 0) - (second.xOffset ?? 0) || first.id.localeCompare(second.id)); const lanes = boardLanes.flatMap((lane) => { const root = roots.find((section) => getRootSectionLane(section.xOffset) === lane); const columnCount = getBoardLaneColumnCount(layout, lane); return root && columnCount > 0 ? [{ lane, root, columnCount }] : []; }); if (lanes.length === 0) { return (
); } const renderItemIcon = (itemId: string) => { const item = preview.items.find((candidate) => candidate.id === itemId); const WidgetIcon = item?.kind ? widgetCatalogIcons[item.kind] : undefined; return item?.iconUrl ? ( ) : WidgetIcon ? ( ) : null; }; return (
`${columnCount}fr`).join(" ") }} > {lanes.map(({ lane, root, columnCount }) => { const laneElements = elements.filter( (element) => element.sectionId === root.id && element.xOffset >= 0 && element.xOffset < columnCount && element.yOffset >= 0 && element.yOffset < maxThumbnailRows && element.width > 0 && element.height > 0, ); const rowCount = Math.min( maxThumbnailRows, Math.max(4, ...laneElements.map((element) => element.yOffset + element.height)), ); return (
{laneElements.map((element) => { const nestedItems = element.type === "section" ? elements.filter((candidate) => candidate.type === "item" && candidate.sectionId === element.id) : []; return ( {element.type === "section" ? ( {nestedItems.map((nestedItem) => ( {renderItemIcon(nestedItem.id)} ))} ) : ( renderItemIcon(element.id) )} ); })}
); })}
); };