From d49f4b2c386ecb830af4d469304f312583191701 Mon Sep 17 00:00:00 2001 From: OllyNicholass Date: Tue, 29 Oct 2024 21:46:52 +0000 Subject: [PATCH] refactor(#35): iNdEnTaTiOn --- package.json | 2 +- src/lib/components/Dropdown.svelte | 2 +- src/lib/components/SignOut.svelte | 10 ++-- src/lib/components/navigation/NavLink.svelte | 17 +++--- .../navigation/NavLinkParent.svelte | 5 +- src/lib/components/navigation/NavLinks.svelte | 60 +++++++++---------- src/lib/utils/supabase/auth.ts | 8 +-- 7 files changed, 49 insertions(+), 55 deletions(-) diff --git a/package.json b/package.json index d38aa0c..3893bae 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "dev": "vite dev", "build": "vite build", "preview": "vite preview", - "stripe": "stripe listen --forward-to localhost:5173/api/webhook/stripe", + "stripe": "stripe listen --forward-to localhost:5173/api/webhook/stripe", "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json", "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch", "lint": "prettier --check . && eslint .", diff --git a/src/lib/components/Dropdown.svelte b/src/lib/components/Dropdown.svelte index f96e598..c4a7655 100644 --- a/src/lib/components/Dropdown.svelte +++ b/src/lib/components/Dropdown.svelte @@ -10,7 +10,7 @@ let dropdown: HTMLDivElement; const DropdownIcon = { - closed: '▼', + closed: '▼', open: '▲' }; diff --git a/src/lib/components/SignOut.svelte b/src/lib/components/SignOut.svelte index afeb2cf..d473f67 100644 --- a/src/lib/components/SignOut.svelte +++ b/src/lib/components/SignOut.svelte @@ -1,6 +1,6 @@ diff --git a/src/lib/components/navigation/NavLink.svelte b/src/lib/components/navigation/NavLink.svelte index b8cb06c..843b323 100644 --- a/src/lib/components/navigation/NavLink.svelte +++ b/src/lib/components/navigation/NavLink.svelte @@ -1,15 +1,14 @@ {#if !linkItem.isSignout} - {linkItem.text} + {linkItem.text} {:else if supabase && linkItem.isSignout} - -{/if} \ No newline at end of file + +{/if} diff --git a/src/lib/components/navigation/NavLinkParent.svelte b/src/lib/components/navigation/NavLinkParent.svelte index 9e28f84..2b33eb8 100644 --- a/src/lib/components/navigation/NavLinkParent.svelte +++ b/src/lib/components/navigation/NavLinkParent.svelte @@ -8,8 +8,7 @@ export let linkItem: NavLinkItem; export let isMobile: boolean; - export let supabase: SupabaseClient | null; - + export let supabase: SupabaseClient | null; let isOpen = false; @@ -35,7 +34,7 @@ transition:slide={{ duration: 200, easing: cubicInOut }} > {#each linkItem.children ?? [] as child (child.text.replace(' ', '-').toLowerCase())} -
  • +
  • {/each} {/if} diff --git a/src/lib/components/navigation/NavLinks.svelte b/src/lib/components/navigation/NavLinks.svelte index 893b792..842e244 100644 --- a/src/lib/components/navigation/NavLinks.svelte +++ b/src/lib/components/navigation/NavLinks.svelte @@ -4,43 +4,39 @@ import NavLinkParent from './NavLinkParent.svelte'; import type SupabaseClient from '@supabase/supabase-js/dist/module/SupabaseClient'; - export let session: Session | null; - export let supabase: SupabaseClient | null = null; + export let session: Session | null; + export let supabase: SupabaseClient | null = null; export let isMobile = false; - const userAccountLinks: NavLinkItem[] = []; + const userAccountLinks: NavLinkItem[] = []; - if (isMobile) { - if (session) { - userAccountLinks.push( - { - text: 'User', // TODO - replace with user's name - will require a database call to get the user's name - suggest setting up a user model to store user data. - isParent: true, - isUserAccount: true, - children: [ - { - text: 'Account', - href: '/account' - }, - { - text: 'Sign Out', - isSignout: true - } - ] - } - ); - } else { - userAccountLinks.push( - { - text: 'Log in', - href: '/login' - }, - ); - } - } + if (isMobile) { + if (session) { + userAccountLinks.push({ + text: 'User', // TODO - replace with user's name - will require a database call to get the user's name - suggest setting up a user model to store user data. + isParent: true, + isUserAccount: true, + children: [ + { + text: 'Account', + href: '/account' + }, + { + text: 'Sign Out', + isSignout: true + } + ] + }); + } else { + userAccountLinks.push({ + text: 'Log in', + href: '/login' + }); + } + } const links: NavLinkItem[] = [ - ...userAccountLinks, + ...userAccountLinks, { text: 'Products', href: '/products' diff --git a/src/lib/utils/supabase/auth.ts b/src/lib/utils/supabase/auth.ts index daf37d2..1e1705a 100644 --- a/src/lib/utils/supabase/auth.ts +++ b/src/lib/utils/supabase/auth.ts @@ -1,6 +1,6 @@ -import type { SupabaseClient } from "@supabase/supabase-js"; +import type { SupabaseClient } from '@supabase/supabase-js'; export async function signOut(supabase: SupabaseClient, callback: () => void) { - // TODO use the error from the response - const { error } = await supabase.auth.signOut().then(callback); -} \ No newline at end of file + // TODO use the error from the response + const { error } = await supabase.auth.signOut().then(callback); +}