mirror of
https://github.com/ajnart/homarr.git
synced 2025-11-11 07:55:52 +01:00
🧑💻 Added strings as an option type for modules
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { Card, Menu, Switch, useMantineTheme } from '@mantine/core';
|
import { Button, Card, Group, Menu, Switch, TextInput, useMantineTheme } from '@mantine/core';
|
||||||
import { useConfig } from '../../tools/state';
|
import { useConfig } from '../../tools/state';
|
||||||
import { IModule } from './modules';
|
import { IModule } from './modules';
|
||||||
|
|
||||||
@@ -19,13 +19,51 @@ export function ModuleWrapper(props: any) {
|
|||||||
types.forEach((type, index) => {
|
types.forEach((type, index) => {
|
||||||
const optionName = `${module.title}.${keys[index]}`;
|
const optionName = `${module.title}.${keys[index]}`;
|
||||||
const moduleInConfig = config.modules?.[module.title];
|
const moduleInConfig = config.modules?.[module.title];
|
||||||
|
if (type === 'string') {
|
||||||
|
items.push(
|
||||||
|
<form
|
||||||
|
onSubmit={(e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
setConfig({
|
||||||
|
...config,
|
||||||
|
modules: {
|
||||||
|
...config.modules,
|
||||||
|
[module.title]: {
|
||||||
|
...config.modules[module.title],
|
||||||
|
options: {
|
||||||
|
...config.modules[module.title].options,
|
||||||
|
[keys[index]]: {
|
||||||
|
...config.modules[module.title].options[keys[index]],
|
||||||
|
value: (e.target as any)[0].value,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Group noWrap align="end" position="center" mt={0}>
|
||||||
|
<TextInput
|
||||||
|
key={optionName}
|
||||||
|
id={optionName}
|
||||||
|
name={optionName}
|
||||||
|
label={values[index].name}
|
||||||
|
defaultValue={(moduleInConfig?.options?.[keys[index]]?.value as string) ?? ''}
|
||||||
|
onChange={(e) => {}}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Button type="submit">Save</Button>
|
||||||
|
</Group>
|
||||||
|
</form>
|
||||||
|
);
|
||||||
|
}
|
||||||
// TODO: Add support for other types
|
// TODO: Add support for other types
|
||||||
if (type === 'boolean') {
|
if (type === 'boolean') {
|
||||||
items.push(
|
items.push(
|
||||||
<Switch
|
<Switch
|
||||||
defaultChecked={
|
defaultChecked={
|
||||||
// Set default checked to the value of the option if it exists
|
// Set default checked to the value of the option if it exists
|
||||||
moduleInConfig?.options?.[keys[index]]?.value ?? false
|
(moduleInConfig?.options?.[keys[index]]?.value as boolean) ?? false
|
||||||
}
|
}
|
||||||
key={keys[index]}
|
key={keys[index]}
|
||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
@@ -59,7 +97,7 @@ export function ModuleWrapper(props: any) {
|
|||||||
<Card hidden={!isShown} mx="sm" withBorder radius="lg" shadow="sm">
|
<Card hidden={!isShown} mx="sm" withBorder radius="lg" shadow="sm">
|
||||||
{module.options && (
|
{module.options && (
|
||||||
<Menu
|
<Menu
|
||||||
size="md"
|
size="lg"
|
||||||
shadow="xl"
|
shadow="xl"
|
||||||
closeOnItemClick={false}
|
closeOnItemClick={false}
|
||||||
radius="md"
|
radius="md"
|
||||||
|
|||||||
@@ -16,5 +16,5 @@ interface Option {
|
|||||||
|
|
||||||
export interface OptionValues {
|
export interface OptionValues {
|
||||||
name: string;
|
name: string;
|
||||||
value: boolean;
|
value: boolean | string;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user