mirror of
https://github.com/ajnart/homarr.git
synced 2025-11-10 23:45:48 +01:00
✨ Add custom search querry url in settings menu
This commit is contained in:
@@ -9,6 +9,7 @@ import {
|
|||||||
SegmentedControl,
|
SegmentedControl,
|
||||||
Indicator,
|
Indicator,
|
||||||
Alert,
|
Alert,
|
||||||
|
TextInput,
|
||||||
} from '@mantine/core';
|
} from '@mantine/core';
|
||||||
import { useColorScheme } from '@mantine/hooks';
|
import { useColorScheme } from '@mantine/hooks';
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
@@ -24,11 +25,19 @@ function SettingsMenu(props: any) {
|
|||||||
const { config, setConfig } = useConfig();
|
const { config, setConfig } = useConfig();
|
||||||
const colorScheme = useColorScheme();
|
const colorScheme = useColorScheme();
|
||||||
const { current, latest } = props;
|
const { current, latest } = props;
|
||||||
|
|
||||||
const matches = [
|
const matches = [
|
||||||
{ label: 'Google', value: 'https://google.com/search?q=' },
|
{ label: 'Google', value: 'https://google.com/search?q=' },
|
||||||
{ label: 'DuckDuckGo', value: 'https://duckduckgo.com/?q=' },
|
{ label: 'DuckDuckGo', value: 'https://duckduckgo.com/?q=' },
|
||||||
{ label: 'Bing', value: 'https://bing.com/search?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 (
|
return (
|
||||||
<Group direction="column" grow>
|
<Group direction="column" grow>
|
||||||
<Alert
|
<Alert
|
||||||
@@ -39,27 +48,47 @@ function SettingsMenu(props: any) {
|
|||||||
>
|
>
|
||||||
Version {latest} is available. Current : {current}
|
Version {latest} is available. Current : {current}
|
||||||
</Alert>
|
</Alert>
|
||||||
<Group>
|
<Group grow direction="column" spacing={0}>
|
||||||
|
<Text>Search engine</Text>
|
||||||
<SegmentedControl
|
<SegmentedControl
|
||||||
|
fullWidth
|
||||||
title="Search engine"
|
title="Search engine"
|
||||||
value={
|
value={
|
||||||
// Match config.settings.searchUrl with a key in the matches array
|
// Match config.settings.searchUrl with a key in the matches array
|
||||||
matches.find((match) => match.value === config.settings.searchUrl)?.value ?? 'Google'
|
searchUrl
|
||||||
}
|
}
|
||||||
onChange={
|
onChange={
|
||||||
// Set config.settings.searchUrl to the value of the selected item
|
// Set config.settings.searchUrl to the value of the selected item
|
||||||
(e) =>
|
(e) => {
|
||||||
|
setSearchUrl(e);
|
||||||
setConfig({
|
setConfig({
|
||||||
...config,
|
...config,
|
||||||
settings: {
|
settings: {
|
||||||
...config.settings,
|
...config.settings,
|
||||||
searchUrl: e,
|
searchUrl: e,
|
||||||
},
|
},
|
||||||
})
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
data={matches}
|
data={matches}
|
||||||
/>
|
/>
|
||||||
<Text>Search engine</Text>
|
{searchUrl === 'Custom' && (
|
||||||
|
<TextInput
|
||||||
|
label="Querry URL"
|
||||||
|
placeholder="Custom querry url"
|
||||||
|
value={customSearchUrl}
|
||||||
|
onChange={(event) => {
|
||||||
|
setCustomSearchUrl(event.currentTarget.value);
|
||||||
|
setConfig({
|
||||||
|
...config,
|
||||||
|
settings: {
|
||||||
|
...config.settings,
|
||||||
|
searchUrl: event.currentTarget.value,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</Group>
|
</Group>
|
||||||
<Group direction="column">
|
<Group direction="column">
|
||||||
<Switch
|
<Switch
|
||||||
|
|||||||
Reference in New Issue
Block a user