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

Fixes issue #419: Improve app by adding working params and fix the fi… #421

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
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
20 changes: 20 additions & 0 deletions src/routes/app/getparam.ts
Original file line number Diff line number Diff line change
@@ -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 [];
}

Loading