diff --git a/frontend/src/helpers/ini.ts b/frontend/src/helpers/ini.ts new file mode 100644 index 0000000..71bbc0b --- /dev/null +++ b/frontend/src/helpers/ini.ts @@ -0,0 +1,18 @@ +// getVal is a function that takes a gus object, a section, a key, and an index, and returns a string. This function is used to handle when anything is undefined, if so it creates it. +export function getVal(gus: { [key: string]: { [key: string]: Array } }, section: string, key: string, index: number = 0): string { + + if (!gus[section]) { + gus[section] = {}; + } + + if (!gus[section][key]) { + gus[section][key] = []; + } + + if (!gus[section][key][index]) { + gus[section][key][index] = ''; + return gus[section][key][index]; + } + + return gus[section][key][index]; +} \ No newline at end of file diff --git a/frontend/src/pages/server/General.tsx b/frontend/src/pages/server/General.tsx index 6183cf6..da31066 100644 --- a/frontend/src/pages/server/General.tsx +++ b/frontend/src/pages/server/General.tsx @@ -26,6 +26,7 @@ import { PasswordInput } from "../../components/PasswordInput"; import { Slider } from "../../components/Slider"; import { useAlert } from "../../components/AlertProvider"; import { EventsOn } from "../../../wailsjs/runtime"; +import {getVal} from "../../helpers/ini"; type Props = { setServ: React.Dispatch>; @@ -136,9 +137,7 @@ function GeneralSettings({ setServ, serv, setGus, gus }: Props) { > { setGus((p) => { @@ -161,11 +160,11 @@ function GeneralSettings({ setServ, serv, setGus, gus }: Props) { Message