Robots are currently drawn on the field according to a set of fixed constraints set in RobotElement in FieldElements.tsx. The robots should instead reflect the robot assigned to their associated path.
- The robot should probably be passed to RobotElement via props from FieldElements in order to prevent issues with iinvalid props/early returns.
- Because FieldElements handles multiple paths which could be invalid, and due to the rules of hooks, useAppSelector cannot be called within the path loop. Instead, you could implement a solution similar to AppTree's calls to getPathNode, where the dictionary is selected first and then the dictionary is accessed inside the actual loop, or you could apply logic like:
const robots = useAppSelector(state => paths?.map(path => selectRobotByValidId(state, path.robotId));
The ? in paths?.map handles the case where paths is undefined; if it is, .map is skipped, and the function returns undefined. FieldElements should then return null if either Paths or Robots is undefined.
Robots are currently drawn on the field according to a set of fixed constraints set in RobotElement in FieldElements.tsx. The robots should instead reflect the robot assigned to their associated path.
const robots = useAppSelector(state => paths?.map(path => selectRobotByValidId(state, path.robotId));The ? in paths?.map handles the case where paths is undefined; if it is, .map is skipped, and the function returns undefined. FieldElements should then return null if either Paths or Robots is undefined.