2022-08-02 00:21:51 +02:00
|
|
|
import { Text, SegmentedControl, TextInput, Stack } from '@mantine/core';
|
2022-06-07 08:21:03 +02:00
|
|
|
import { useState } from 'react';
|
2022-08-22 09:50:54 +02:00
|
|
|
import { useTranslation } from 'next-i18next';
|
2022-06-07 08:21:03 +02:00
|
|
|
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';
|
2022-06-28 19:08:18 +02:00
|
|
|
import Tip from '../layout/Tip';
|
2022-08-18 21:46:46 +02:00
|
|
|
import LanguageSwitch from './LanguageSwitch';
|
2022-06-07 08:21:03 +02:00
|
|
|
|
|
|
|
|
export default function CommonSettings(args: any) {
|
|
|
|
|
const { config, setConfig } = useConfig();
|
2022-08-22 09:50:54 +02:00
|
|
|
const { t } = useTranslation([
|
|
|
|
|
'settings/general/search-engine',
|
|
|
|
|
'settings/general/config-changer',
|
|
|
|
|
]);
|
2022-06-07 08:21:03 +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=' },
|
|
|
|
|
{ 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-08-02 02:21:04 +02:00
|
|
|
<Stack mb="md" mr="sm">
|
|
|
|
|
<Stack spacing={0} mt="xs">
|
2022-08-22 09:50:54 +02:00
|
|
|
<Text>{t('title')}</Text>
|
|
|
|
|
<Tip>{t('tips.generalTip')}</Tip>
|
2022-06-07 08:21:03 +02:00
|
|
|
<SegmentedControl
|
|
|
|
|
fullWidth
|
2022-06-28 19:08:18 +02:00
|
|
|
mb="sm"
|
2022-08-22 09:50:54 +02:00
|
|
|
title={t('title')}
|
2022-06-07 08:21:03 +02:00
|
|
|
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' && (
|
2022-06-28 19:08:18 +02:00
|
|
|
<>
|
2022-08-22 09:50:54 +02:00
|
|
|
<Tip>{t('tips.placeholderTip')}</Tip>
|
2022-06-28 19:08:18 +02:00
|
|
|
<TextInput
|
2022-08-22 09:50:54 +02:00
|
|
|
label={t('customEngine.label')}
|
|
|
|
|
placeholder={t('customEngine.placeholder')}
|
2022-06-28 19:08:18 +02:00
|
|
|
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
|
|
|
)}
|
2022-07-26 00:51:55 +02:00
|
|
|
</Stack>
|
2022-06-07 08:21:03 +02:00
|
|
|
<ColorSchemeSwitch />
|
2022-06-12 08:04:20 +02:00
|
|
|
<WidgetsPositionSwitch />
|
2022-06-11 19:44:11 +02:00
|
|
|
<ModuleEnabler />
|
2022-08-18 21:46:46 +02:00
|
|
|
<LanguageSwitch />
|
2022-06-07 08:21:03 +02:00
|
|
|
<ConfigChanger />
|
|
|
|
|
<SaveConfigComponent />
|
2022-08-22 09:50:54 +02:00
|
|
|
<Tip>{t('configTip')}</Tip>
|
2022-07-26 00:51:55 +02:00
|
|
|
</Stack>
|
2022-06-07 08:21:03 +02:00
|
|
|
);
|
|
|
|
|
}
|