Skip to content
This repository has been archived by the owner on Sep 12, 2024. It is now read-only.

Commit

Permalink
Fixes issue #419: Improved by adding working params and fixed when th…
Browse files Browse the repository at this point in the history
…e filter when switch to github or eddie
  • Loading branch information
D-01576 committed Sep 1, 2024
1 parent e1b62b2 commit 3a3a74c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 19 additions & 1 deletion src/routes/app/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -21,7 +22,8 @@
if (!checked) checked = false;
let selectedLabels: string[] = [];
let selectedLabels: string[] = para();
let misss = false;
$: issues = createInfiniteQuery({
queryKey: ['issues', { global: checked }],
Expand All @@ -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) => {
Expand Down
19 changes: 19 additions & 0 deletions src/routes/app/getparam.ts
Original file line number Diff line number Diff line change
@@ -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 [];
}

0 comments on commit 3a3a74c

Please sign in to comment.