mirror of
https://github.com/ajnart/homarr.git
synced 2025-11-11 16:05:47 +01:00
🐛 Fix configLoader
This commit is contained in:
@@ -5,61 +5,20 @@ import {
|
|||||||
IconX as X,
|
IconX as X,
|
||||||
IconCheck as Check,
|
IconCheck as Check,
|
||||||
TablerIcon,
|
TablerIcon,
|
||||||
|
IconX,
|
||||||
|
IconPhoto,
|
||||||
|
IconUpload,
|
||||||
} from '@tabler/icons';
|
} from '@tabler/icons';
|
||||||
import { showNotification } from '@mantine/notifications';
|
import { showNotification } from '@mantine/notifications';
|
||||||
import { useRef } from 'react';
|
|
||||||
import { useRouter } from 'next/router';
|
|
||||||
import { setCookie } from 'cookies-next';
|
import { setCookie } from 'cookies-next';
|
||||||
import { Dropzone } from '@mantine/dropzone';
|
import { Dropzone } from '@mantine/dropzone';
|
||||||
import { useConfig } from '../../tools/state';
|
import { useConfig } from '../../tools/state';
|
||||||
import { Config } from '../../tools/types';
|
import { Config } from '../../tools/types';
|
||||||
import { migrateToIdConfig } from '../../tools/migrate';
|
import { migrateToIdConfig } from '../../tools/migrate';
|
||||||
|
|
||||||
function getIconColor(status: DropzoneStatus, theme: MantineTheme) {
|
|
||||||
return status.accepted
|
|
||||||
? theme.colors[theme.primaryColor][theme.colorScheme === 'dark' ? 4 : 6]
|
|
||||||
: status.rejected
|
|
||||||
? theme.colors.red[theme.colorScheme === 'dark' ? 4 : 6]
|
|
||||||
: theme.colorScheme === 'dark'
|
|
||||||
? theme.colors.dark[0]
|
|
||||||
: theme.colors.gray[7];
|
|
||||||
}
|
|
||||||
|
|
||||||
function ImageUploadIcon({
|
|
||||||
status,
|
|
||||||
...props
|
|
||||||
}: React.ComponentProps<TablerIcon> & { status: DropzoneStatus }) {
|
|
||||||
if (status.accepted) {
|
|
||||||
return <Upload {...props} />;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (status.rejected) {
|
|
||||||
return <X {...props} />;
|
|
||||||
}
|
|
||||||
|
|
||||||
return <Photo {...props} />;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const dropzoneChildren = (status: DropzoneStatus, theme: MantineTheme) => (
|
|
||||||
<Group position="center" spacing="xl" style={{ minHeight: 220, pointerEvents: 'none' }}>
|
|
||||||
<ImageUploadIcon status={status} style={{ color: getIconColor(status, theme) }} size={80} />
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<Text size="xl" inline>
|
|
||||||
Drag images here or click to select files
|
|
||||||
</Text>
|
|
||||||
<Text size="sm" color="dimmed" inline mt={7}>
|
|
||||||
Attach as many files as you like, each file should not exceed 5mb
|
|
||||||
</Text>
|
|
||||||
</div>
|
|
||||||
</Group>
|
|
||||||
);
|
|
||||||
|
|
||||||
export default function LoadConfigComponent(props: any) {
|
export default function LoadConfigComponent(props: any) {
|
||||||
const { setConfig } = useConfig();
|
const { setConfig } = useConfig();
|
||||||
const theme = useMantineTheme();
|
const theme = useMantineTheme();
|
||||||
const router = useRouter();
|
|
||||||
const openRef = useRef<() => void>();
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dropzone.FullScreen
|
<Dropzone.FullScreen
|
||||||
@@ -100,7 +59,31 @@ export default function LoadConfigComponent(props: any) {
|
|||||||
}}
|
}}
|
||||||
accept={['application/json']}
|
accept={['application/json']}
|
||||||
>
|
>
|
||||||
{(status: any) => dropzoneChildren(status, theme)}
|
<Group position="center" spacing="xl" style={{ minHeight: 220, pointerEvents: 'none' }}>
|
||||||
|
<Dropzone.Accept>
|
||||||
|
<Text size="xl" inline>
|
||||||
|
<IconUpload
|
||||||
|
size={50}
|
||||||
|
stroke={1.5}
|
||||||
|
color={theme.colors[theme.primaryColor][theme.colorScheme === 'dark' ? 4 : 6]}
|
||||||
|
/>
|
||||||
|
Drag files here to upload a config. Support for JSON only.
|
||||||
|
</Text>
|
||||||
|
</Dropzone.Accept>
|
||||||
|
<Dropzone.Reject>
|
||||||
|
<Text size="xl" inline>
|
||||||
|
<IconX
|
||||||
|
size={50}
|
||||||
|
stroke={1.5}
|
||||||
|
color={theme.colors.red[theme.colorScheme === 'dark' ? 4 : 6]}
|
||||||
|
/>
|
||||||
|
This file format is not supported. Please only upload JSON.
|
||||||
|
</Text>
|
||||||
|
</Dropzone.Reject>
|
||||||
|
<Dropzone.Idle>
|
||||||
|
<IconPhoto size={50} stroke={1.5} />
|
||||||
|
</Dropzone.Idle>
|
||||||
|
</Group>
|
||||||
</Dropzone.FullScreen>
|
</Dropzone.FullScreen>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user