mirror of
https://github.com/ajnart/homarr.git
synced 2025-11-14 17:26:26 +01:00
Update settings and search bar
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import { Input, TextInput, Text, ActionIcon, useMantineTheme } from '@mantine/core';
|
import { Input, TextInput, Text, ActionIcon, useMantineTheme } from '@mantine/core';
|
||||||
|
import { useForm } from '@mantine/hooks';
|
||||||
import { showNotification } from '@mantine/notifications';
|
import { showNotification } from '@mantine/notifications';
|
||||||
import { useState, useEffect } from 'react';
|
import { useState, useEffect } from 'react';
|
||||||
import { Search, ArrowRight, ArrowLeft } from 'tabler-icons-react';
|
import { Search, ArrowRight, ArrowLeft } from 'tabler-icons-react';
|
||||||
@@ -8,6 +9,13 @@ export default function SearchBar(props: any) {
|
|||||||
const theme = useMantineTheme();
|
const theme = useMantineTheme();
|
||||||
const [config, setConfig] = useState<Config>({
|
const [config, setConfig] = useState<Config>({
|
||||||
searchBar: true,
|
searchBar: true,
|
||||||
|
searchUrl : 'https://www.google.com/search?q=',
|
||||||
|
});
|
||||||
|
const querryUrl = config.searchUrl || 'https://www.google.com/search?q=';
|
||||||
|
const form = useForm({
|
||||||
|
initialValues: {
|
||||||
|
querry: '',
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -21,21 +29,22 @@ export default function SearchBar(props: any) {
|
|||||||
setConfig(config);
|
setConfig(config);
|
||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
if (!config.searchBar) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TextInput
|
<form onSubmit={form.onSubmit((values) => window.open(`${querryUrl}${values.querry}`))}>
|
||||||
icon={<Search size={18} />}
|
<TextInput
|
||||||
radius="xl"
|
icon={<Search size={18} />}
|
||||||
size="md"
|
radius="xl"
|
||||||
placeholder="Search the web"
|
size="md"
|
||||||
onChange={(e) => {
|
placeholder="Search the web"
|
||||||
showNotification({
|
rightSectionWidth={42}
|
||||||
autoClose: 1000,
|
{...props}
|
||||||
title: <Text>Searching for {e.target.value}</Text>,
|
{...form.getInputProps('querry')}
|
||||||
message: undefined,
|
/>
|
||||||
});
|
</form>
|
||||||
}}
|
|
||||||
rightSectionWidth={42}
|
|
||||||
{...props}
|
|
||||||
/>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { ActionIcon, Group, Modal, Switch, Title, Text, Tooltip } from '@mantine/core';
|
import { ActionIcon, Group, Modal, Switch, Title, Text, Tooltip, TextInput } from '@mantine/core';
|
||||||
import { showNotification } from '@mantine/notifications';
|
import { showNotification } from '@mantine/notifications';
|
||||||
import { motion } from 'framer-motion';
|
import { motion } from 'framer-motion';
|
||||||
import { CSSProperties, useEffect, useState } from 'react';
|
import { CSSProperties, useEffect, useState } from 'react';
|
||||||
@@ -8,6 +8,7 @@ import SaveConfigComponent from '../Config/SaveConfig';
|
|||||||
|
|
||||||
function SettingsMenu(props: any) {
|
function SettingsMenu(props: any) {
|
||||||
const [config, setConfig] = useState<Config>({
|
const [config, setConfig] = useState<Config>({
|
||||||
|
searchUrl: 'https://www.google.com/search?q=',
|
||||||
searchBar: true,
|
searchBar: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -18,24 +19,42 @@ function SettingsMenu(props: any) {
|
|||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
return (
|
return (
|
||||||
<Group direction="column">
|
<Group direction="column" grow>
|
||||||
<Switch
|
|
||||||
onChange={(e) => {
|
<TextInput label='Search bar querry url' defaultValue={config.searchUrl} onChange={
|
||||||
|
(e) => {
|
||||||
setConfig({
|
setConfig({
|
||||||
...config,
|
...config,
|
||||||
searchBar: e.target.checked,
|
searchUrl: e.target.value
|
||||||
});
|
});
|
||||||
localStorage.setItem(
|
localStorage.setItem(
|
||||||
'settings',
|
'settings',
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
...config,
|
...config,
|
||||||
searchBar: e.target.checked,
|
searchUrl: e.target.value,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}}
|
}
|
||||||
checked={config.searchBar}
|
} />
|
||||||
label="Enable search bar"
|
<Group direction="column" >
|
||||||
/>
|
<Switch
|
||||||
|
onChange={(e) => {
|
||||||
|
setConfig({
|
||||||
|
...config,
|
||||||
|
searchBar: e.target.checked,
|
||||||
|
});
|
||||||
|
localStorage.setItem(
|
||||||
|
'settings',
|
||||||
|
JSON.stringify({
|
||||||
|
...config,
|
||||||
|
searchBar: e.target.checked,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
checked={config.searchBar}
|
||||||
|
label="Enable search bar"
|
||||||
|
/>
|
||||||
|
</Group>
|
||||||
<SaveConfigComponent />
|
<SaveConfigComponent />
|
||||||
<Text
|
<Text
|
||||||
style={{
|
style={{
|
||||||
@@ -56,7 +75,7 @@ export function SettingsMenuButton(props: any) {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Modal
|
<Modal
|
||||||
size={'xl'}
|
size={'md'}
|
||||||
title={<Title order={3}>Settings</Title>}
|
title={<Title order={3}>Settings</Title>}
|
||||||
opened={props.opened || opened}
|
opened={props.opened || opened}
|
||||||
onClose={() => setOpened(false)}
|
onClose={() => setOpened(false)}
|
||||||
|
|||||||
@@ -12,5 +12,6 @@ export function loadConfig(path: string): Config | null {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface Config {
|
export interface Config {
|
||||||
|
searchUrl: string;
|
||||||
searchBar: boolean,
|
searchBar: boolean,
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user