From 110b89079ee04c0e495eeeb390714467f3734a9c Mon Sep 17 00:00:00 2001 From: Jordan Shatford Date: Fri, 13 Oct 2023 11:19:19 +1100 Subject: [PATCH] feat(web): allow getting more results for a search if possible Signed-off-by: Jordan Shatford --- apps/web/src/lib/stores/search.ts | 21 +++++++++++++++++++++ apps/web/src/routes/+page.svelte | 18 ++++++++++++++++-- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/apps/web/src/lib/stores/search.ts b/apps/web/src/lib/stores/search.ts index d6c935eb..e897972e 100644 --- a/apps/web/src/lib/stores/search.ts +++ b/apps/web/src/lib/stores/search.ts @@ -39,9 +39,30 @@ function createSearchStore() { } } + async function getMore() { + update((state) => { + state.loading = true; + return state; + }); + let results: Video[] = []; + try { + results = await SearchService.getNextSearch(); + toast.success('Success', `Found ${results.length} more search results.`); + } catch (err) { + toast.error('Error', 'Failed to get more search results.'); + console.error('Failed to get more search videos ', err); + } + update((state) => { + state.results = [...state.results, ...results]; + state.loading = false; + return state; + }); + } + return { subscribe, get, + getMore, reset: () => set({ term: '', results: [], loading: false }) }; } diff --git a/apps/web/src/routes/+page.svelte b/apps/web/src/routes/+page.svelte index da29568c..7cb76e6c 100644 --- a/apps/web/src/routes/+page.svelte +++ b/apps/web/src/routes/+page.svelte @@ -1,5 +1,5 @@