mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-30 19:39:10 +00:00
fix: multi select infinite loop
This commit is contained in:
committed by
Alex Christoffer Rasmussen
parent
d00d7677bc
commit
bffa863fb4
@@ -39,7 +39,14 @@ export default function ParamInput({ paramField }: ParamInputProps) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (type === 'multi-option') {
|
if (type === 'multi-option') {
|
||||||
return <MultiOption paramField={paramField} />;
|
const optionFromParams = searchParams.getAll(id);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<MultiOption
|
||||||
|
paramField={paramField}
|
||||||
|
options={optionFromParams.length ? optionFromParams : paramField.defaultValue ?? ['']}
|
||||||
|
/>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type === 'boolean') {
|
if (type === 'boolean') {
|
||||||
@@ -74,19 +81,17 @@ export default function ParamInput({ paramField }: ParamInputProps) {
|
|||||||
|
|
||||||
interface EditFormMultiOptionProps {
|
interface EditFormMultiOptionProps {
|
||||||
paramField: ParamField & { type: 'multi-option' };
|
paramField: ParamField & { type: 'multi-option' };
|
||||||
|
options: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
function MultiOption({ paramField }: EditFormMultiOptionProps) {
|
function MultiOption({ paramField, options }: EditFormMultiOptionProps) {
|
||||||
const [searchParams] = useSearchParams();
|
const { id, values } = paramField;
|
||||||
const { id, values, defaultValue = [''] } = paramField;
|
const [paramState, setParamState] = useState<string[]>(options);
|
||||||
|
|
||||||
const optionFromParams = searchParams.getAll(id);
|
|
||||||
const [paramState, setParamState] = useState<string[]>(optionFromParams.length ? optionFromParams : defaultValue);
|
|
||||||
|
|
||||||
|
// synchronise options
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const params = searchParams.getAll(id);
|
setParamState(options);
|
||||||
setParamState(params.length ? params : defaultValue);
|
}, [options]);
|
||||||
}, [searchParams, id, defaultValue]);
|
|
||||||
|
|
||||||
const toggleValue = (value: string, checked: boolean) => {
|
const toggleValue = (value: string, checked: boolean) => {
|
||||||
if (checked) {
|
if (checked) {
|
||||||
|
|||||||
Reference in New Issue
Block a user