From 195e1ba946942dd5b86ce204d94eb0d83c8958c8 Mon Sep 17 00:00:00 2001 From: ajnart Date: Tue, 22 Nov 2022 13:58:50 +0900 Subject: [PATCH] AppShelf adjustments --- src/components/AppShelf/AppShelf.tsx | 148 ++++++----------------- src/components/AppShelf/AppShelfItem.tsx | 8 +- 2 files changed, 45 insertions(+), 111 deletions(-) diff --git a/src/components/AppShelf/AppShelf.tsx b/src/components/AppShelf/AppShelf.tsx index 85a204f0c..61587b8bf 100644 --- a/src/components/AppShelf/AppShelf.tsx +++ b/src/components/AppShelf/AppShelf.tsx @@ -1,5 +1,5 @@ import React, { useState } from 'react'; -import { Accordion, Grid, Paper, Stack, Text, useMantineColorScheme } from '@mantine/core'; +import { Accordion, Grid, Stack, Title, useMantineColorScheme } from '@mantine/core'; import { closestCenter, DndContext, @@ -9,16 +9,16 @@ import { useSensor, useSensors, } from '@dnd-kit/core'; + import { arrayMove, SortableContext } from '@dnd-kit/sortable'; import { useLocalStorage } from '@mantine/hooks'; import { useTranslation } from 'next-i18next'; +import * as Modules from '../../modules'; import { useConfig } from '../../tools/state'; -import { SortableAppShelfItem, AppShelfItem } from './AppShelfItem'; -import { ModuleMenu, ModuleWrapper } from '../../modules/moduleWrapper'; +import { AppShelfItem, SortableItem } from './AppShelfItem'; +import { ModuleWrapper } from '../../modules/moduleWrapper'; import { UsenetModule, TorrentsModule } from '../../modules'; -import TorrentsComponent from '../../modules/torrents/TorrentsModule'; -import { UsenetComponent } from '../../modules/usenet/UsenetModule'; const AppShelf = (props: any) => { const { config, setConfig } = useConfig(); @@ -79,13 +79,14 @@ const AppShelf = (props: any) => { const getItems = (filter?: string) => { // If filter is not set, return all the services without a category or a null category let filtered = config.services; + const modules = Object.values(Modules).map((module) => module); + if (!filter) { filtered = config.services.filter((e) => !e.category || e.category === null); } if (filter) { filtered = config.services.filter((e) => e.category === filter); } - return ( { onDragEnd={handleDragEnd} > - + {filtered.map((service) => ( - - + + + + ))} @@ -123,100 +119,36 @@ const AppShelf = (props: any) => { ); }; - if (categoryList.length > 0) { - const noCategory = config.services.filter( - (e) => e.category === undefined || e.category === null - ); - - const torrentEnabled = config.modules?.[TorrentsModule.id]?.enabled ?? false; - const usenetEnabled = config.modules?.[UsenetModule.id]?.enabled ?? false; - - const downloadEnabled = usenetEnabled || torrentEnabled; - // Create an item with 0: true, 1: true, 2: true... For each category - return ( - // TODO: Style accordion so that the bar is transparent to the user settings - - { - setToggledCategories([...state]); - }} - > - {categoryList.map((category, idx) => ( - - {category} - {getItems(category)} - - ))} - {/* Return the item for all services without category */} - {noCategory && noCategory.length > 0 ? ( - - {t('accordions.others.text')} - {getItems()} - - ) : null} - {downloadEnabled ? ( - - {t('accordions.downloads.text')} - - - {torrentEnabled && ( - <> - {t('accordions.downloads.torrents')} - - - - )} - {usenetEnabled && ( - <> - {t('accordions.downloads.usenet')} - - - - )} - - - - ) : null} - - - ); - } return ( + { + setToggledCategories([...state]); + }} + > + {categoryList.map((category, idx) => ( + + + {category} + + {getItems(category)} + + ))} + {getItems()} diff --git a/src/components/AppShelf/AppShelfItem.tsx b/src/components/AppShelf/AppShelfItem.tsx index 35c730d68..35ca6d604 100644 --- a/src/components/AppShelf/AppShelfItem.tsx +++ b/src/components/AppShelf/AppShelfItem.tsx @@ -31,7 +31,7 @@ const useStyles = createStyles((theme) => ({ }, })); -export function SortableAppShelfItem(props: any) { +export function SortableItem(props: any) { const { attributes, listeners, setNodeRef, transform, transition } = useSortable({ id: props.id, }); @@ -43,7 +43,7 @@ export function SortableAppShelfItem(props: any) { return (
- + {props.children}
); } @@ -75,6 +75,8 @@ export function AppShelfItem(props: any) { shadow="md" className={classes.item} style={{ + // Use the grab cursor when hovering over the card + cursor: hovering ? 'grab' : 'auto', background: `rgba(${colorScheme === 'dark' ? '37, 38, 43,' : '255, 255, 255,'} \ ${(config.settings.appOpacity || 100) / 100}`, borderColor: `rgba(${colorScheme === 'dark' ? '37, 38, 43,' : '233, 236, 239,'} \ @@ -140,4 +142,4 @@ export function AppShelfItem(props: any) { ); -} +} \ No newline at end of file