From a9a4950c1bb200e7696ededa62e4845aa7d2ff17 Mon Sep 17 00:00:00 2001 From: luke-hagar-sp <98849695+luke-hagar-sp@users.noreply.github.com> Date: Wed, 17 Jan 2024 13:05:35 -0600 Subject: [PATCH] Type changes and coercions, spelling, @ts, and @eslint fixes --- Sveltekit-App/src/lib/Utils.ts | 58 +++++++++++-- Sveltekit-App/src/routes/+page.server.ts | 11 ++- .../src/routes/callback/+page.server.ts | 5 +- .../src/routes/callback/loadinglist.ts | 1 + Sveltekit-App/src/routes/home/+error.svelte | 29 ++++++- .../routes/home/identities/+page.server.ts | 5 +- .../src/routes/home/identities/+page.svelte | 87 ++++++++++--------- .../src/routes/home/sources/+page.svelte | 7 -- 8 files changed, 136 insertions(+), 67 deletions(-) diff --git a/Sveltekit-App/src/lib/Utils.ts b/Sveltekit-App/src/lib/Utils.ts index 6b2e831..3010b12 100644 --- a/Sveltekit-App/src/lib/Utils.ts +++ b/Sveltekit-App/src/lib/Utils.ts @@ -1,12 +1,10 @@ +import { goto } from '$app/navigation'; + export function formatDate(date: string | null | undefined) { if (!date) return 'N/A'; return new Date(date).toLocaleString(); } -export function getOffset(url: URL) { - return url.searchParams.get('offset') || '0'; -} - export function getLimit(url: URL) { return url.searchParams.get('limit') || '10'; } @@ -25,10 +23,60 @@ export function getPage(url: URL) { export function getPaginationParams(url: URL) { return { - offset: getOffset(url), limit: getLimit(url), page: getPage(url), filters: getFilters(url), sorters: getSorters(url) }; } + +type PaginationParams = { + limit: string; + page: string; + filters: string; + sorters: string; +}; + +export function createOnPageChange(params: PaginationParams, path: string) { + return function onPageChange(e: CustomEvent): void { + const urlParams = new URLSearchParams(); + urlParams.set('page', e.detail); + urlParams.set('limit', params.limit); + urlParams.set('sorters', params.sorters); + urlParams.set('filters', params.filters); + + console.log(`${path}?${urlParams.toString()}`); + + goto(`${path}?${urlParams.toString()}`); + }; +} + +export function createOnAmountChange(params: PaginationParams, path: string) { + return function onAmountChange(e: CustomEvent): void { + const urlParams = new URLSearchParams(); + urlParams.set('page', params.page); + urlParams.set('limit', e.detail); + urlParams.set('sorters', params.sorters); + urlParams.set('filters', params.filters); + + console.log(`${path}?${urlParams.toString()}`); + + goto(`${path}?${urlParams.toString()}`); + }; +} + +export function createOnGo(params: PaginationParams, path: string) { + return function onGo(e: KeyboardEvent | MouseEvent): void { + if (e.type !== 'click' && (e as KeyboardEvent).key !== 'Enter') return; + + const urlParams = new URLSearchParams(); + urlParams.set('page', params.page); + urlParams.set('limit', params.limit); + urlParams.set('sorters', params.sorters); + urlParams.set('filters', params.filters); + + console.log(`${path}?${urlParams.toString()}`); + + goto(`${path}?${urlParams.toString()}`); + }; +} diff --git a/Sveltekit-App/src/routes/+page.server.ts b/Sveltekit-App/src/routes/+page.server.ts index 195e54e..4829b0f 100644 --- a/Sveltekit-App/src/routes/+page.server.ts +++ b/Sveltekit-App/src/routes/+page.server.ts @@ -3,14 +3,17 @@ import type { Actions } from './$types'; import { generateAuthLink } from '$lib/utils/oauth'; export const actions = { - default: async ({ cookies, request, url }) => { + default: async ({ cookies, request }) => { const data = await request.formData(); const baseUrl = data.get('baseUrl'); const tenant = data.get('tenant'); - const domain = data.get('domain'); const tenantUrl = data.get('tenantUrl'); + if (!baseUrl || !tenantUrl) { + throw redirect(302, '/login'); + } + const sessionString = cookies.get('idnSession'); if (sessionString) { @@ -26,6 +29,6 @@ export const actions = { } cookies.set('session', JSON.stringify({ baseUrl, tenantUrl })); - throw redirect(302, generateAuthLink(tenantUrl)); - }, + throw redirect(302, generateAuthLink(tenantUrl.toString())); + } } satisfies Actions; diff --git a/Sveltekit-App/src/routes/callback/+page.server.ts b/Sveltekit-App/src/routes/callback/+page.server.ts index 3ba81d6..e3193d0 100644 --- a/Sveltekit-App/src/routes/callback/+page.server.ts +++ b/Sveltekit-App/src/routes/callback/+page.server.ts @@ -8,12 +8,14 @@ export const load: PageServerLoad = async ({ url, cookies }) => { const code = url.searchParams.get('code'); const sessionString = cookies.get('session'); - let session: any = null; + let session: { baseUrl: string; tenantUrl: string } | undefined = undefined; if (sessionString) { session = JSON.parse(cookies.get('session')!); } + if (session == undefined) throw error(500, 'No Session Found'); + if (!code) throw error(500, 'No Authorization Code Provided'); const response = await axios .post( @@ -25,6 +27,7 @@ export const load: PageServerLoad = async ({ url, cookies }) => { console.log(err.response.data); console.log(err.response.status); console.log(err.response.headers); + // @ts-expect-error session is null checked above throw redirect(302, generateAuthLink(session.tenantUrl)); } else if (err.request) { // The request was made but no response was received diff --git a/Sveltekit-App/src/routes/callback/loadinglist.ts b/Sveltekit-App/src/routes/callback/loadinglist.ts index 9b8d4c8..6f05897 100644 --- a/Sveltekit-App/src/routes/callback/loadinglist.ts +++ b/Sveltekit-App/src/routes/callback/loadinglist.ts @@ -233,4 +233,5 @@ export const counterList = [ "Don't panic... AHHHHH!", 'Ensuring Gnomes are still short.', 'Baking ice cream...' + // eslint-disable-next-line @typescript-eslint/no-unused-vars ].sort((a, b) => 0.5 - Math.random()); diff --git a/Sveltekit-App/src/routes/home/+error.svelte b/Sveltekit-App/src/routes/home/+error.svelte index c180e51..37ad9ea 100644 --- a/Sveltekit-App/src/routes/home/+error.svelte +++ b/Sveltekit-App/src/routes/home/+error.svelte @@ -5,16 +5,37 @@
- WHOOPS!
Seems like an error occurred.
If you believe this is a bug please submit
- an issue on
+
+ WHOOPS! an error occurred.
If you believe this is a bug please submit an issue on
GitHub
+ GitHub
+
Message:
{$page.error.message}
These links may be helpful:
+Context