diff --git a/package-lock.json b/package-lock.json index 28efc91..fb6c7d1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "issue-finder", - "version": "2.19.5", + "version": "2.19.12", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "issue-finder", - "version": "2.19.5", + "version": "2.19.12", "license": "MIT", "dependencies": { "node-fetch": "^3.3.1", 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..f1d8565 --- /dev/null +++ b/src/routes/app/getparam.ts @@ -0,0 +1,19 @@ +// 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 []; +}