mirror of
https://github.com/ajnart/homarr.git
synced 2025-11-09 06:55:51 +01:00
🎉 Persistent config 🎉
After sweat and tears... It's there!
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
import {
|
import {
|
||||||
useMantineTheme,
|
|
||||||
Modal,
|
Modal,
|
||||||
Center,
|
Center,
|
||||||
Group,
|
Group,
|
||||||
@@ -21,9 +20,7 @@ import { ServiceTypeList } from '../../tools/types';
|
|||||||
import { AppShelfItemWrapper } from './AppShelfItemWrapper';
|
import { AppShelfItemWrapper } from './AppShelfItemWrapper';
|
||||||
|
|
||||||
export default function AddItemShelfItem(props: any) {
|
export default function AddItemShelfItem(props: any) {
|
||||||
const { addService } = useConfig();
|
|
||||||
const [opened, setOpened] = useState(false);
|
const [opened, setOpened] = useState(false);
|
||||||
const theme = useMantineTheme();
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Modal
|
<Modal
|
||||||
@@ -83,7 +80,7 @@ function MatchIcon(name: string, form: any) {
|
|||||||
form.setFieldValue('icon', res.url);
|
form.setFieldValue('icon', res.url);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((e) => {
|
.catch(() => {
|
||||||
// Do nothing
|
// Do nothing
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -92,7 +89,7 @@ function MatchIcon(name: string, form: any) {
|
|||||||
|
|
||||||
export function AddAppShelfItemForm(props: { setOpened: (b: boolean) => void } & any) {
|
export function AddAppShelfItemForm(props: { setOpened: (b: boolean) => void } & any) {
|
||||||
const { setOpened } = props;
|
const { setOpened } = props;
|
||||||
const { addService, config, setConfig } = useConfig();
|
const { config, setConfig } = useConfig();
|
||||||
const [isLoading, setLoading] = useState(false);
|
const [isLoading, setLoading] = useState(false);
|
||||||
|
|
||||||
const form = useForm({
|
const form = useForm({
|
||||||
@@ -104,7 +101,7 @@ export function AddAppShelfItemForm(props: { setOpened: (b: boolean) => void } &
|
|||||||
apiKey: props.apiKey ?? (undefined as unknown as string),
|
apiKey: props.apiKey ?? (undefined as unknown as string),
|
||||||
},
|
},
|
||||||
validate: {
|
validate: {
|
||||||
apiKey: (value: string) => null,
|
apiKey: () => null,
|
||||||
// Validate icon with a regex
|
// Validate icon with a regex
|
||||||
icon: (value: string) => {
|
icon: (value: string) => {
|
||||||
if (!value.match(/^https?:\/\/.+\.(png|jpg|jpeg|gif)$/)) {
|
if (!value.match(/^https?:\/\/.+\.(png|jpg|jpeg|gif)$/)) {
|
||||||
@@ -143,7 +140,10 @@ export function AddAppShelfItemForm(props: { setOpened: (b: boolean) => void } &
|
|||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
addService(form.values);
|
setConfig({
|
||||||
|
...config,
|
||||||
|
services: [...config.services, form.values],
|
||||||
|
});
|
||||||
}
|
}
|
||||||
setOpened(false);
|
setOpened(false);
|
||||||
form.reset();
|
form.reset();
|
||||||
|
|||||||
@@ -1,35 +1,18 @@
|
|||||||
import React, { useEffect, useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import { motion } from 'framer-motion';
|
import { motion } from 'framer-motion';
|
||||||
import {
|
import { Text, AspectRatio, SimpleGrid, Card, Image, Group, Space } from '@mantine/core';
|
||||||
Text,
|
|
||||||
AspectRatio,
|
|
||||||
SimpleGrid,
|
|
||||||
Card,
|
|
||||||
useMantineTheme,
|
|
||||||
Image,
|
|
||||||
Group,
|
|
||||||
Space,
|
|
||||||
} from '@mantine/core';
|
|
||||||
import { useConfig } from '../../tools/state';
|
import { useConfig } from '../../tools/state';
|
||||||
import { serviceItem } from '../../tools/types';
|
import { serviceItem } from '../../tools/types';
|
||||||
import AddItemShelfItem from './AddAppShelfItem';
|
import AddItemShelfItem from './AddAppShelfItem';
|
||||||
import { AppShelfItemWrapper } from './AppShelfItemWrapper';
|
import { AppShelfItemWrapper } from './AppShelfItemWrapper';
|
||||||
import AppShelfMenu from './AppShelfMenu';
|
import AppShelfMenu from './AppShelfMenu';
|
||||||
|
|
||||||
const AppShelf = (props: any) => {
|
const AppShelf = () => {
|
||||||
const { config, addService, removeService, setConfig } = useConfig();
|
const { config } = useConfig();
|
||||||
|
|
||||||
/* A hook that is used to load the config from local storage. */
|
|
||||||
useEffect(() => {
|
|
||||||
const localConfig = localStorage.getItem('config');
|
|
||||||
if (localConfig) {
|
|
||||||
setConfig(JSON.parse(localConfig));
|
|
||||||
}
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SimpleGrid m="xl" cols={5} spacing="xl">
|
<SimpleGrid m="xl" cols={5} spacing="xl">
|
||||||
{config.services.map((service, i) => (
|
{config.services.map((service) => (
|
||||||
<AppShelfItem key={service.name} service={service} />
|
<AppShelfItem key={service.name} service={service} />
|
||||||
))}
|
))}
|
||||||
<AddItemShelfItem />
|
<AddItemShelfItem />
|
||||||
@@ -39,16 +22,14 @@ const AppShelf = (props: any) => {
|
|||||||
|
|
||||||
export function AppShelfItem(props: any) {
|
export function AppShelfItem(props: any) {
|
||||||
const { service }: { service: serviceItem } = props;
|
const { service }: { service: serviceItem } = props;
|
||||||
const theme = useMantineTheme();
|
|
||||||
const { removeService } = useConfig();
|
|
||||||
const [hovering, setHovering] = useState(false);
|
const [hovering, setHovering] = useState(false);
|
||||||
return (
|
return (
|
||||||
<motion.div
|
<motion.div
|
||||||
key={service.name}
|
key={service.name}
|
||||||
onHoverStart={(e) => {
|
onHoverStart={() => {
|
||||||
setHovering(true);
|
setHovering(true);
|
||||||
}}
|
}}
|
||||||
onHoverEnd={(e) => {
|
onHoverEnd={() => {
|
||||||
setHovering(false);
|
setHovering(false);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
@@ -79,7 +60,7 @@ export function AppShelfItem(props: any) {
|
|||||||
opacity: hovering ? 1 : 0,
|
opacity: hovering ? 1 : 0,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<AppShelfMenu service={service} removeitem={removeService} />
|
<AppShelfMenu service={service} />
|
||||||
</motion.div>
|
</motion.div>
|
||||||
</Group>
|
</Group>
|
||||||
</Card.Section>
|
</Card.Section>
|
||||||
|
|||||||
@@ -2,10 +2,12 @@ import { Menu, Modal, Text } from '@mantine/core';
|
|||||||
import { showNotification } from '@mantine/notifications';
|
import { showNotification } from '@mantine/notifications';
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { Check, Edit, Trash } from 'tabler-icons-react';
|
import { Check, Edit, Trash } from 'tabler-icons-react';
|
||||||
|
import { useConfig } from '../../tools/state';
|
||||||
import { AddAppShelfItemForm } from './AddAppShelfItem';
|
import { AddAppShelfItemForm } from './AddAppShelfItem';
|
||||||
|
|
||||||
export default function AppShelfMenu(props: any) {
|
export default function AppShelfMenu(props: any) {
|
||||||
const { service, removeitem: removeItem } = props;
|
const { service } = props;
|
||||||
|
const { config, setConfig } = useConfig();
|
||||||
const [opened, setOpened] = useState(false);
|
const [opened, setOpened] = useState(false);
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -40,7 +42,10 @@ export default function AppShelfMenu(props: any) {
|
|||||||
<Menu.Item
|
<Menu.Item
|
||||||
color="red"
|
color="red"
|
||||||
onClick={(e: any) => {
|
onClick={(e: any) => {
|
||||||
removeItem(service.name);
|
setConfig({
|
||||||
|
...config,
|
||||||
|
services: config.services.filter((s) => s.name !== service.name),
|
||||||
|
});
|
||||||
showNotification({
|
showNotification({
|
||||||
autoClose: 5000,
|
autoClose: 5000,
|
||||||
title: (
|
title: (
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ export const dropzoneChildren = (status: DropzoneStatus, theme: MantineTheme) =>
|
|||||||
);
|
);
|
||||||
|
|
||||||
export default function LoadConfigComponent(props: any) {
|
export default function LoadConfigComponent(props: any) {
|
||||||
const { saveConfig, setConfig } = useConfig();
|
const { setConfig } = useConfig();
|
||||||
const theme = useMantineTheme();
|
const theme = useMantineTheme();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const openRef = useRef<() => void>();
|
const openRef = useRef<() => void>();
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ function SettingsMenu(props: any) {
|
|||||||
{ 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=' },
|
||||||
];
|
];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Group direction="column" grow>
|
<Group direction="column" grow>
|
||||||
<Alert
|
<Alert
|
||||||
|
|||||||
16
data/configs/cringe.json
Normal file
16
data/configs/cringe.json
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"name": "cringe",
|
||||||
|
"services": [
|
||||||
|
{
|
||||||
|
"type": "Other",
|
||||||
|
"name": "sonarr",
|
||||||
|
"icon": "https://cdn.jsdelivr.net/gh/walkxhub/dashboard-icons/png/sonarr.png",
|
||||||
|
"url": "http://sonarr.tv/"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"settings": {
|
||||||
|
"enabledModules": [],
|
||||||
|
"searchBar": true,
|
||||||
|
"searchUrl": "https://www.google.com/search?q="
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,14 +2,14 @@
|
|||||||
"name": "default",
|
"name": "default",
|
||||||
"services": [
|
"services": [
|
||||||
{
|
{
|
||||||
"type": "Other",
|
"type": "Other hello",
|
||||||
"name": "ok",
|
"name": "example",
|
||||||
"icon": "https://c.tenor.com/o656qFKDzeUAAAAC/rick-astley-never-gonna-give-you-up.gif",
|
"icon": "https://c.tenor.com/o656qFKDzeUAAAAC/rick-astley-never-gonna-give-you-up.gif",
|
||||||
"url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
|
"url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"settings": {
|
"settings": {
|
||||||
"searchBar": false,
|
"searchBar": true,
|
||||||
"searchUrl": "https://www.google.com/search?q=",
|
"searchUrl": "https://www.google.com/search?q=",
|
||||||
"enabledModules": []
|
"enabledModules": []
|
||||||
}
|
}
|
||||||
|
|||||||
16
data/configs/low.json
Normal file
16
data/configs/low.json
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"name": "low",
|
||||||
|
"services": [
|
||||||
|
{
|
||||||
|
"type": "I am ",
|
||||||
|
"name": "example",
|
||||||
|
"icon": "https://c.tenor.com/o656qFKDzeUAAAAC/rick-astley-never-gonna-give-you-up.gif",
|
||||||
|
"url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"settings": {
|
||||||
|
"searchBar": true,
|
||||||
|
"searchUrl": "https://www.google.com/search?q=",
|
||||||
|
"enabledModules": []
|
||||||
|
}
|
||||||
|
}
|
||||||
3
data/configs/undefined.json
Normal file
3
data/configs/undefined.json
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"true": ""
|
||||||
|
}
|
||||||
@@ -6,7 +6,7 @@ function Get(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
const files = fs.readdirSync('data/configs');
|
const files = fs.readdirSync('data/configs');
|
||||||
// Strip the .json extension from the file name
|
// Strip the .json extension from the file name
|
||||||
const configs = files.map((file) => file.replace('.json', ''));
|
const configs = files.map((file) => file.replace('.json', ''));
|
||||||
// Return the list of files
|
|
||||||
return res.status(200).json(configs);
|
return res.status(200).json(configs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,57 @@
|
|||||||
import { Group } from '@mantine/core';
|
import { Group } from '@mantine/core';
|
||||||
|
import { getCookie, setCookies } from 'cookies-next';
|
||||||
|
import { GetServerSidePropsContext } from 'next';
|
||||||
|
import path from 'path';
|
||||||
|
import fs from 'fs';
|
||||||
|
import { useEffect } from 'react';
|
||||||
import AppShelf from '../components/AppShelf/AppShelf';
|
import AppShelf from '../components/AppShelf/AppShelf';
|
||||||
import LoadConfigComponent from '../components/Config/LoadConfig';
|
import LoadConfigComponent from '../components/Config/LoadConfig';
|
||||||
import SearchBar from '../components/SearchBar/SearchBar';
|
import SearchBar from '../components/SearchBar/SearchBar';
|
||||||
|
import { Config } from '../tools/types';
|
||||||
|
import { useConfig } from '../tools/state';
|
||||||
|
|
||||||
export default function HomePage() {
|
export async function getServerSideProps({
|
||||||
|
req,
|
||||||
|
res,
|
||||||
|
}: GetServerSidePropsContext): Promise<{ props: { config: Config } }> {
|
||||||
|
let cookie = getCookie('config-name', { req, res });
|
||||||
|
if (!cookie) {
|
||||||
|
setCookies('config-name', 'default', { req, res, maxAge: 60 * 60 * 24 * 30 });
|
||||||
|
cookie = 'default';
|
||||||
|
}
|
||||||
|
// Check if the config file exists
|
||||||
|
const configPath = path.join(process.cwd(), 'data/configs', `${cookie}.json`);
|
||||||
|
if (!fs.existsSync(configPath)) {
|
||||||
|
return {
|
||||||
|
props: {
|
||||||
|
config: {
|
||||||
|
name: cookie.toString(),
|
||||||
|
services: [],
|
||||||
|
settings: {
|
||||||
|
enabledModules: [],
|
||||||
|
searchBar: true,
|
||||||
|
searchUrl: 'https://www.google.com/search?q=',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const config = fs.readFileSync(configPath, 'utf8');
|
||||||
|
// Print loaded config
|
||||||
|
return {
|
||||||
|
props: {
|
||||||
|
config: JSON.parse(config),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function HomePage(props: any) {
|
||||||
|
const { config: initialConfig }: { config: Config } = props;
|
||||||
|
const { config, loadConfig, setConfig, getConfigs } = useConfig();
|
||||||
|
useEffect(() => {
|
||||||
|
setConfig(initialConfig);
|
||||||
|
}, [initialConfig]);
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<SearchBar />
|
<SearchBar />
|
||||||
|
|||||||
@@ -2,20 +2,40 @@ import { getCookie, setCookies } from 'cookies-next';
|
|||||||
import { GetServerSidePropsContext } from 'next/types';
|
import { GetServerSidePropsContext } from 'next/types';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import { Button, JsonInput, Space } from '@mantine/core';
|
import { Button, JsonInput, Select, Space } from '@mantine/core';
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import axios from 'axios';
|
|
||||||
import { showNotification } from '@mantine/notifications';
|
|
||||||
import { Config } from '../tools/types';
|
import { Config } from '../tools/types';
|
||||||
import { useConfig } from '../tools/state';
|
import { useConfig } from '../tools/state';
|
||||||
|
|
||||||
export async function getServerSideProps({ req, res }: GetServerSidePropsContext) {
|
export async function getServerSideProps({
|
||||||
|
req,
|
||||||
|
res,
|
||||||
|
}: GetServerSidePropsContext): Promise<{ props: { config: Config } }> {
|
||||||
let cookie = getCookie('config-name', { req, res });
|
let cookie = getCookie('config-name', { req, res });
|
||||||
if (!cookie) {
|
if (!cookie) {
|
||||||
setCookies('config-name', 'default', { req, res, maxAge: 60 * 60 * 24 * 30 });
|
setCookies('config-name', 'default', { req, res, maxAge: 60 * 60 * 24 * 30 });
|
||||||
cookie = 'default';
|
cookie = 'default';
|
||||||
}
|
}
|
||||||
const config = fs.readFileSync(path.join('data/configs', `${cookie}.json`), 'utf8');
|
// Check if the config file exists
|
||||||
|
const configPath = path.join(process.cwd(), 'data/configs', `${cookie}.json`);
|
||||||
|
if (!fs.existsSync(configPath)) {
|
||||||
|
return {
|
||||||
|
props: {
|
||||||
|
config: {
|
||||||
|
name: cookie.toString(),
|
||||||
|
services: [],
|
||||||
|
settings: {
|
||||||
|
enabledModules: [],
|
||||||
|
searchBar: true,
|
||||||
|
searchUrl: 'https://www.google.com/search?q=',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const config = fs.readFileSync(configPath, 'utf8');
|
||||||
|
// Print loaded config
|
||||||
return {
|
return {
|
||||||
props: {
|
props: {
|
||||||
config: JSON.parse(config),
|
config: JSON.parse(config),
|
||||||
@@ -25,9 +45,13 @@ export async function getServerSideProps({ req, res }: GetServerSidePropsContext
|
|||||||
|
|
||||||
export default function TryConfig(props: any) {
|
export default function TryConfig(props: any) {
|
||||||
const { config: initialConfig }: { config: Config } = props;
|
const { config: initialConfig }: { config: Config } = props;
|
||||||
const { config, loadConfig, setConfig } = useConfig();
|
const { config, loadConfig, setConfig, getConfigs } = useConfig();
|
||||||
const [value, setValue] = useState(JSON.stringify(config, null, 2));
|
const [value, setValue] = useState(JSON.stringify(config, null, 2));
|
||||||
|
const [configList, setConfigList] = useState([] as string[]);
|
||||||
|
useEffect(() => {
|
||||||
|
setValue(JSON.stringify(initialConfig, null, 2));
|
||||||
|
setConfig(initialConfig);
|
||||||
|
}, [initialConfig]);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setValue(JSON.stringify(config, null, 2));
|
setValue(JSON.stringify(config, null, 2));
|
||||||
// setConfig(initialConfig);
|
// setConfig(initialConfig);
|
||||||
@@ -42,11 +66,35 @@ export default function TryConfig(props: any) {
|
|||||||
<p>
|
<p>
|
||||||
The <code>config</code> API is a way to store configuration data in a JSON file.
|
The <code>config</code> API is a way to store configuration data in a JSON file.
|
||||||
</p>
|
</p>
|
||||||
|
<p>
|
||||||
|
Cookie loaded was <code>{initialConfig.name}</code>
|
||||||
|
</p>
|
||||||
<JsonInput autosize onChange={setValue} value={value} />
|
<JsonInput autosize onChange={setValue} value={value} />
|
||||||
<Space my="xl" />
|
<Space my="xl" />
|
||||||
<Button onClick={() => loadConfig('cringe')}>Load config cringe</Button>
|
<Button onClick={() => getConfigs().then((configs) => setConfigList(configs))}>
|
||||||
<Button onClick={() => loadConfig('default')}>Load config default</Button>
|
Get configs
|
||||||
<Button onClick={() => setConfig(JSON.parse(value))}>Save config</Button>
|
</Button>
|
||||||
|
<Space my="xl" />
|
||||||
|
<Select
|
||||||
|
label="Config loader"
|
||||||
|
onChange={(e) => {
|
||||||
|
loadConfig(e ?? 'default');
|
||||||
|
}}
|
||||||
|
data={
|
||||||
|
// If config list is empty, return the current config
|
||||||
|
configList.length === 0 ? [config.name] : configList
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<Space my="xl" />
|
||||||
|
<Button mx="md" onClick={() => setConfig(JSON.parse(value))}>
|
||||||
|
Save config
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
mx="md"
|
||||||
|
onClick={() => setCookies('config-name', 'cringe', { maxAge: 60 * 60 * 24 * 30 })}
|
||||||
|
>
|
||||||
|
Set cookie to config = cringe
|
||||||
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ type configContextType = {
|
|||||||
config: Config;
|
config: Config;
|
||||||
setConfig: (newconfig: Config) => void;
|
setConfig: (newconfig: Config) => void;
|
||||||
loadConfig: (name: string) => void;
|
loadConfig: (name: string) => void;
|
||||||
|
getConfigs: () => Promise<string[]>;
|
||||||
};
|
};
|
||||||
|
|
||||||
const configContext = createContext<configContextType>({
|
const configContext = createContext<configContextType>({
|
||||||
@@ -23,6 +24,7 @@ const configContext = createContext<configContextType>({
|
|||||||
},
|
},
|
||||||
setConfig: () => {},
|
setConfig: () => {},
|
||||||
loadConfig: async (name: string) => {},
|
loadConfig: async (name: string) => {},
|
||||||
|
getConfigs: async () => [],
|
||||||
});
|
});
|
||||||
|
|
||||||
export function useConfig() {
|
export function useConfig() {
|
||||||
@@ -40,14 +42,7 @@ type Props = {
|
|||||||
export function ConfigProvider({ children }: Props) {
|
export function ConfigProvider({ children }: Props) {
|
||||||
const [config, setConfigInternal] = useState<Config>({
|
const [config, setConfigInternal] = useState<Config>({
|
||||||
name: 'default',
|
name: 'default',
|
||||||
services: [
|
services: [],
|
||||||
{
|
|
||||||
type: 'Other',
|
|
||||||
name: 'example',
|
|
||||||
icon: 'https://c.tenor.com/o656qFKDzeUAAAAC/rick-astley-never-gonna-give-you-up.gif',
|
|
||||||
url: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
settings: {
|
settings: {
|
||||||
searchBar: true,
|
searchBar: true,
|
||||||
searchUrl: 'https://www.google.com/search?q=',
|
searchUrl: 'https://www.google.com/search?q=',
|
||||||
@@ -58,7 +53,6 @@ export function ConfigProvider({ children }: Props) {
|
|||||||
async function loadConfig(configName: string) {
|
async function loadConfig(configName: string) {
|
||||||
try {
|
try {
|
||||||
const response = await axios.get(`/api/configs/${configName}`);
|
const response = await axios.get(`/api/configs/${configName}`);
|
||||||
console.log('response', response);
|
|
||||||
setConfigInternal(response.data);
|
setConfigInternal(response.data);
|
||||||
showNotification({
|
showNotification({
|
||||||
title: 'Config',
|
title: 'Config',
|
||||||
@@ -85,10 +79,16 @@ export function ConfigProvider({ children }: Props) {
|
|||||||
setConfigInternal(newconfig);
|
setConfigInternal(newconfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getConfigs(): Promise<string[]> {
|
||||||
|
const response = await axios.get('/api/configs');
|
||||||
|
return response.data;
|
||||||
|
}
|
||||||
|
|
||||||
const value = {
|
const value = {
|
||||||
config,
|
config,
|
||||||
setConfig,
|
setConfig,
|
||||||
loadConfig,
|
loadConfig,
|
||||||
|
getConfigs,
|
||||||
};
|
};
|
||||||
return <configContext.Provider value={value}>{children}</configContext.Provider>;
|
return <configContext.Provider value={value}>{children}</configContext.Provider>;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user