fix: env ID generation and React state synchronization

This commit is contained in:
sokol
2026-02-18 15:51:13 +03:00
parent f262c785aa
commit 6565223b96
2 changed files with 47 additions and 61 deletions

View File

@@ -44,8 +44,12 @@ export function Environment(props: { envs: Env[], onChanged: (env: Env) => void,
const name = prompt("Enter new environment name:");
if (!name || name.trim() === "") return;
// Calculate next integer ID based on max existing ID
const maxId = props.envs.reduce((max, e) => Math.max(max, e.id ?? 0), -1);
const newId = maxId + 1;
const newEnv = new Env(
Math.random() * 10000,
newId,
name.trim(),
[...currEnv.params]
);