refactor(#35): iNdEnTaTiOn

This commit is contained in:
OllyNicholass
2024-10-29 21:46:52 +00:00
parent 550d9bac18
commit d49f4b2c38
7 changed files with 49 additions and 55 deletions
+1 -1
View File
@@ -6,7 +6,7 @@
"dev": "vite dev", "dev": "vite dev",
"build": "vite build", "build": "vite build",
"preview": "vite preview", "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": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch", "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
"lint": "prettier --check . && eslint .", "lint": "prettier --check . && eslint .",
+1 -1
View File
@@ -10,7 +10,7 @@
let dropdown: HTMLDivElement; let dropdown: HTMLDivElement;
const DropdownIcon = { const DropdownIcon = {
closed: '▼', closed: '▼',
open: '▲' open: '▲'
}; };
+5 -5
View File
@@ -1,6 +1,6 @@
<script lang="ts"> <script lang="ts">
import { createEventDispatcher } from 'svelte'; import { createEventDispatcher } from 'svelte';
import { signOut } from '$lib/utils/supabase/auth'; import { signOut } from '$lib/utils/supabase/auth';
import type { SupabaseClient } from '@supabase/supabase-js'; import type { SupabaseClient } from '@supabase/supabase-js';
const dispatch = createEventDispatcher(); const dispatch = createEventDispatcher();
@@ -11,10 +11,10 @@
// Access the supabase client from the layout data // Access the supabase client from the layout data
export let supabase: SupabaseClient | null; export let supabase: SupabaseClient | null;
async function signOutClick() { async function signOutClick() {
if (!supabase) return; if (!supabase) return;
await signOut(supabase, emitSignedOutEvent); await signOut(supabase, emitSignedOutEvent);
} }
</script> </script>
<button on:click={signOutClick}>Sign Out</button> <button on:click={signOutClick}>Sign Out</button>
+7 -8
View File
@@ -1,15 +1,14 @@
<script lang="ts"> <script lang="ts">
import type { NavLinkItem } from "$lib/types/Nav/NavLinkItem"; import type { NavLinkItem } from '$lib/types/Nav/NavLinkItem';
import type { SupabaseClient } from "@supabase/supabase-js"; import type { SupabaseClient } from '@supabase/supabase-js';
import SignOut from "../SignOut.svelte"; import SignOut from '../SignOut.svelte';
export let linkItem: NavLinkItem;
export let supabase: SupabaseClient | null = null;
export let linkItem: NavLinkItem;
export let supabase: SupabaseClient | null = null;
</script> </script>
{#if !linkItem.isSignout} {#if !linkItem.isSignout}
<a href={linkItem.href}>{linkItem.text}</a> <a href={linkItem.href}>{linkItem.text}</a>
{:else if supabase && linkItem.isSignout} {:else if supabase && linkItem.isSignout}
<SignOut {supabase} /> <SignOut {supabase} />
{/if} {/if}
@@ -8,8 +8,7 @@
export let linkItem: NavLinkItem; export let linkItem: NavLinkItem;
export let isMobile: boolean; export let isMobile: boolean;
export let supabase: SupabaseClient | null; export let supabase: SupabaseClient | null;
let isOpen = false; let isOpen = false;
</script> </script>
@@ -35,7 +34,7 @@
transition:slide={{ duration: 200, easing: cubicInOut }} transition:slide={{ duration: 200, easing: cubicInOut }}
> >
{#each linkItem.children ?? [] as child (child.text.replace(' ', '-').toLowerCase())} {#each linkItem.children ?? [] as child (child.text.replace(' ', '-').toLowerCase())}
<li><NavLink linkItem={child} {supabase} /></li> <li><NavLink linkItem={child} {supabase} /></li>
{/each} {/each}
</ul> </ul>
{/if} {/if}
+28 -32
View File
@@ -4,43 +4,39 @@
import NavLinkParent from './NavLinkParent.svelte'; import NavLinkParent from './NavLinkParent.svelte';
import type SupabaseClient from '@supabase/supabase-js/dist/module/SupabaseClient'; import type SupabaseClient from '@supabase/supabase-js/dist/module/SupabaseClient';
export let session: Session | null; export let session: Session | null;
export let supabase: SupabaseClient | null = null; export let supabase: SupabaseClient | null = null;
export let isMobile = false; export let isMobile = false;
const userAccountLinks: NavLinkItem[] = []; const userAccountLinks: NavLinkItem[] = [];
if (isMobile) { if (isMobile) {
if (session) { if (session) {
userAccountLinks.push( 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.
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,
isParent: true, isUserAccount: true,
isUserAccount: true, children: [
children: [ {
{ text: 'Account',
text: 'Account', href: '/account'
href: '/account' },
}, {
{ text: 'Sign Out',
text: 'Sign Out', isSignout: true
isSignout: true }
} ]
] });
} } else {
); userAccountLinks.push({
} else { text: 'Log in',
userAccountLinks.push( href: '/login'
{ });
text: 'Log in', }
href: '/login' }
},
);
}
}
const links: NavLinkItem[] = [ const links: NavLinkItem[] = [
...userAccountLinks, ...userAccountLinks,
{ {
text: 'Products', text: 'Products',
href: '/products' href: '/products'
+3 -3
View File
@@ -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) { export async function signOut(supabase: SupabaseClient, callback: () => void) {
// TODO use the error from the response // TODO use the error from the response
const { error } = await supabase.auth.signOut().then(callback); const { error } = await supabase.auth.signOut().then(callback);
} }