2022-05-06 23:10:00 +02:00
|
|
|
|
import {
|
|
|
|
|
|
ActionIcon,
|
|
|
|
|
|
Group,
|
|
|
|
|
|
Title,
|
|
|
|
|
|
Text,
|
|
|
|
|
|
Tooltip,
|
|
|
|
|
|
SegmentedControl,
|
2022-05-15 13:09:25 +02:00
|
|
|
|
TextInput,
|
2022-05-24 22:55:10 +02:00
|
|
|
|
Drawer,
|
2022-05-26 20:07:54 +02:00
|
|
|
|
Anchor,
|
2022-05-06 23:10:00 +02:00
|
|
|
|
} from '@mantine/core';
|
2022-05-24 23:02:27 +02:00
|
|
|
|
import { useColorScheme, useHotkeys } from '@mantine/hooks';
|
2022-05-18 22:08:09 +02:00
|
|
|
|
import { useState } from 'react';
|
2022-05-29 18:42:58 +02:00
|
|
|
|
import { IconBrandGithub as BrandGithub, IconSettings } from '@tabler/icons';
|
2022-05-26 20:07:54 +02:00
|
|
|
|
import { CURRENT_VERSION } from '../../../data/constants';
|
2022-05-02 15:09:39 +02:00
|
|
|
|
import { useConfig } from '../../tools/state';
|
2022-05-09 01:35:11 +02:00
|
|
|
|
import { ColorSchemeSwitch } from '../ColorSchemeToggle/ColorSchemeSwitch';
|
2022-05-12 22:16:22 +02:00
|
|
|
|
import ConfigChanger from '../Config/ConfigChanger';
|
2022-04-27 03:12:17 +02:00
|
|
|
|
import SaveConfigComponent from '../Config/SaveConfig';
|
2022-05-10 20:33:11 +02:00
|
|
|
|
import ModuleEnabler from './ModuleEnabler';
|
2022-04-27 03:12:17 +02:00
|
|
|
|
|
|
|
|
|
|
function SettingsMenu(props: any) {
|
2022-05-02 15:09:39 +02:00
|
|
|
|
const { config, setConfig } = useConfig();
|
2022-05-09 01:35:11 +02:00
|
|
|
|
const colorScheme = useColorScheme();
|
2022-05-12 02:41:13 +02:00
|
|
|
|
const { current, latest } = props;
|
2022-05-15 13:09:25 +02:00
|
|
|
|
|
2022-05-06 23:10:00 +02:00
|
|
|
|
const matches = [
|
|
|
|
|
|
{ label: 'Google', value: 'https://google.com/search?q=' },
|
|
|
|
|
|
{ label: 'DuckDuckGo', value: 'https://duckduckgo.com/?q=' },
|
|
|
|
|
|
{ label: 'Bing', value: 'https://bing.com/search?q=' },
|
2022-05-15 13:09:25 +02:00
|
|
|
|
{ label: 'Custom', value: 'Custom' },
|
2022-05-06 23:10:00 +02:00
|
|
|
|
];
|
2022-05-15 13:09:25 +02:00
|
|
|
|
|
|
|
|
|
|
const [customSearchUrl, setCustomSearchUrl] = useState(config.settings.searchUrl);
|
|
|
|
|
|
const [searchUrl, setSearchUrl] = useState(
|
|
|
|
|
|
matches.find((match) => match.value === config.settings.searchUrl)?.value ?? 'Custom'
|
|
|
|
|
|
);
|
|
|
|
|
|
|
2022-04-27 03:12:17 +02:00
|
|
|
|
return (
|
2022-04-27 20:10:51 +02:00
|
|
|
|
<Group direction="column" grow>
|
2022-05-15 13:09:25 +02:00
|
|
|
|
<Group grow direction="column" spacing={0}>
|
|
|
|
|
|
<Text>Search engine</Text>
|
2022-05-06 23:10:00 +02:00
|
|
|
|
<SegmentedControl
|
2022-05-15 13:09:25 +02:00
|
|
|
|
fullWidth
|
2022-05-06 23:10:00 +02:00
|
|
|
|
title="Search engine"
|
2022-05-12 22:35:21 +02:00
|
|
|
|
value={
|
2022-05-06 23:10:00 +02:00
|
|
|
|
// Match config.settings.searchUrl with a key in the matches array
|
2022-05-15 13:09:25 +02:00
|
|
|
|
searchUrl
|
2022-05-06 23:10:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
onChange={
|
|
|
|
|
|
// Set config.settings.searchUrl to the value of the selected item
|
2022-05-15 13:09:25 +02:00
|
|
|
|
(e) => {
|
|
|
|
|
|
setSearchUrl(e);
|
2022-05-06 23:10:00 +02:00
|
|
|
|
setConfig({
|
|
|
|
|
|
...config,
|
|
|
|
|
|
settings: {
|
|
|
|
|
|
...config.settings,
|
|
|
|
|
|
searchUrl: e,
|
|
|
|
|
|
},
|
2022-05-15 13:09:25 +02:00
|
|
|
|
});
|
|
|
|
|
|
}
|
2022-05-06 23:10:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
data={matches}
|
|
|
|
|
|
/>
|
2022-05-15 13:09:25 +02:00
|
|
|
|
{searchUrl === 'Custom' && (
|
|
|
|
|
|
<TextInput
|
2022-05-16 12:38:46 +02:00
|
|
|
|
label="Query URL"
|
|
|
|
|
|
placeholder="Custom query url"
|
2022-05-15 13:09:25 +02:00
|
|
|
|
value={customSearchUrl}
|
|
|
|
|
|
onChange={(event) => {
|
|
|
|
|
|
setCustomSearchUrl(event.currentTarget.value);
|
|
|
|
|
|
setConfig({
|
|
|
|
|
|
...config,
|
|
|
|
|
|
settings: {
|
|
|
|
|
|
...config.settings,
|
|
|
|
|
|
searchUrl: event.currentTarget.value,
|
|
|
|
|
|
},
|
|
|
|
|
|
});
|
|
|
|
|
|
}}
|
|
|
|
|
|
/>
|
|
|
|
|
|
)}
|
2022-05-06 23:10:00 +02:00
|
|
|
|
</Group>
|
2022-05-10 20:33:11 +02:00
|
|
|
|
<ModuleEnabler />
|
2022-05-09 01:35:11 +02:00
|
|
|
|
<ColorSchemeSwitch />
|
2022-05-12 22:16:22 +02:00
|
|
|
|
<ConfigChanger />
|
2022-04-27 03:12:17 +02:00
|
|
|
|
<SaveConfigComponent />
|
|
|
|
|
|
<Text
|
|
|
|
|
|
style={{
|
|
|
|
|
|
alignSelf: 'center',
|
|
|
|
|
|
fontSize: '0.75rem',
|
|
|
|
|
|
textAlign: 'center',
|
|
|
|
|
|
color: '#a0aec0',
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
2022-05-04 07:49:29 +02:00
|
|
|
|
tip: You can upload your config file by dragging and dropping it onto the page
|
2022-04-27 03:12:17 +02:00
|
|
|
|
</Text>
|
2022-05-26 20:07:54 +02:00
|
|
|
|
<Group position="center" direction="row" mr="xs">
|
|
|
|
|
|
<Group spacing={0}>
|
|
|
|
|
|
<ActionIcon<'a'> component="a" href="https://github.com/ajnart/homarr" size="lg">
|
|
|
|
|
|
<BrandGithub size={18} />
|
|
|
|
|
|
</ActionIcon>
|
|
|
|
|
|
<Text
|
|
|
|
|
|
style={{
|
|
|
|
|
|
position: 'relative',
|
|
|
|
|
|
fontSize: '0.90rem',
|
|
|
|
|
|
color: 'gray',
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
{CURRENT_VERSION}
|
|
|
|
|
|
</Text>
|
|
|
|
|
|
</Group>
|
|
|
|
|
|
<Text
|
|
|
|
|
|
style={{
|
|
|
|
|
|
fontSize: '0.90rem',
|
|
|
|
|
|
textAlign: 'center',
|
|
|
|
|
|
color: '#a0aec0',
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
Made with ❤️ by @
|
|
|
|
|
|
<Anchor
|
|
|
|
|
|
href="https://github.com/ajnart"
|
|
|
|
|
|
style={{ color: 'inherit', fontStyle: 'inherit', fontSize: 'inherit' }}
|
|
|
|
|
|
>
|
|
|
|
|
|
ajnart
|
|
|
|
|
|
</Anchor>
|
|
|
|
|
|
</Text>
|
|
|
|
|
|
</Group>
|
2022-04-27 03:12:17 +02:00
|
|
|
|
</Group>
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function SettingsMenuButton(props: any) {
|
2022-05-24 23:02:27 +02:00
|
|
|
|
useHotkeys([['ctrl+L', () => setOpened(!opened)]]);
|
|
|
|
|
|
|
2022-04-27 03:12:17 +02:00
|
|
|
|
const [opened, setOpened] = useState(false);
|
|
|
|
|
|
return (
|
|
|
|
|
|
<>
|
2022-05-24 22:55:10 +02:00
|
|
|
|
<Drawer
|
|
|
|
|
|
size="auto"
|
|
|
|
|
|
padding="xl"
|
|
|
|
|
|
position="right"
|
2022-04-27 03:12:17 +02:00
|
|
|
|
title={<Title order={3}>Settings</Title>}
|
|
|
|
|
|
opened={props.opened || opened}
|
|
|
|
|
|
onClose={() => setOpened(false)}
|
|
|
|
|
|
>
|
2022-05-18 22:08:09 +02:00
|
|
|
|
<SettingsMenu />
|
2022-05-24 22:55:10 +02:00
|
|
|
|
</Drawer>
|
2022-04-27 03:12:17 +02:00
|
|
|
|
<ActionIcon
|
|
|
|
|
|
variant="default"
|
2022-05-14 21:42:11 +02:00
|
|
|
|
radius="md"
|
2022-04-30 21:35:39 +02:00
|
|
|
|
size="xl"
|
|
|
|
|
|
color="blue"
|
2022-04-27 03:12:17 +02:00
|
|
|
|
style={props.style}
|
|
|
|
|
|
onClick={() => setOpened(true)}
|
|
|
|
|
|
>
|
|
|
|
|
|
<Tooltip label="Settings">
|
2022-05-29 18:42:58 +02:00
|
|
|
|
<IconSettings />
|
2022-04-27 03:12:17 +02:00
|
|
|
|
</Tooltip>
|
|
|
|
|
|
</ActionIcon>
|
|
|
|
|
|
</>
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|