Move direct DOM outside of useEffect
Signed-off-by: James Ketrenos <james_eikona@ketrenos.com>
This commit is contained in:
parent
dac755cad0
commit
d7c3aa2668
@ -528,11 +528,7 @@ const Board = () => {
|
|||||||
borderOrder, borders, pipOrder, pips, tileOrder, tiles
|
borderOrder, borders, pipOrder, pips, tileOrder, tiles
|
||||||
]);
|
]);
|
||||||
|
|
||||||
useEffect(() => {
|
if (turn) {
|
||||||
if (!turn) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let nodes = document.querySelectorAll('.Active');
|
let nodes = document.querySelectorAll('.Active');
|
||||||
for (let i = 0; i < nodes.length; i++) {
|
for (let i = 0; i < nodes.length; i++) {
|
||||||
nodes[i].classList.remove('Active');
|
nodes[i].classList.remove('Active');
|
||||||
@ -550,13 +546,9 @@ const Board = () => {
|
|||||||
nodes[i].classList.add('Active');
|
nodes[i].classList.add('Active');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [ turn ]);
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!placements) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (placements) {
|
||||||
/* Set color and type based on placement data from the server */
|
/* Set color and type based on placement data from the server */
|
||||||
placements.corners.forEach((corner, index) => {
|
placements.corners.forEach((corner, index) => {
|
||||||
const el = document.querySelector(`.Corner[data-index="${index}"]`);
|
const el = document.querySelector(`.Corner[data-index="${index}"]`);
|
||||||
@ -637,25 +629,23 @@ const Board = () => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [ placements, turn]);
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
let nodes = document.querySelectorAll(`.Pip.Robber`);
|
||||||
let nodes = document.querySelectorAll(`.Pip.Robber`);
|
for (let i = 0; i < nodes.length; i++) {
|
||||||
for (let i = 0; i < nodes.length; i++) {
|
nodes[i].classList.remove('Robber');
|
||||||
nodes[i].classList.remove('Robber');
|
[ 'Robert', 'Roberta', 'Velocirobber' ].forEach(robberName =>
|
||||||
[ 'Robert', 'Roberta', 'Velocirobber' ].forEach(robberName =>
|
nodes[i].classList.remove(robberName)
|
||||||
nodes[i].classList.remove(robberName)
|
);
|
||||||
);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (robber !== undefined) {
|
if (robber !== undefined) {
|
||||||
const el = document.querySelector(`.Pip[data-index="${robber}"]`);
|
const el = document.querySelector(`.Pip[data-index="${robber}"]`);
|
||||||
if (el) {
|
if (el) {
|
||||||
el.classList.add('Robber');
|
el.classList.add('Robber');
|
||||||
el.classList.add(robberName);
|
el.classList.add(robberName);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}, [ robber, robberName ]);
|
}
|
||||||
|
|
||||||
const canAction = (action) => {
|
const canAction = (action) => {
|
||||||
return (turn && Array.isArray(turn.actions) && turn.actions.indexOf(action) !== -1);
|
return (turn && Array.isArray(turn.actions) && turn.actions.indexOf(action) !== -1);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user