Skip to content

Commit d418b6a

Browse files
committed
fix: one-time migration from courses table to localStorage on first open
1 parent 69255a0 commit d418b6a

1 file changed

Lines changed: 16 additions & 3 deletions

File tree

frontend/js/app.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -622,16 +622,29 @@ document.addEventListener("alpine:init", () => {
622622
this.subsSelMiddle = [];
623623
this.subsSelRight = [];
624624
this.subsError = "";
625-
// Load current subscription from localStorage (last-saved secret state).
626-
// The ``courses`` table is NOT a valid fallback — it holds every course
627-
// that has ever been processed, not just the currently subscribed ones.
625+
// Load subscription from localStorage (cached secret state).
628626
this.subscribedIds = [];
629627
try {
630628
var cached = JSON.parse(
631629
localStorage.getItem(_LS + "lastSubscribed") || "null"
632630
);
633631
if (Array.isArray(cached)) this.subscribedIds = cached.map(String);
634632
} catch {}
633+
// One-time migration: if the cache is empty, seed it from the courses
634+
// table so the user doesn't start with an empty left column. Save
635+
// immediately so future loads read from localStorage without the DB
636+
// fallback (the courses table grows over time and isn't the secret).
637+
if (!this.subscribedIds.length) {
638+
this.subscribedIds = ICS.db.getSubscribedCourseIds().map(String);
639+
if (this.subscribedIds.length) {
640+
try {
641+
localStorage.setItem(
642+
_LS + "lastSubscribed",
643+
JSON.stringify(this.subscribedIds),
644+
);
645+
} catch {}
646+
}
647+
}
635648
this.rebuildSubsFiltered();
636649
this.navigate("subscriptions");
637650
},

0 commit comments

Comments
 (0)