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

Undo/redo actions support #118

Closed
wants to merge 5 commits into from
Closed

Undo/redo actions support #118

wants to merge 5 commits into from

Conversation

mapmeld
Copy link
Member

@mapmeld mapmeld commented Oct 7, 2024

Description

Screenshot 2024-10-06 at 11 39 57 PM
  • There is an undo stack (recentZoneAssignments, to reverse the last mousedown -> mouseup draw action.
  • Once you undo an action, the "Redo" button is enabled and it reapplies draw actions
  • Because undo/redo use setFeatureState and setZoneAssignments, they update the map, chart, and serverside doc
  • If you undo and then draw new districts, the future Redo-able actions are erased
  • A new flag prevents Undo/Redo from adding its actions to the undo stack

Remaining issues

  • Better integration into drawing UI
  • Object.keys(..).forEach(...) was odd syntax to re-apply zone draws, could be refactored & consider issues with debouncing if we update several zones at once
  • Limit the number of actions in the undo stack (did 7) before erasing the first actions
  • Doesn't work with changes to zones from the original map load, because those are not in state.zoneAssignments

@mapmeld mapmeld changed the title Draft PR for undo/redo Draft PR for undo/redo [#69] Oct 7, 2024
@mapmeld mapmeld changed the title Draft PR for undo/redo [#69] Draft PR for undo/redo Oct 7, 2024
@mapmeld mapmeld changed the title Draft PR for undo/redo Undo/redo actions support Oct 10, 2024
@mapmeld
Copy link
Member Author

mapmeld commented Oct 10, 2024

I set a limit of 7 undo-able actions, and removed a call to resetZoneAssignments() which cleared the assignments which had been loaded from a saved map.

@nofurtherinformation
Copy link
Collaborator

Hey @mapmeld! What would you think about using this undo/redo middleware for zustand? I think this will be ultimately less code to maintain, and with the changes coming down in from Shattering the map rendering happens as subscriptions/side-effects of state changes which should make the app and map state easier to observe

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.

2 participants