Skip to content

Commit

Permalink
Allow params via page load and history
Browse files Browse the repository at this point in the history
  • Loading branch information
Kractero committed Oct 15, 2023
1 parent 13ec2d2 commit 16d8078
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/lib/helpers/util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const pushHistory = (params: string) => {
const currentURL = window.location.href;
const baseURL = currentURL.split('?')[0];
window.history.pushState(null, '', `${baseURL}${params}`);
}
18 changes: 18 additions & 0 deletions src/lib/loadStorage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export function loadStorage(key: string) {
switch (key) {
case 'stationJDJ':
return {
common: Number(localStorage.getItem(`${key}Common`)) || 0.5,
uncommon: Number(localStorage.getItem(`${key}Uncommon`)) || 1,
rare: Number(localStorage.getItem(`${key}Rare`)) || 1,
'ultra-rare': Number(localStorage.getItem(`${key}UltraRare`)) || 1,
epic: Number(localStorage.getItem(`${key}Epic`)) || 1
};
case 'stationROCDays':
return Number(localStorage.getItem(key)) || 30;
case 'stationROCTop':
return Number(localStorage.getItem(`${key}`)) || 100;
default:
return localStorage.getItem(key) || '';
}
}
12 changes: 12 additions & 0 deletions src/routes/tools/+layout.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type { LayoutServerLoad } from './$types';

export const load: LayoutServerLoad = async ( { url }) => {
const searchParams = url.searchParams;
const parameters: {[key: string]: string} = {};
for (const [key, value] of searchParams) {
parameters[key] = value;
}
return {
"parameters": parameters
};
};

0 comments on commit 16d8078

Please sign in to comment.