From 83f7daedfa0d6ccebd450e7ce8bac2d2e58346a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleksa=20Siri=C5=A1ki?= <31509435+aleksasiriski@users.noreply.github.com> Date: Wed, 3 Apr 2024 16:25:34 +0200 Subject: [PATCH] fix(loadlazyresults): forgot to change field names --- src/lib/functions/fetchResultsLazily.ts | 56 +++++++++++++++---------- 1 file changed, 33 insertions(+), 23 deletions(-) diff --git a/src/lib/functions/fetchResultsLazily.ts b/src/lib/functions/fetchResultsLazily.ts index 066473ff..3abc3928 100644 --- a/src/lib/functions/fetchResultsLazily.ts +++ b/src/lib/functions/fetchResultsLazily.ts @@ -1,28 +1,38 @@ -import { fetchPublicResultsJSON } from "$lib/functions/fetchPublicResultsJSON"; -import type { ResultType } from "$lib/types/result"; +import { fetchPublicResultsJSON } from '$lib/functions/fetchPublicResultsJSON'; +import type { ResultType } from '$lib/types/result'; -export async function fetchResultsLazily(query: string, start: number, offset: number, pages: number, results: ResultType[], paramsString: string): Promise<[number, ResultType[]]> { - // create URLParams object from string and set start parameter - const params: URLSearchParams = new URLSearchParams(paramsString); - params.set("q", query); - params.set("start", (start + offset).toString()); - params.set("pages", pages.toString()); +export async function fetchResultsLazily( + query: string, + start: number, + offset: number, + pages: number, + results: ResultType[], + paramsString: string +): Promise<[number, ResultType[]]> { + // create URLParams object from string and set start parameter + const params: URLSearchParams = new URLSearchParams(paramsString); + params.set('q', query); + params.set('start', (start + offset).toString()); + params.set('pages', pages.toString()); - // get additional results - let additionalResults: ResultType[]; - try { - additionalResults = await fetchPublicResultsJSON(params); - } catch(err: any) { - throw new Error(`Error fetching additional results: ${err.message}`); - } + // get additional results + let additionalResults: ResultType[]; + try { + additionalResults = await fetchPublicResultsJSON(params); + } catch (err: any) { + throw new Error(`Error fetching additional results: ${err.message}`); + } - // append additional results to combined results while removing duplicates - const combinedResults: ResultType[] = [...results, ...additionalResults.filter((r) => !results.some((result) => result.URL === r.URL))]; + // append additional results to combined results while removing duplicates + const combinedResults: ResultType[] = [ + ...results, + ...additionalResults.filter((r) => !results.some((result) => result.url === r.url)) + ]; - // adjust new results' ranks to continue from the last rank of the existing results - for (let i: number = results.length; i < combinedResults.length; i++) { - combinedResults[i].Rank = i + 1; - } + // adjust new results' ranks to continue from the last rank of the existing results + for (let i: number = results.length; i < combinedResults.length; i++) { + combinedResults[i].rank = i + 1; + } - return [offset+pages, combinedResults]; -} \ No newline at end of file + return [offset + pages, combinedResults]; +}