feat(category): save collapse state for signed in users (#2134)
This commit is contained in:
@@ -2,6 +2,8 @@ import { Card, Collapse, Group, Stack, Title, UnstyledButton } from "@mantine/co
|
||||
import { useDisclosure } from "@mantine/hooks";
|
||||
import { IconChevronDown, IconChevronUp } from "@tabler/icons-react";
|
||||
|
||||
import { clientApi } from "@homarr/api/client";
|
||||
|
||||
import type { CategorySection } from "~/app/[locale]/boards/_types";
|
||||
import { useRequiredBoard } from "~/app/[locale]/boards/(content)/_context";
|
||||
import { CategoryMenu } from "./category/category-menu";
|
||||
@@ -13,8 +15,16 @@ interface Props {
|
||||
}
|
||||
|
||||
export const BoardCategorySection = ({ section }: Props) => {
|
||||
const [opened, { toggle }] = useDisclosure(false);
|
||||
const { mutate } = clientApi.section.changeCollapsed.useMutation();
|
||||
const board = useRequiredBoard();
|
||||
const [opened, { toggle }] = useDisclosure(section.collapsed, {
|
||||
onOpen() {
|
||||
mutate({ sectionId: section.id, collapsed: true });
|
||||
},
|
||||
onClose() {
|
||||
mutate({ sectionId: section.id, collapsed: false });
|
||||
},
|
||||
});
|
||||
|
||||
return (
|
||||
<Card style={{ "--opacity": board.opacity / 100 }} withBorder p={0} className={classes.itemCard}>
|
||||
|
||||
@@ -67,6 +67,7 @@ const createSections = (categoryCount: number) => {
|
||||
name: `Category ${index}`,
|
||||
yOffset: index,
|
||||
xOffset: 0,
|
||||
collapsed: false,
|
||||
items: [],
|
||||
})) satisfies Section[];
|
||||
};
|
||||
|
||||
@@ -118,6 +118,7 @@ const createSections = (initialYOffsets: number[]) => {
|
||||
id: yOffset.toString(),
|
||||
kind: index % 2 === 0 ? "empty" : "category",
|
||||
name: "Category",
|
||||
collapsed: false,
|
||||
yOffset,
|
||||
xOffset: 0,
|
||||
items: [createItem({ id: yOffset.toString() })],
|
||||
|
||||
@@ -40,6 +40,7 @@ export const useCategoryActions = () => {
|
||||
kind: "category",
|
||||
yOffset,
|
||||
xOffset: 0,
|
||||
collapsed: false,
|
||||
items: [],
|
||||
},
|
||||
{
|
||||
@@ -89,6 +90,7 @@ export const useCategoryActions = () => {
|
||||
kind: "category",
|
||||
yOffset: lastYOffset + 1,
|
||||
xOffset: 0,
|
||||
collapsed: false,
|
||||
items: [],
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user