Some fiddling, but also version upgrades and a new button for downloading a pdf version of the current maze.
Some checks reported errors
continuous-integration/drone/push Build encountered an error
Some checks reported errors
continuous-integration/drone/push Build encountered an error
This commit is contained in:
parent
79467e29f2
commit
b6359bcb5d
21 changed files with 2002 additions and 927 deletions
|
|
@ -1,5 +1,4 @@
|
|||
import {ActionDispatch, FormEvent, useState} from 'react';
|
||||
import ValidatingInputNumberField, {ValidatorFunction} from "./validating-input-number-field.tsx";
|
||||
import {
|
||||
Action,
|
||||
actionLoadedMaze,
|
||||
|
|
@ -7,10 +6,14 @@ import {
|
|||
actionStartedLoading,
|
||||
actionToggledShowSolution
|
||||
} from "./state/action.ts";
|
||||
import styles from "./input-form.module.css";
|
||||
import "./input-form.css";
|
||||
import styles from "./input-form.module.scss";
|
||||
import "./input-form.scss";
|
||||
import {State} from "@/app/state/state.ts";
|
||||
import ValidatingInputBigIntField from "@/app/validating-input-bigint-field.tsx";
|
||||
import {
|
||||
ValidatingInputNumberField,
|
||||
ValidatingInputRegExpField,
|
||||
ValidatorFunction
|
||||
} from "@/app/validating-input-field.tsx";
|
||||
|
||||
export default function InputForm({state, dispatch}: {
|
||||
state: State,
|
||||
|
|
@ -18,7 +21,7 @@ export default function InputForm({state, dispatch}: {
|
|||
}) {
|
||||
const [width, setWidth] = useState(10);
|
||||
const [height, setHeight] = useState(10);
|
||||
const [id, setId] = useState<bigint>();
|
||||
const [id, setId] = useState<string>();
|
||||
const [algorithm, setAlgorithm] = useState('wilson');
|
||||
|
||||
const handleSubmit = (e: FormEvent) => {
|
||||
|
|
@ -36,7 +39,7 @@ export default function InputForm({state, dispatch}: {
|
|||
dispatch(actionLoadingFailed(reason));
|
||||
});
|
||||
};
|
||||
const validateWidthHeightInput: ValidatorFunction<string, number> = value => {
|
||||
const validateSizeInput: ValidatorFunction<string, number> = value => {
|
||||
const numberValue = Number(value);
|
||||
if (isNaN(numberValue) || "" === value || (Math.floor(numberValue) !== numberValue)) {
|
||||
return {
|
||||
|
|
@ -55,24 +58,6 @@ export default function InputForm({state, dispatch}: {
|
|||
value: numberValue
|
||||
};
|
||||
};
|
||||
const validateIdInput: ValidatorFunction<string, bigint> = value => {
|
||||
if ("" === value) {
|
||||
return {
|
||||
valid: true
|
||||
};
|
||||
}
|
||||
const numberValue = BigInt(value);
|
||||
if (numberValue.toString() !== value.trim()) {
|
||||
return {
|
||||
valid: false,
|
||||
message: "Must be empty or an integer"
|
||||
};
|
||||
}
|
||||
return {
|
||||
valid: true,
|
||||
value: numberValue
|
||||
}
|
||||
};
|
||||
return (
|
||||
<form onSubmit={handleSubmit}>
|
||||
<div className={styles.inputform}>
|
||||
|
|
@ -82,7 +67,7 @@ export default function InputForm({state, dispatch}: {
|
|||
constraints={{
|
||||
min: 2
|
||||
}}
|
||||
validatorFn={validateWidthHeightInput}
|
||||
validatorFn={validateSizeInput}
|
||||
disabled={state.loading}
|
||||
onChange={setWidth}
|
||||
/>
|
||||
|
|
@ -92,16 +77,30 @@ export default function InputForm({state, dispatch}: {
|
|||
constraints={{
|
||||
min: 2
|
||||
}}
|
||||
validatorFn={validateWidthHeightInput}
|
||||
validatorFn={validateSizeInput}
|
||||
disabled={state.loading}
|
||||
onChange={setHeight}
|
||||
/>
|
||||
<ValidatingInputBigIntField id={"id"}
|
||||
{/*<ValidatingInputBigIntField id={"id"}*/}
|
||||
{/* label={"ID (optional)"}*/}
|
||||
{/* value={id}*/}
|
||||
{/* validatorFn={validateIdInput}*/}
|
||||
{/* disabled={state.loading}*/}
|
||||
{/* onChange={setId}*/}
|
||||
{/* constraints={{*/}
|
||||
{/* min: -9223372036854775808n,*/}
|
||||
{/* max: 9223372036854775807n*/}
|
||||
{/* }}*/}
|
||||
{/*/>*/}
|
||||
<ValidatingInputRegExpField id={"id"}
|
||||
label={"ID (optional)"}
|
||||
value={id}
|
||||
validatorFn={validateIdInput}
|
||||
disabled={state.loading}
|
||||
onChange={setId}
|
||||
constraints={[
|
||||
/^[0-9a-fA-F]{0,16}$/
|
||||
]}
|
||||
placeholder={"Hex-Number (without 0x prefix)"}
|
||||
/>
|
||||
<label htmlFor="algorithm">Algorithm:</label>
|
||||
<select id={"algorithm"}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue