fix: seed discovery ring from server on initial page load
The ring was only populated from localStorage or during SPA navigation. First visits (empty localStorage) or cross-shop visits (stale ring) left ringProductIds empty, causing the related content sidebar to show only the current product. Now: - On page load, if localStorage ring is empty, fetch from watch JSON - Invalidate stale rings when current product is not in the saved ring
This commit is contained in:
parent
5385e14a29
commit
25d255447e
1 changed files with 27 additions and 1 deletions
|
|
@ -217,6 +217,16 @@
|
|||
var initialId = initialProductEl.getAttribute('data-watch-product-id');
|
||||
currentProductId = initialId;
|
||||
markWatched(initialId);
|
||||
|
||||
// Invalidate stale ring (wrong shop or product removed from ring)
|
||||
if (ringProductIds.length && ringProductIds.indexOf(initialId) === -1) {
|
||||
ringProductIds = [];
|
||||
ringPosition = 0;
|
||||
ringHistory = {};
|
||||
ringLoops = 0;
|
||||
saveRingState();
|
||||
}
|
||||
|
||||
syncRingPosition(initialId);
|
||||
if (initialProductEl.getAttribute('data-watch-is-mod') === '1') {
|
||||
isMod = true;
|
||||
|
|
@ -1827,5 +1837,21 @@
|
|||
rebindToggles();
|
||||
|
||||
renderQueue();
|
||||
preloadNext();
|
||||
|
||||
// Seed ring from server if localStorage is empty (first visit, cache cleared)
|
||||
if (!ringProductIds.length && currentProductId) {
|
||||
fetchWatchData(currentProductId).then(function(data) {
|
||||
if (data.ring && data.ring.length) {
|
||||
ringProductIds = data.ring;
|
||||
syncRingPosition(currentProductId);
|
||||
saveRingState();
|
||||
updateProgressDisplay();
|
||||
}
|
||||
preloadNext();
|
||||
}).catch(function() {
|
||||
preloadNext();
|
||||
});
|
||||
} else {
|
||||
preloadNext();
|
||||
}
|
||||
})();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue