Fix checkbox inputs always being unchecked on load

This commit is contained in:
grimsi
2024-09-10 17:14:26 +02:00
parent eb7c0c5d87
commit 4e75075c01
4 changed files with 17 additions and 6 deletions
@@ -10,7 +10,9 @@ const CheckboxInput = ({label, ...props}) => {
<div className="flex flex-row flex-grow items-center gap-2 my-2">
<Checkbox
{...field}
id={field.name}>
id={field.name}
isSelected={field.value}
>
{label}
</Checkbox>
</div>
+1 -1
View File
@@ -8,7 +8,7 @@ const Input = ({label, ...props}) => {
const [field, meta] = useField(props);
return (
<div className="grid w-full max-w-sm items-center gap-2 my-2">
<div className="flex flex-grow max-w-sm items-center gap-2 my-2">
<NextUiInput
{...props}
{...field}
@@ -5,6 +5,7 @@ import {Form, Formik} from "formik";
import ConfigFormField from "Frontend/components/administration/ConfigFormField";
import {Button, Divider, Skeleton} from "@nextui-org/react";
import {toast} from "sonner";
import {Check} from "@phosphor-icons/react";
type NestedConfig = {
[field: string]: any;
@@ -17,6 +18,7 @@ type ConfigValuePair = {
export function LibraryManagement() {
const isInitialized = useRef(false);
const [configSaved, setConfigSaved] = useState(false);
const [configDtos, setConfigDtos] = useState<ConfigEntryDto[]>([]);
useEffect(() => {
@@ -26,6 +28,12 @@ export function LibraryManagement() {
});
}, []);
useEffect(() => {
if (configSaved) {
setTimeout(() => setConfigSaved(false), 2000);
}
}, [configSaved])
async function handleSubmit(values: NestedConfig) {
const configValues = toConfigValuePair(values);
await Promise.all(configValues.map(async (c: ConfigValuePair) => {
@@ -37,6 +45,7 @@ export function LibraryManagement() {
await ConfigController.setConfig(c.key, c.value.toString());
}));
setConfigSaved(true);
toast.success("Configuration saved");
}
@@ -122,9 +131,10 @@ export function LibraryManagement() {
<Button
color="secondary"
isLoading={formik.isSubmitting}
disabled={formik.isSubmitting || configSaved}
type="submit"
>
{formik.isSubmitting ? "" : "Save"}
{formik.isSubmitting ? "" : configSaved ? <Check/> : "Save"}
</Button>
</div>
<div className="mb-8 flex flex-col flex-grow">
@@ -145,7 +155,6 @@ export function LibraryManagement() {
<ConfigFormField
configElement={getConfig("library.display.games-per-page")}></ConfigFormField>
</div>
<pre>{JSON.stringify(formik.values, null, 2)}</pre>
</Form>
)}
</Formik>
@@ -8,11 +8,11 @@ import org.springframework.web.servlet.HandlerInterceptor
@Component
@Profile("development")
@Profile("dev")
class DelayInterceptor : HandlerInterceptor {
override fun preHandle(request: HttpServletRequest, response: HttpServletResponse, handler: Any): Boolean {
Thread.sleep(2000)
if (request.requestURI.startsWith("/connect")) Thread.sleep(2000)
return true
}