Ability to toggle categories

Fixes #150
This commit is contained in:
ajnart
2022-06-06 12:18:51 +02:00
parent 9686761c3d
commit 26cfc485c2

View File

@@ -1,5 +1,5 @@
import React, { useState } from 'react'; import React, { useState } from 'react';
import { Grid, Group, Title } from '@mantine/core'; import { Accordion, Grid, Group } from '@mantine/core';
import { import {
closestCenter, closestCenter,
DndContext, DndContext,
@@ -11,6 +11,7 @@ import {
useSensors, useSensors,
} from '@dnd-kit/core'; } from '@dnd-kit/core';
import { arrayMove, SortableContext, sortableKeyboardCoordinates } from '@dnd-kit/sortable'; import { arrayMove, SortableContext, sortableKeyboardCoordinates } from '@dnd-kit/sortable';
import { useLocalStorage } from '@mantine/hooks';
import { useConfig } from '../../tools/state'; import { useConfig } from '../../tools/state';
import { SortableAppShelfItem, AppShelfItem } from './AppShelfItem'; import { SortableAppShelfItem, AppShelfItem } from './AppShelfItem';
@@ -18,6 +19,10 @@ import { ModuleWrapper } from '../modules/moduleWrapper';
import { DownloadsModule } from '../modules'; import { DownloadsModule } from '../modules';
const AppShelf = (props: any) => { const AppShelf = (props: any) => {
const [toggledCategories, settoggledCategories] = useLocalStorage({
key: 'app-shelf-toggled',
defaultValue: {},
});
const [activeId, setActiveId] = useState(null); const [activeId, setActiveId] = useState(null);
const { config, setConfig } = useConfig(); const { config, setConfig } = useConfig();
const sensors = useSensors( const sensors = useSensors(
@@ -110,26 +115,26 @@ const AppShelf = (props: any) => {
const noCategory = config.services.filter( const noCategory = config.services.filter(
(e) => e.category === undefined || e.category === null (e) => e.category === undefined || e.category === null
); );
// Create an item with 0: true, 1: true, 2: true... For each category
return ( return (
// Return one item for each category // Return one item for each category
<Group grow direction="column"> <Group grow direction="column">
{categoryList.map((category) => ( <Accordion
<> order={2}
<Title order={3} key={category}> iconPosition="right"
{category} multiple
</Title> initialState={toggledCategories}
{item(category)} onChange={(idx) => settoggledCategories(idx)}
</> >
))} {categoryList.map((category) => (
{/* Return the item for all services without category */} <Accordion.Item label={category}>{item(category)}</Accordion.Item>
{noCategory && noCategory.length > 0 ? ( ))}
<> {/* Return the item for all services without category */}
<Title order={3}>Other</Title> {noCategory && noCategory.length > 0 ? (
{item()} <Accordion.Item label="Other">{item()}</Accordion.Item>
</> ) : null}
) : null} <ModuleWrapper mt="xl" module={DownloadsModule} />
<ModuleWrapper mt="xl" module={DownloadsModule} /> </Accordion>
</Group> </Group>
); );
} }