From fc02f12ad39f24d5370ffc6bf2978e03c829d0d8 Mon Sep 17 00:00:00 2001 From: Siraj01576 Date: Sun, 1 Sep 2024 17:11:25 +0500 Subject: [PATCH] Fixes issue #419: Improve app by adding working params and fix the filter when switch to github or eddie --- src/routes/app/+page.svelte | 20 +++++++++++++++++++- src/routes/app/getparam.ts | 20 ++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 src/routes/app/getparam.ts diff --git a/src/routes/app/+page.svelte b/src/routes/app/+page.svelte index 91fed16..e179ade 100644 --- a/src/routes/app/+page.svelte +++ b/src/routes/app/+page.svelte @@ -13,6 +13,7 @@ import Filter from '$lib/components/filter.svelte'; import Search from '$lib/components/search.svelte'; import Modal from '$lib/components/modal.svelte'; + import { para } from './getparam'; export let data: PageData; let { checked } = data; @@ -21,7 +22,8 @@ if (!checked) checked = false; - let selectedLabels: string[] = []; + let selectedLabels: string[] = para(); + let misss = false; $: issues = createInfiniteQuery({ queryKey: ['issues', { global: checked }], @@ -39,15 +41,31 @@ const onChangeHandler = async () => { if (checked) { await goto('?global=true', { noScroll: true }); + selectedLabels = []; return; } await goto('?global=false', { noScroll: true }); + selectedLabels = []; }; const onFilterClear = () => { selectedLabels = []; }; + $: { + if (typeof window !== 'undefined' && misss) { + const labelsParam = selectedLabels.length > 0 ? selectedLabels.join(',') : ''; + const currentQuery = new URLSearchParams(window.location.search); + if (labelsParam) { + currentQuery.set('filter', labelsParam); + } else { + currentQuery.delete('filter'); + } + history.replaceState(null, '', `?${currentQuery.toString()}`); + } + misss = true; + } + $: filteredResponse = $issues.data?.pages?.flatMap((page) => { return page.edges .filter((edge) => { diff --git a/src/routes/app/getparam.ts b/src/routes/app/getparam.ts new file mode 100644 index 0000000..757abc6 --- /dev/null +++ b/src/routes/app/getparam.ts @@ -0,0 +1,20 @@ +// getparam.ts +export function para(): string[] { + if (typeof window !== 'undefined') { + // Extract query parameters from the URL + const urlParams = new URLSearchParams(window.location.search); + const filter = urlParams.get('filter'); + + if (filter) { + // Decode URL-encoded string + const decodedFilter = decodeURIComponent(filter); + const arr = decodedFilter.split(','); + console.log(arr); + return arr; + } + } + + // Return an empty array if no valid parameters are found + return []; + } + \ No newline at end of file