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

87 lines
2.9 KiB
TypeScript
Raw Normal View History

2022-06-28 11:06:45 +02:00
import { Group, Text, SegmentedControl, TextInput } from '@mantine/core';
2022-06-07 08:21:03 +02:00
import { useState } from 'react';
import { useConfig } from '../../tools/state';
import { ColorSchemeSwitch } from '../ColorSchemeToggle/ColorSchemeSwitch';
2022-06-12 08:04:20 +02:00
import { WidgetsPositionSwitch } from '../WidgetsPositionSwitch/WidgetsPositionSwitch';
2022-06-07 08:21:03 +02:00
import ConfigChanger from '../Config/ConfigChanger';
import SaveConfigComponent from '../Config/SaveConfig';
import ModuleEnabler from './ModuleEnabler';
import Tip from '../layout/Tip';
2022-06-07 08:21:03 +02:00
export default function CommonSettings(args: any) {
const { config, setConfig } = useConfig();
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'
);
return (
2022-06-28 11:06:45 +02:00
<Group direction="column" grow mb="lg">
2022-06-07 08:21:03 +02:00
<Group grow direction="column" spacing={0}>
<Text>Search engine</Text>
<Tip>
Use the prefixes <b>!yt</b> and <b>!t</b> in front of your query to search on YouTube or
for a Torrent respectively.
</Tip>
2022-06-07 08:21:03 +02:00
<SegmentedControl
fullWidth
mb="sm"
2022-06-07 08:21:03 +02:00
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' && (
<>
<Tip>%s can be used as a placeholder for the query.</Tip>
<TextInput
label="Query URL"
placeholder="Custom query URL"
value={customSearchUrl}
onChange={(event) => {
setCustomSearchUrl(event.currentTarget.value);
setConfig({
...config,
settings: {
...config.settings,
searchUrl: event.currentTarget.value,
},
});
}}
/>
</>
2022-06-07 08:21:03 +02:00
)}
</Group>
<ColorSchemeSwitch />
2022-06-12 08:04:20 +02:00
<WidgetsPositionSwitch />
<ModuleEnabler />
2022-06-07 08:21:03 +02:00
<ConfigChanger />
<SaveConfigComponent />
<Tip>Upload your config file by dragging and dropping it onto the page!</Tip>
2022-06-07 08:21:03 +02:00
</Group>
);
}