Fix for offline mode
This commit is contained in:
+13
-1
@@ -36,7 +36,10 @@ function createHomeStore() {
|
||||
try {
|
||||
const repo = auth.getRepository();
|
||||
|
||||
const [resume, nextUp, latest, recentAudio, resumeMovies] = await Promise.all([
|
||||
// Use allSettled so one failing section (e.g. Next Up is online-only and
|
||||
// rejects offline) doesn't wipe out the whole homepage. Each section falls
|
||||
// back to an empty list; cached sections (resume/latest/recent) still show.
|
||||
const settled = await Promise.allSettled([
|
||||
repo.getResumeItems(undefined, 12),
|
||||
repo.getNextUpEpisodes(undefined, 12),
|
||||
repo.getLatestItems("", 16),
|
||||
@@ -44,6 +47,15 @@ function createHomeStore() {
|
||||
repo.getResumeMovies(12),
|
||||
]);
|
||||
|
||||
const valueOr = <T>(i: number, fallback: T): T =>
|
||||
settled[i].status === "fulfilled" ? (settled[i] as PromiseFulfilledResult<T>).value : fallback;
|
||||
|
||||
const resume = valueOr(0, [] as typeof initialState.resumeItems);
|
||||
const nextUp = valueOr(1, [] as typeof initialState.nextUpItems);
|
||||
const latest = valueOr(2, [] as typeof initialState.latestItems);
|
||||
const recentAudio = valueOr(3, [] as typeof initialState.recentlyPlayedAudio);
|
||||
const resumeMovies = valueOr(4, [] as typeof initialState.resumeMovies);
|
||||
|
||||
// Use resume items or latest as hero items
|
||||
const hero = resume.length >= 3 ? resume.slice(0, 5) : latest.slice(0, 5);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user