Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix hovers and fix move unit duplicating state #72

Merged
merged 1 commit into from
Jul 11, 2020
Merged

Conversation

zemiret
Copy link
Owner

@zemiret zemiret commented Jul 11, 2020

No description provided.

for i, existing := range state.UnitsPlacement {
if existing.UnitID == placement.UnitID {
moved = true
state.UnitsPlacement[i] = placement
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see what has changed here. The outcome should be the same (?)

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope. There was a bug.

  1. Place unit1 on the gameboard (x = 1, y = 1)
  2. Place unit2 on the gameboard (x = 5, y = 5)
  3. With unit2 still selected, place it on (1, 1)

Then I expect the unitsPlacement state to be

unit2 x=1, y=1

But it was:

unit2 x=1, y=1
unit2 x=1, y=1

It's easy to see that the previous code never removed anything from the gameboard.
But in this case you had 2 units on the gameboard, and when you moved the one onto the other, the other should disappear, and be replaced.

@@ -20,16 +20,14 @@ const BoardUnit: React.FunctionComponent<Props> = ({ unit }: Props) => {
onMouseEnter={() => setHover(true)}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need this if the trigger has been set to hover?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, yes! It does not really matter what the trigger is, I believe it's covered by some other element.

@@ -11,6 +10,7 @@ interface Props {

const BoardUnit: React.FunctionComponent<Props> = ({ unit }: Props) => {
const [hover, setHover] = useState<boolean>(false);
const [unitId] = useState<string>(unit.id);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you elaborate how these changes fix the hover being broken?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem was that

  1. There is a unit with id=1 on board, and so with element id #unit-1
  2. I change units on board
  3. The popover is trying to open itself but it has not yet gotten the new state (so it still thinks that it should show itself for the old id), but the DOM is already updated, so #unit-1 is not present there

When you change this to be the state, the component will re-render in proper order. So first, it gets the new state (from redux), than it changes its internal state, and then it updates itself.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This gave me a clue: reactstrap/reactstrap#773

@zemiret zemiret merged commit 80a15cb into master Jul 11, 2020
@maciekmm maciekmm deleted the bugfix/hovers branch July 15, 2020 17:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants