Improved import security, added browser tests
This commit is contained in:
@@ -9,18 +9,23 @@
|
||||
const ROUTES = ['resume', 'today', 'settings', 'stats', 'details', 'automations', 'non-working'];
|
||||
|
||||
function fromHash() {
|
||||
const h = location.hash.replace(/^#\/?/, '');
|
||||
return ROUTES.includes(h) ? h : null;
|
||||
const [path, query = ''] = location.hash.replace(/^#\/?/, '').split('?');
|
||||
const date = new URLSearchParams(query).get('date');
|
||||
return { route: ROUTES.includes(path) ? path : null,
|
||||
selectedDate: date && /^\d{4}-\d{2}-\d{2}$/.test(date) ? date : '' };
|
||||
}
|
||||
|
||||
export const router = $state({ route: fromHash(), selectedDate: '' });
|
||||
export const router = $state(fromHash());
|
||||
|
||||
window.addEventListener('hashchange', () => {
|
||||
router.route = fromHash();
|
||||
const next = fromHash();
|
||||
router.route = next.route;
|
||||
if (next.selectedDate) router.selectedDate = next.selectedDate;
|
||||
});
|
||||
|
||||
export function go(route) {
|
||||
location.hash = route ? `#/${route}` : '';
|
||||
const date = ['resume', 'details'].includes(route) && router.selectedDate ? `?date=${router.selectedDate}` : '';
|
||||
location.hash = route ? `#/${route}${date}` : '';
|
||||
}
|
||||
|
||||
export function back() {
|
||||
|
||||
Reference in New Issue
Block a user