Improvements to search store

This commit is contained in:
WardPearce
2025-06-04 15:50:36 +12:00
parent 1f71469276
commit ce7c94df18
3 changed files with 9 additions and 7 deletions
+1 -1
View File
@@ -118,6 +118,6 @@ export const feedCacheStore: Writable<{
[key: string]: (VideoBase | Video | PlaylistPageVideo)[];
}> = writable({});
export const searchCacheStore: Writable<{
[searchType: string]: (Channel | Video | Playlist | HashTag)[];
[searchTypeAndQuery: string]: (Channel | Video | Playlist | HashTag)[];
}> = writable({});
export const feedLastItemId: Writable<string | undefined> = writable(undefined);
@@ -27,7 +27,7 @@
async function changeType(type: 'playlist' | 'all' | 'video' | 'channel') {
currentType = type;
currentPage = 1;
searchCacheStore.set({ [type]: await getSearch(data.slug, { type: type }) });
searchCacheStore.set({ [data.searchStoreId]: await getSearch(data.slug, { type: type }) });
}
async function loadMore(event: InfiniteEvent) {
@@ -41,7 +41,7 @@
event.detail.complete();
} else {
searchCacheStore.set({
[currentType]: [...($searchCacheStore[currentType] ?? []), ...newSearch]
[data.searchStoreId]: [...($searchCacheStore[data.searchStoreId] ?? []), ...newSearch]
});
event.detail.loaded();
}
@@ -13,24 +13,26 @@ export async function load({ params, url }) {
type = 'all';
}
const search = get(searchCacheStore).all;
const searchStoreId = type + params.slug;
const search = get(searchCacheStore)[searchStoreId];
if (!search) {
try {
searchCacheStore.set({ [type]: await getSearch(params.slug, { type: type }) });
searchCacheStore.set({ [searchStoreId]: await getSearch(params.slug, { type: type }) });
} catch (errorMessage: any) {
error(500, errorMessage);
}
} else {
getSearch(params.slug, { type: type }).then((newSearch) => {
searchCacheStore.set({
[type]: [...new Set([...newSearch, ...search])]
[searchStoreId]: [...new Set([...newSearch, ...search])]
});
});
}
return {
slug: params.slug,
searchType: type
searchType: type,
searchStoreId: searchStoreId
};
}