mirror of
https://github.com/ajnart/homarr.git
synced 2025-11-11 16:05:47 +01:00
Merge pull request #649 from ajnart/feature-category-collapse
Add category collapse
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
import { Group, Title } from '@mantine/core';
|
import { Accordion, Title } from '@mantine/core';
|
||||||
|
import { useLocalStorage } from '@mantine/hooks';
|
||||||
|
import { useConfigContext } from '../../../../config/provider';
|
||||||
import { CategoryType } from '../../../../types/category';
|
import { CategoryType } from '../../../../types/category';
|
||||||
import { HomarrCardWrapper } from '../../Tiles/HomarrCardWrapper';
|
import { useCardStyles } from '../../../layout/useCardStyles';
|
||||||
import { useEditModeStore } from '../../Views/useEditModeStore';
|
import { useEditModeStore } from '../../Views/useEditModeStore';
|
||||||
import { useGridstack } from '../gridstack/use-gridstack';
|
import { useGridstack } from '../gridstack/use-gridstack';
|
||||||
import { WrapperContent } from '../WrapperContent';
|
import { WrapperContent } from '../WrapperContent';
|
||||||
@@ -13,13 +15,38 @@ interface DashboardCategoryProps {
|
|||||||
export const DashboardCategory = ({ category }: DashboardCategoryProps) => {
|
export const DashboardCategory = ({ category }: DashboardCategoryProps) => {
|
||||||
const { refs, apps, widgets } = useGridstack('category', category.id);
|
const { refs, apps, widgets } = useGridstack('category', category.id);
|
||||||
const isEditMode = useEditModeStore((x) => x.enabled);
|
const isEditMode = useEditModeStore((x) => x.enabled);
|
||||||
|
const { config } = useConfigContext();
|
||||||
|
const { classes: cardClasses } = useCardStyles(true);
|
||||||
|
|
||||||
|
const categoryList = config?.categories.map((x) => x.name) ?? [];
|
||||||
|
const [toggledCategories, setToggledCategories] = useLocalStorage({
|
||||||
|
key: `${config?.configProperties.name}-app-shelf-toggled`,
|
||||||
|
// This is a bit of a hack to toggle the categories on the first load, return a string[] of the categories
|
||||||
|
defaultValue: categoryList,
|
||||||
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<HomarrCardWrapper pt={10} mx={10} isCategory>
|
<Accordion
|
||||||
<Group position="apart" align="center">
|
classNames={{
|
||||||
|
item: cardClasses.card,
|
||||||
|
}}
|
||||||
|
mx={0}
|
||||||
|
chevronPosition="left"
|
||||||
|
multiple
|
||||||
|
value={isEditMode ? categoryList : toggledCategories}
|
||||||
|
variant="separated"
|
||||||
|
radius="lg"
|
||||||
|
onChange={(state) => {
|
||||||
|
// Cancel if edit mode is on
|
||||||
|
if (isEditMode) return;
|
||||||
|
setToggledCategories([...state]);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Accordion.Item value={category.name}>
|
||||||
|
<Accordion.Control icon={isEditMode && <CategoryEditMenu category={category} />}>
|
||||||
<Title order={3}>{category.name}</Title>
|
<Title order={3}>{category.name}</Title>
|
||||||
{isEditMode ? <CategoryEditMenu category={category} /> : null}
|
</Accordion.Control>
|
||||||
</Group>
|
<Accordion.Panel>
|
||||||
<div
|
<div
|
||||||
className="grid-stack grid-stack-category"
|
className="grid-stack grid-stack-category"
|
||||||
data-category={category.id}
|
data-category={category.id}
|
||||||
@@ -27,6 +54,8 @@ export const DashboardCategory = ({ category }: DashboardCategoryProps) => {
|
|||||||
>
|
>
|
||||||
<WrapperContent apps={apps} refs={refs} widgets={widgets} />
|
<WrapperContent apps={apps} refs={refs} widgets={widgets} />
|
||||||
</div>
|
</div>
|
||||||
</HomarrCardWrapper>
|
</Accordion.Panel>
|
||||||
|
</Accordion.Item>
|
||||||
|
</Accordion>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ export const CategoryEditMenu = ({ category }: CategoryEditMenuProps) => {
|
|||||||
useCategoryActions(configName, category);
|
useCategoryActions(configName, category);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Menu withinPortal position="left-start" withArrow>
|
<Menu withinPortal withArrow>
|
||||||
<Menu.Target>
|
<Menu.Target>
|
||||||
<ActionIcon>
|
<ActionIcon>
|
||||||
<IconDots />
|
<IconDots />
|
||||||
|
|||||||
Reference in New Issue
Block a user