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

Implement undo/redo with zundo #157

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

Implement undo/redo with zundo #157

wants to merge 11 commits into from

Conversation

mapmeld
Copy link
Member

@mapmeld mapmeld commented Oct 28, 2024

Testing if we can replace #118 with the zundo plugin , and whether GitHub Actions will produce a test build for this

  • Adds undo/redo buttons to UI
  • Wraps mapState in temporal(...)

Issues:
onSave still needs to update MapBox and the server

@mapmeld
Copy link
Member Author

mapmeld commented Nov 11, 2024

This is working better now (possibly to undo/redo paint actions and those get reflected on the map). I think that I need to change the equality function to make sure it doesn't save intermediate / invisible changes

@mapmeld
Copy link
Member Author

mapmeld commented Nov 11, 2024

ok, interestingly by the undo/redo works pretty well by default after a block has a paint or eraser (null) value attached to it. Then actions after that can be undone. Will revisit

@mapmeld mapmeld changed the title Test zundo build Implement undo/redo with zundo Nov 11, 2024
@nofurtherinformation
Copy link
Collaborator

There is an optimization that checks the previous state before changing the feature state, but this is producing some unexpected behavior. For now, I'd recommend removing this and just have all the zone assignments assigned each time.

id && !isInitialRender && previousZoneAssignments?.get(id) === zoneAssignments.get(id);

Also as a heads up there will be some substantial merge conflicts coming in from main!

@nofurtherinformation
Copy link
Collaborator

Just wanted to flag some additional complexity coming down the pipeline for this PR. With breaking (shattering) and healing (unshattering) we may need to track shatter IDs or shatter mappings in the temporal state. Undo and redo break/heal may get a bit tricky.

I'm thinking the most minimal way to handle this could be:

  • If parent shatter ID removed - heal parent
  • If parent shatter ID added - break parent

A pitfall here is going to be if on heal/break there is a new zone assignment created, if that would break the previous undo/redo event chain. I think the way handleShatter and processHealParentsQueue are set up does the whole zoneAssignments change in one go (remove parent and add children, remove children and add parent) but we may need to do some light refactors to clean up edge cases

@mapmeld
Copy link
Member Author

mapmeld commented Nov 12, 2024

I agree this should be paused especially since I don't know enough yet about shattering to say anything informed on implementing that

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