actually save value

This commit is contained in:
Erik 2023-07-05 14:28:06 +03:00
parent fd4d72eb21
commit 4b28045d60
Signed by: Navy.gif
GPG Key ID: 2532FBBB61C65A68
3 changed files with 37 additions and 35 deletions

View File

@ -28,6 +28,7 @@
"warn", "warn",
"allman" "allman"
], ],
"indent": "warn" "indent": "warn",
"semi": "error"
} }
} }

View File

@ -1,4 +1,4 @@
import React, { Children, useRef, useState } from "react"; import React, { useRef, useState } from "react";
import ClickDetector from "../util/ClickDetector"; import ClickDetector from "../util/ClickDetector";
import { DropdownBaseProps, DropdownItemProps } from "../@types/Components"; import { DropdownBaseProps, DropdownItemProps } from "../@types/Components";
import '../css/components/InputElements.css'; import '../css/components/InputElements.css';

View File

@ -21,19 +21,20 @@ const Flag = ({ flag: incoming }: { flag: APIFlag }) =>
const save = async () => const save = async () =>
{ {
const response = await patch(`/api/flags/${flag.id}`, flag); const response = await patch(`/api/flags/${flag.id}`, flag);
console.log(flag);
if (response.success) if (response.success)
setUnsaved(false); setUnsaved(false);
else else
setError(response.message) setError(response.message);
}; };
let Input = <p>Loading...</p>; let Input = <p>Loading...</p>;
if (flag.type === 'string') if (flag.type === 'string')
Input = <StringInput onChange={() => setUnsaved(true)} inputRef={valueRef} value={flag.value as string} />; Input = <StringInput onChange={({target}) => updateFlag({...flag, value: target.value })} inputRef={valueRef} value={flag.value as string} />;
else if (flag.type === 'number') else if (flag.type === 'number')
Input = <NumberInput onChange={() => setUnsaved(true)} inputRef={valueRef} value={flag.value as number} type='float' />; Input = <NumberInput onChange={({target}) => updateFlag({...flag, value: parseFloat(target.value)})} inputRef={valueRef} value={flag.value as number} type='float' />;
else if (flag.type === 'boolean') else if (flag.type === 'boolean')
Input = <ToggleSwitch onChange={() => setUnsaved(true)} inputRef={valueRef} value={flag.value as boolean} />; Input = <ToggleSwitch onChange={({target}) => updateFlag({...flag, value: target.value })} inputRef={valueRef} value={flag.value as boolean} />;
return <div className='flag mt-0 mb-1'> return <div className='flag mt-0 mb-1'>
{/* TODO: Improve these*/} {/* TODO: Improve these*/}