import type { PropsWithChildren } from "react"; import { Fragment, useEffect } from "react"; import { ActionIcon, Group, Indicator, Menu, Popover, Stack, UnstyledButton } from "@mantine/core"; import { useHover } from "@mantine/hooks"; import { IconDotsVertical, IconTrash } from "@tabler/icons-react"; import { useConfirmModal } from "@homarr/modals"; import { useI18n, useScopedI18n } from "@homarr/translation/client"; import type { DynamicSection } from "~/app/[locale]/boards/_types"; import { useEditMode, useRequiredBoard } from "~/app/[locale]/boards/(content)/_context"; import { useDynamicSectionActions } from "./dynamic-actions"; import { useAboveDynamicSectionIds } from "./dynamic-context"; export const BoardDynamicSectionMenu = ({ section }: { section: DynamicSection }) => { const [isEditMode] = useEditMode(); const aboveIds = useAboveDynamicSectionIds(); const board = useRequiredBoard(); const hasItemInTopRightCorner = section.items.some((item) => item.xOffset + item.width === section.width && item.yOffset === 0) || board.sections.some( (innerSection) => innerSection.kind === "dynamic" && innerSection.parentSectionId === section.id && innerSection.xOffset + innerSection.width == section.width && innerSection.yOffset == 0, ); if (!isEditMode) return null; if (aboveIds.length >= 1 && !hasItemInTopRightCorner) { return ( {[...aboveIds, section.id].map((id, index) => ( ))} ); } if (aboveIds.length >= 1 && !hasItemInTopRightCorner) { return ( ); } return null; }; interface DesktopButtonProps { index: number; id: string; } const DesktopButton = ({ index, id }: DesktopButtonProps) => { const { hovered, ref } = useHover(); useEffect(() => { const sectionRef = document.querySelector(`[data-section-id="${id}"]`); if (!sectionRef) return; if (hovered) { const previousBackground = sectionRef.style.backgroundColor; sectionRef.style.backgroundColor = "rgba(255, 0, 0, 0.1)"; return () => { sectionRef.style.backgroundColor = previousBackground; }; } }, [hovered]); return ( Section {index + 1} ); }; const InnerMenu = ({ children, id, trigger }: PropsWithChildren<{ id: string; trigger?: "hover" }>) => { const t = useI18n(); const tDynamic = useScopedI18n("section.dynamic"); const { removeDynamicSection } = useDynamicSectionActions(); const { openConfirmModal } = useConfirmModal(); const openRemoveModal = () => { openConfirmModal({ title: tDynamic("remove.title"), children: tDynamic("remove.message"), onConfirm: () => { removeDynamicSection({ id }); }, }); }; return ( {children} {t("common.dangerZone")} } onClick={openRemoveModal}> {tDynamic("action.remove")} ); };