Files
Homarr/src/components/Settings/SettingsMenu.tsx

163 lines
4.5 KiB
TypeScript
Raw Normal View History

import {
ActionIcon,
Group,
Title,
Text,
Tooltip,
SegmentedControl,
TextInput,
Drawer,
2022-05-26 20:07:54 +02:00
Anchor,
} from '@mantine/core';
import { useColorScheme, useHotkeys } from '@mantine/hooks';
import { useState } from 'react';
2022-05-26 20:07:54 +02:00
import { BrandGithub, Settings as SettingsIcon } from 'tabler-icons-react';
import { CURRENT_VERSION } from '../../../data/constants';
import { useConfig } from '../../tools/state';
import { ColorSchemeSwitch } from '../ColorSchemeToggle/ColorSchemeSwitch';
import ConfigChanger from '../Config/ConfigChanger';
2022-04-27 03:12:17 +02:00
import SaveConfigComponent from '../Config/SaveConfig';
import ModuleEnabler from './ModuleEnabler';
2022-04-27 03:12:17 +02:00
function SettingsMenu(props: any) {
const { config, setConfig } = useConfig();
const colorScheme = useColorScheme();
const { current, latest } = props;
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=' },
{ label: 'Custom', value: 'Custom' },
];
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>
<Group grow direction="column" spacing={0}>
<Text>Search engine</Text>
<SegmentedControl
fullWidth
title="Search engine"
value={
// Match config.settings.searchUrl with a key in the matches array
searchUrl
}
onChange={
// Set config.settings.searchUrl to the value of the selected item
(e) => {
setSearchUrl(e);
setConfig({
...config,
settings: {
...config.settings,
searchUrl: e,
},
});
}
}
data={matches}
/>
{searchUrl === 'Custom' && (
<TextInput
2022-05-16 12:38:46 +02:00
label="Query URL"
placeholder="Custom query url"
value={customSearchUrl}
onChange={(event) => {
setCustomSearchUrl(event.currentTarget.value);
setConfig({
...config,
settings: {
...config.settings,
searchUrl: event.currentTarget.value,
},
});
}}
/>
)}
</Group>
<ModuleEnabler />
<ColorSchemeSwitch />
<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) {
useHotkeys([['ctrl+L', () => setOpened(!opened)]]);
2022-04-27 03:12:17 +02:00
const [opened, setOpened] = useState(false);
return (
<>
<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)}
>
<SettingsMenu />
</Drawer>
2022-04-27 03:12:17 +02:00
<ActionIcon
variant="default"
2022-05-14 21:42:11 +02:00
radius="md"
size="xl"
color="blue"
2022-04-27 03:12:17 +02:00
style={props.style}
onClick={() => setOpened(true)}
>
<Tooltip label="Settings">
<SettingsIcon />
2022-04-27 03:12:17 +02:00
</Tooltip>
</ActionIcon>
</>
);
}