diff --git a/apps/nextjs/src/components/board/sections/dynamic-section.tsx b/apps/nextjs/src/components/board/sections/dynamic-section.tsx
index 6a858bd10..9e75ea7e8 100644
--- a/apps/nextjs/src/components/board/sections/dynamic-section.tsx
+++ b/apps/nextjs/src/components/board/sections/dynamic-section.tsx
@@ -2,6 +2,7 @@ import { Box, Card } from "@mantine/core";
import type { DynamicSection } from "~/app/[locale]/boards/_types";
import { useRequiredBoard } from "~/app/[locale]/boards/(content)/_context";
+import { DynamicSectionProvider } from "./dynamic/dynamic-context";
import { BoardDynamicSectionMenu } from "./dynamic/dynamic-menu";
import { GridStack } from "./gridstack/gridstack";
import classes from "./item.module.css";
@@ -12,6 +13,7 @@ interface Props {
export const BoardDynamicSection = ({ section }: Props) => {
const board = useRequiredBoard();
+
return (
{
}}
p={0}
>
-
+
+
+
diff --git a/apps/nextjs/src/components/board/sections/dynamic/dynamic-context.tsx b/apps/nextjs/src/components/board/sections/dynamic/dynamic-context.tsx
new file mode 100644
index 000000000..8e7f92709
--- /dev/null
+++ b/apps/nextjs/src/components/board/sections/dynamic/dynamic-context.tsx
@@ -0,0 +1,54 @@
+"use client";
+
+import type { PropsWithChildren } from "react";
+import { createContext, useContext } from "react";
+
+import type { DynamicSection } from "~/app/[locale]/boards/_types";
+import { useRequiredBoard } from "~/app/[locale]/boards/(content)/_context";
+
+interface DynamicSectionContextProps {
+ sectionIds: string[];
+}
+
+const DynamicSectionContext = createContext({
+ sectionIds: [],
+});
+
+interface DynamicSectionProviderProps {
+ section: DynamicSection;
+}
+
+export const DynamicSectionProvider = ({ section, children }: PropsWithChildren) => {
+ const aboveIds = useAboveDynamicSectionIds();
+ const resetPrevious = usePlacedTopRightAndInDynamicSection({ sectionOrItem: section, previousId: aboveIds.at(-1) });
+
+ return (
+
+ {children}
+
+ );
+};
+
+export const useAboveDynamicSectionIds = () => {
+ return useContext(DynamicSectionContext).sectionIds;
+};
+
+interface UsePlacedTopRightAndInDynamicSectionProps {
+ sectionOrItem: { width: number; xOffset: number; yOffset: number };
+ previousId: string | undefined;
+}
+
+export const usePlacedTopRightAndInDynamicSection = ({
+ sectionOrItem,
+ previousId,
+}: UsePlacedTopRightAndInDynamicSectionProps) => {
+ const board = useRequiredBoard();
+ const aboveSection = board.sections.find(
+ (section): section is DynamicSection => section.id === previousId && section.kind === "dynamic",
+ );
+
+ // When not on top, no above section or not reaching the end of the above section, we want to reset the previous sections
+ return (
+ sectionOrItem.yOffset >= 1 || !aboveSection || sectionOrItem.xOffset + sectionOrItem.width !== aboveSection.width
+ );
+};
diff --git a/apps/nextjs/src/components/board/sections/dynamic/dynamic-menu.tsx b/apps/nextjs/src/components/board/sections/dynamic/dynamic-menu.tsx
index 1a07eb81e..5adc47959 100644
--- a/apps/nextjs/src/components/board/sections/dynamic/dynamic-menu.tsx
+++ b/apps/nextjs/src/components/board/sections/dynamic/dynamic-menu.tsx
@@ -1,39 +1,120 @@
-import { ActionIcon, Menu } from "@mantine/core";
+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 } from "~/app/[locale]/boards/(content)/_context";
+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 [isEditMode] = useEditMode();
-
- if (!isEditMode) return null;
-
const openRemoveModal = () => {
openConfirmModal({
title: tDynamic("remove.title"),
children: tDynamic("remove.message"),
onConfirm: () => {
- removeDynamicSection({ id: section.id });
+ removeDynamicSection({ id });
},
});
};
return (
-