Skip to content

Commit

Permalink
Undoing import leads to wrong client state (#642)
Browse files Browse the repository at this point in the history
  • Loading branch information
sorenjohanson authored Dec 26, 2024
1 parent 8011a53 commit 023c0e4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
9 changes: 9 additions & 0 deletions teammapper-frontend/mmp/src/map/handlers/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export default class History {
}
Log.error('There was an error importing the map; changes have been rolled back.')
} else {
this.clearHistory()
this.save()
if (notifyWithEvent) this.map.events.call(Event.create, this.map.dom, { previousMap: previousData })
}
Expand Down Expand Up @@ -154,6 +155,14 @@ export default class History {
this.index++
}

/**
* Clears the history of the map
*/
public clearHistory = () => {
this.snapshots = []
this.index = -1
}

/**
* Return all history of map with all snapshots.
* @returns {MapSnapshot[]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
<button
(click)="mmpService.undo()"
[title]="'TOOLTIPS.UNDO_MAP' | translate"
[disabled]="editDisabled"
[disabled]="editDisabled || !canUndoRedo"
color="primary"
mat-icon-button>
<mat-icon>undo</mat-icon>
Expand All @@ -120,7 +120,7 @@
<button
(click)="mmpService.redo()"
[title]="'TOOLTIPS.REDO_MAP' | translate"
[disabled]="editDisabled"
[disabled]="editDisabled || !canUndoRedo"
color="primary"
mat-icon-button>
<mat-icon>redo</mat-icon>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ export class ToolbarComponent {
}
}

get canUndoRedo() {
if (this.mmpService && typeof this.mmpService.history === 'function') {
const history = this.mmpService.history();
return history?.snapshots?.length > 1;
}
return false;
}

public async share() {
this.dialogService.openShareDialog();
}
Expand Down

0 comments on commit 023c0e4

Please sign in to comment.