State used in trending and home page

This commit is contained in:
WardPearce
2025-05-31 15:38:46 +12:00
parent 48396bda84
commit f13480fabb
3 changed files with 33 additions and 16 deletions
+2 -2
View File
@@ -1,12 +1,12 @@
{
"name": "Materialious",
"version": "1.8.7",
"version": "1.8.8",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "Materialious",
"version": "1.8.7",
"version": "1.8.8",
"license": "MIT",
"dependencies": {
"@capacitor-community/electron": "^5.0.0",
+17 -8
View File
@@ -1,19 +1,28 @@
import { getPopular } from '$lib/api/index';
import { feedCacheStore } from '$lib/store';
import { error } from '@sveltejs/kit';
import { get } from 'svelte/store';
export async function load() {
let popular = undefined;
let popular = get(feedCacheStore).popular;
let popularDisabled: boolean = false;
try {
popular = await getPopular();
} catch (errorMessage: any) {
if (errorMessage.toString() === 'Error: Administrator has disabled this endpoint.') {
popularDisabled = true;
} else {
error(500, errorMessage);
if (!popular) {
try {
popular = await getPopular();
} catch (errorMessage: any) {
if (errorMessage.toString() === 'Error: Administrator has disabled this endpoint.') {
popularDisabled = true;
} else {
error(500, errorMessage);
}
}
feedCacheStore.set({ popular });
} else {
getPopular().then((newPopular) => feedCacheStore.set({ popular: newPopular }));
}
return {
popular: popular,
popularDisabled: popularDisabled
@@ -1,13 +1,21 @@
import { getTrending } from '$lib/api/index';
import type { Video } from '$lib/api/model';
import { feedCacheStore } from '$lib/store';
import { error } from '@sveltejs/kit';
import { get } from 'svelte/store';
export async function load() {
let trending: Video[];
try {
trending = await getTrending();
} catch (errorMessage: any) {
error(500, errorMessage);
let trending = get(feedCacheStore).trending;
if (!trending) {
try {
trending = await getTrending();
} catch (errorMessage: any) {
error(500, errorMessage);
}
feedCacheStore.set({ trending });
} else {
getTrending().then((newTrending) => feedCacheStore.set({ trending: newTrending }));
}
return { trending: trending };