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

Fixes issue #419: Improved by adding working params and fixed when th… #420

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this file, since you didn't add a new package

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How to do

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opened a new pull request

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 [];
}
Loading