"use client"; import { useCallback, useRef } from "react"; import type { RouterOutputs } from "@homarr/api"; import { clientApi } from "@homarr/api/client"; import { Box, LoadingOverlay, Stack } from "@homarr/ui"; import { BoardCategorySection } from "~/components/board/sections/category-section"; import { BoardEmptySection } from "~/components/board/sections/empty-section"; import { BoardBackgroundVideo } from "~/components/layout/background"; import { useIsBoardReady, useRequiredBoard } from "./_context"; let boardName: string | null = null; export const updateBoardName = (name: string | null) => { boardName = name; }; type UpdateCallback = ( prev: RouterOutputs["board"]["default"], ) => RouterOutputs["board"]["default"]; export const useUpdateBoard = () => { const utils = clientApi.useUtils(); const updateBoard = useCallback( (updaterWithoutUndefined: UpdateCallback) => { if (!boardName) { throw new Error("Board name is not set"); } utils.board.byName.setData({ name: boardName }, (previous) => previous ? updaterWithoutUndefined(previous) : previous, ); }, [utils], ); return { updateBoard, }; }; export const ClientBoard = () => { const board = useRequiredBoard(); const isReady = useIsBoardReady(); const sortedSections = board.sections.sort( (sectionA, sectionB) => sectionA.position - sectionB.position, ); const ref = useRef(null); return ( {sortedSections.map((section) => section.kind === "empty" ? ( ) : ( ), )} ); };