Skip to content

Commit

Permalink
feat: allow viewing homepage even if logged in
Browse files Browse the repository at this point in the history
  • Loading branch information
WhyAsh5114 committed Oct 12, 2024
1 parent 5a1edf8 commit 1194855
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/routes/(components)/layout/DesktopLayout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</script>

<header class="flex h-screen w-96 flex-col bg-muted p-10">
<Button class="justify-start gap-2 text-foreground" href="/" variant="link">
<Button class="justify-start gap-2 text-foreground" href="/?forceView" variant="link">
{#if $navigating}
<div class="flex h-[72px] w-[72px] items-center justify-center">
<LoaderCircle class="animate-spin text-primary" height={48} width={48} />
Expand Down
16 changes: 7 additions & 9 deletions src/routes/(components)/layout/MobileLayout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,13 @@
</Sheet.Trigger>
<Sheet.Content side="left">
<Sheet.Header class="items-start">
<Sheet.Title>
<Button
class="justify-start gap-2 text-foreground"
onclick={async () => {
await goto('/');
sheetOpen = false;
}}
variant="link"
>
<Sheet.Title
onclick={async () => {
await goto('/?forceView');
sheetOpen = false;
}}
>
<Button class="pointer-events-none justify-start gap-2 text-foreground" variant="link">
<img alt="MyFit logo" height={52} src="/favicon.webp" width={52} />
<h1 class="text-2xl font-bold">MyFit</h1>
</Button>
Expand Down
9 changes: 5 additions & 4 deletions src/routes/(components)/layout/NavLinks.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
export let sheetOpen: boolean | undefined = undefined;
const linkItems: { text: string; href: string }[] = [
{ text: 'Workouts', href: '/workouts' },
{ text: 'Mesocycles', href: '/mesocycles' },
{ text: 'Dashboard', href: '/dashboard' },
{ text: 'Exercise splits', href: '/exercise-splits' },
{ text: 'Privacy policy', href: '/privacy-policy' },
{ text: 'Donations', href: '/donations' }
{ text: 'Mesocycles', href: '/mesocycles' },
{ text: 'Workouts', href: '/workouts' },
{ text: 'Donations', href: '/donations' },
{ text: 'Privacy policy', href: '/privacy-policy' }
];
</script>

Expand Down
16 changes: 10 additions & 6 deletions src/routes/(components)/page/ActionButtons.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import GitHub from 'virtual:icons/lucide/github';
import Star from 'virtual:icons/lucide/star';
import LoginProviderMenu from '../layout/LoginProviderMenu.svelte';
import type { Session } from '@auth/sveltekit';
let { session }: { session: Session | null } = $props();
let stars: number | undefined = $state();
onMount(async () => {
Expand All @@ -30,10 +32,12 @@
</Badge>
{/if}
</Button>
<DropdownMenu.Root>
<DropdownMenu.Trigger asChild let:builder>
<Button builders={[builder]} class="w-fit">Login</Button>
</DropdownMenu.Trigger>
<LoginProviderMenu />
</DropdownMenu.Root>
{#if session === null}
<DropdownMenu.Root>
<DropdownMenu.Trigger asChild let:builder>
<Button builders={[builder]} class="w-fit">Login</Button>
</DropdownMenu.Trigger>
<LoginProviderMenu />
</DropdownMenu.Root>
{/if}
</div>
2 changes: 1 addition & 1 deletion src/routes/(components)/page/DesktopLandingPage.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</div>
<CarouselComponent />
<StatsComponent {...counts} />
<ActionButtons />
<ActionButtons {...counts} />
<Features />
<Faq class="col-span-2" />
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/routes/(components)/page/MobileLandingPage.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</span>
<CarouselComponent />
<StatsComponent {...counts} />
<ActionButtons />
<ActionButtons {...counts} />
<Features />
<Faq />
</div>
7 changes: 5 additions & 2 deletions src/routes/+page.server.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import { prisma } from '$lib/prisma.js';
import type { Session } from '@auth/sveltekit';
import { redirect } from '@sveltejs/kit';

export const load = async ({ parent }) => {
export const load = async ({ parent, url }) => {
const { session } = await parent();
if (session) redirect(302, '/dashboard');
if (session && !url.searchParams.has('forceView')) redirect(302, '/dashboard');

return {
session,
workoutCount: prisma.workout.count(),
exerciseCount: prisma.workoutExercise.count(),
setsCount: prisma.workoutExerciseSet.count()
};
};

export type HomePageCounts = {
session: Session | null;
workoutCount: Promise<number>;
exerciseCount: Promise<number>;
setsCount: Promise<number>;
Expand Down

0 comments on commit 1194855

Please sign in to comment.