Skip to content

Commit

Permalink
stores/constellations.ts: fix history navigation past the first page!
Browse files Browse the repository at this point in the history
Oops, we made it so that the timeline never actually refilled itself
as we navigated forward! So we'd get to the end of page 1 and run out
of scenes.

Also fix a bug with managing the pagination.
  • Loading branch information
pkgw committed Nov 18, 2023
1 parent 64fe12b commit fc6d6ad
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions stores/constellations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,16 @@ export const useConstellationsStore = defineStore("wwt-constellations", () => {
const page = nextNeededPage;
const result = await getNextScenes($backendCall, page);

// Once again, we must make sure that the navigation situation hasn't
// change on us while we were waiting for getNextScenes() to resolve.
if (nextNeededPage === page && !needToChangeSceneSource(navigationMode.value)) {
for (const scene of result.results) {
knownScenes.value.set(scene.id, scene);
futureScenes.value.push(scene);
}
}

nextNeededPage += 1;
nextNeededPage += 1;
}
}
}

Expand Down Expand Up @@ -202,6 +204,10 @@ export const useConstellationsStore = defineStore("wwt-constellations", () => {
return;
}

// Make sure that we always have forward coverage past the target, so that
// the "next" button remains available if it should!
await ensureForwardCoverage(count + 1);

// These two variables are just containers so that we don't need to update ref values more than once
let scene: GetSceneResponseT | undefined = undefined;
let node: Yallist.Node<GetSceneResponseT> | undefined = undefined;
Expand All @@ -215,7 +221,9 @@ export const useConstellationsStore = defineStore("wwt-constellations", () => {
node = next;
} else {
if (futureScenes.value.length === 0) {
await ensureForwardCoverage(count); // Should this be larger?
// Just in case ... once again, ensure that we go past the target to
// be able to properly make the "next" button clickable or not.
await ensureForwardCoverage(count + 1);
}

scene = futureScenes.value.shift();
Expand Down

0 comments on commit fc6d6ad

Please sign in to comment.