STANEK: FIX #3669 Clearing stanek grid using API could crash the page.

Fix #3669 - Query the "activegrid" at each re-rerendering of the Stanek Page. Rather than using React useState and passing it as Props.

Tested with :
ns.clearLog()
ns.tail()
await ns.sleep(2000)

ns.print("Clearing gift")
await ns.sleep(1000);
ns.stanek.clearGift()
This commit is contained in:
borisflagell
2022-05-22 00:57:30 +02:00
parent b2659318c8
commit ce5fdb00af
2 changed files with 5 additions and 7 deletions
-4
View File
@@ -18,7 +18,6 @@ interface IProps {
}
export function MainBoard(props: IProps): React.ReactElement {
const [grid, setGrid] = React.useState(calculateGrid(props.gift));
const [ghostGrid, setGhostGrid] = React.useState(zeros([props.gift.width(), props.gift.height()]));
const [pos, setPos] = React.useState([0, 0]);
const [rotation, setRotation] = React.useState(0);
@@ -54,12 +53,10 @@ export function MainBoard(props: IProps): React.ReactElement {
if (!props.gift.canPlace(worldX, worldY, rotation, selectedFragment)) return;
props.gift.place(worldX, worldY, rotation, selectedFragment);
}
setGrid(calculateGrid(props.gift));
}
function clear(): void {
props.gift.clear();
setGrid(zeros([props.gift.width(), props.gift.height()]));
}
function updateSelectedFragment(fragment: Fragment): void {
@@ -92,7 +89,6 @@ export function MainBoard(props: IProps): React.ReactElement {
<Grid
width={props.gift.width()}
height={props.gift.height()}
activeGrid={grid}
ghostGrid={ghostGrid}
gift={props.gift}
enter={(i, j) => moveGhost(i, j, rotation)}