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

feat: improvements to save state #1135

Merged
merged 1 commit into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions apps/antalmanac/src/stores/AppStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ class AppStore extends EventEmitter {
this.unsavedChanges = false;

await actionTypesStore.loadScheduleFromLocalSave();
this.schedule.clearPreviousStates();

this.emit('addedCoursesChange');
this.emit('customEventsChange');
Expand Down Expand Up @@ -430,6 +431,8 @@ class AppStore extends EventEmitter {

termsInSchedule = (term: string) =>
new Set([term, ...this.schedule.getCurrentCourses().map((course) => course.term)]);

getPreviousStates = () => this.schedule.getPreviousStates();
}

const store = new AppStore();
Expand Down
19 changes: 19 additions & 0 deletions apps/antalmanac/src/stores/Schedules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,20 @@ export class Schedules {
return calendarizeFinals(this.getCurrentCourses());
}

/**
* Getter for previous states
*/
getPreviousStates() {
return this.previousStates;
}

/**
* Clears previous states
*/
clearPreviousStates() {
this.previousStates = [];
}

/**
* Appends a copy of the current schedule to previous states to revert to
* Previous states are capped to 50
Expand All @@ -466,6 +480,11 @@ export class Schedules {
* All actions that call `addUndoState()` can be reverted.
*/
revertState() {
// prevent the user from undoing to an empty state
if (this.previousStates.length <= 1) {
return;
}

const state = this.previousStates.pop();
if (state !== undefined) {
this.schedules = state.schedules;
Expand Down
Loading