feat: added bordercolor option for dynamic section (#2334)

This commit is contained in:
Jack Weller
2025-03-02 20:39:17 +10:00
committed by GitHub
parent 7dfc3646b7
commit 7dfb108a56
20 changed files with 4134 additions and 12 deletions

View File

@@ -1,11 +1,18 @@
import { useCallback } from "react";
import type { z } from "zod";
import { useUpdateBoard } from "@homarr/boards/updater";
import type { dynamicSectionOptionsSchema } from "@homarr/validation";
import { addDynamicSectionCallback } from "./actions/add-dynamic-section";
import type { RemoveDynamicSectionInput } from "./actions/remove-dynamic-section";
import { removeDynamicSectionCallback } from "./actions/remove-dynamic-section";
interface UpdateDynamicOptions {
itemId: string;
newOptions: z.infer<typeof dynamicSectionOptionsSchema>;
}
export const useDynamicSectionActions = () => {
const { updateBoard } = useUpdateBoard();
@@ -13,6 +20,16 @@ export const useDynamicSectionActions = () => {
updateBoard(addDynamicSectionCallback());
}, [updateBoard]);
const updateDynamicSection = useCallback(
({ itemId, newOptions }: UpdateDynamicOptions) => {
updateBoard((previous) => ({
...previous,
sections: previous.sections.map((item) => (item.id !== itemId ? item : { ...item, options: newOptions })),
}));
},
[updateBoard],
);
const removeDynamicSection = useCallback(
(input: RemoveDynamicSectionInput) => {
updateBoard(removeDynamicSectionCallback(input));
@@ -22,6 +39,7 @@ export const useDynamicSectionActions = () => {
return {
addDynamicSection,
updateDynamicSection,
removeDynamicSection,
};
};