Skip to content

Commit

Permalink
RealMAX - Improve pave navigation prefetching
Browse files Browse the repository at this point in the history
  • Loading branch information
Inrixia committed Jan 30, 2025
1 parent 685901c commit 934e71c
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions plugins/_lib/Caches/MediaItemCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import getPlaybackControl from "../getPlaybackControl";

import { libTrace } from "../trace";

let currentPage: string | null = null;

export type MediaItem = TrackItem | VideoItem;
export class MediaItemCache {
private static readonly _cache: Record<ItemId, MediaItem> = {};
Expand Down Expand Up @@ -37,8 +39,7 @@ export class MediaItemCache {
}

if (this._cache[itemId] === undefined) {
const currentPage = window.location.pathname;

if (currentPage === null) currentPage = window.location.pathname;
const loadedTrack = await interceptPromise(() => neptune.actions.router.replace(<any>`/track/${itemId}`), ["page/IS_DONE_LOADING"], [])
.then(() => true)
.catch(libTrace.warn.withContext(`TrackItemCache.ensure failed to load track ${itemId}`));
Expand All @@ -48,11 +49,15 @@ export class MediaItemCache {
libTrace.warn.withContext(`TrackItemCache.ensure failed to load video ${itemId}`)
);
}
neptune.actions.router.replace(<any>currentPage);

const mediaItems: Record<number, TidalMediaItem> = store.getState().content.mediaItems;
const trackItem = mediaItems[+itemId]?.item;
this._cache[itemId] = trackItem;

setTimeout(() => {
currentPage = null;
neptune.actions.router.replace(<any>currentPage);
});
}

return this._cache[itemId];
Expand Down

0 comments on commit 934e71c

Please sign in to comment.