mirror of
https://github.com/ajnart/homarr.git
synced 2025-11-09 23:15:46 +01:00
✨ Add element selector tile for categories
This commit is contained in:
@@ -1,27 +1,62 @@
|
|||||||
import { Group, Space, Stack, Text, UnstyledButton } from '@mantine/core';
|
import { Group, Space, Stack, Text, UnstyledButton } from '@mantine/core';
|
||||||
import { IconBox, IconStack } from '@tabler/icons';
|
import { closeModal } from '@mantine/modals';
|
||||||
|
import { IconBox, IconBoxAlignTop, IconStack } from '@tabler/icons';
|
||||||
import { useTranslation } from 'next-i18next';
|
import { useTranslation } from 'next-i18next';
|
||||||
import { ReactNode } from 'react';
|
import { ReactNode } from 'react';
|
||||||
import { v4 as uuidv4 } from 'uuid';
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
import { useConfigContext } from '../../../../../../config/provider';
|
import { useConfigContext } from '../../../../../../config/provider';
|
||||||
|
import { useConfigStore } from '../../../../../../config/store';
|
||||||
import { openContextModalGeneric } from '../../../../../../tools/mantineModalManagerExtensions';
|
import { openContextModalGeneric } from '../../../../../../tools/mantineModalManagerExtensions';
|
||||||
import { AppType } from '../../../../../../types/app';
|
import { AppType } from '../../../../../../types/app';
|
||||||
import { appTileDefinition } from '../../../../Tiles/Apps/AppTile';
|
import { appTileDefinition } from '../../../../Tiles/Apps/AppTile';
|
||||||
import { useStyles } from '../Shared/styles';
|
import { useStyles } from '../Shared/styles';
|
||||||
|
|
||||||
interface AvailableElementTypesProps {
|
interface AvailableElementTypesProps {
|
||||||
|
modalId: string;
|
||||||
onOpenIntegrations: () => void;
|
onOpenIntegrations: () => void;
|
||||||
onOpenStaticElements: () => void;
|
onOpenStaticElements: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const AvailableElementTypes = ({
|
export const AvailableElementTypes = ({
|
||||||
|
modalId,
|
||||||
onOpenIntegrations: onOpenWidgets,
|
onOpenIntegrations: onOpenWidgets,
|
||||||
onOpenStaticElements,
|
onOpenStaticElements,
|
||||||
}: AvailableElementTypesProps) => {
|
}: AvailableElementTypesProps) => {
|
||||||
const { t } = useTranslation('layout/element-selector/selector');
|
const { t } = useTranslation('layout/element-selector/selector');
|
||||||
const { config } = useConfigContext();
|
const { config, name: configName } = useConfigContext();
|
||||||
|
const { updateConfig } = useConfigStore();
|
||||||
const getLowestWrapper = () => config?.wrappers.sort((a, b) => a.position - b.position)[0];
|
const getLowestWrapper = () => config?.wrappers.sort((a, b) => a.position - b.position)[0];
|
||||||
|
|
||||||
|
const onClickCreateCategory = async () => {
|
||||||
|
if (!configName) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await updateConfig(configName, (previousConfig) => ({
|
||||||
|
...previousConfig,
|
||||||
|
wrappers:
|
||||||
|
previousConfig.wrappers.length <= previousConfig.categories.length
|
||||||
|
? [
|
||||||
|
...previousConfig.wrappers,
|
||||||
|
{
|
||||||
|
id: uuidv4(),
|
||||||
|
position: previousConfig.categories.length,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
: previousConfig.wrappers,
|
||||||
|
categories: [
|
||||||
|
...previousConfig.categories,
|
||||||
|
{
|
||||||
|
id: uuidv4(),
|
||||||
|
name: `Category ${previousConfig.categories.length + 1}`,
|
||||||
|
position: previousConfig.categories.length,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}));
|
||||||
|
|
||||||
|
closeModal(modalId);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Text color="dimmed">{t('modal.text')}</Text>
|
<Text color="dimmed">{t('modal.text')}</Text>
|
||||||
@@ -82,6 +117,11 @@ export const AvailableElementTypes = ({
|
|||||||
icon={<IconStack size={40} strokeWidth={1.3} />}
|
icon={<IconStack size={40} strokeWidth={1.3} />}
|
||||||
onClick={onOpenWidgets}
|
onClick={onOpenWidgets}
|
||||||
/>
|
/>
|
||||||
|
<ElementItem
|
||||||
|
name="Category"
|
||||||
|
icon={<IconBoxAlignTop size={40} strokeWidth={1.3} />}
|
||||||
|
onClick={onClickCreateCategory}
|
||||||
|
/>
|
||||||
{/*<ElementItem
|
{/*<ElementItem
|
||||||
name="Static Element"
|
name="Static Element"
|
||||||
icon={<IconTextResize size={40} strokeWidth={1.3} />}
|
icon={<IconTextResize size={40} strokeWidth={1.3} />}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ export const SelectElementModal = ({ context, id }: ContextModalProps) => {
|
|||||||
case undefined:
|
case undefined:
|
||||||
return (
|
return (
|
||||||
<AvailableElementTypes
|
<AvailableElementTypes
|
||||||
|
modalId={id}
|
||||||
onOpenIntegrations={() => setActiveTab('integrations')}
|
onOpenIntegrations={() => setActiveTab('integrations')}
|
||||||
onOpenStaticElements={() => setActiveTab('static_elements')}
|
onOpenStaticElements={() => setActiveTab('static_elements')}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in New Issue
Block a user