Skip to content

Commit

Permalink
hide hamburger on mobile by default
Browse files Browse the repository at this point in the history
  • Loading branch information
craigkai committed Jun 25, 2024
1 parent 34abc07 commit fea4e04
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 9 deletions.
25 changes: 24 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
},
"type": "module",
"dependencies": {
"radix-svelte": "^0.9.0"
"radix-svelte": "^0.9.0",
"ua-parser-js": "^1.0.38"
}
}
1 change: 1 addition & 0 deletions src/app.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ declare global {
safeGetSession: () => Promise<{ session: Session | null; user: User | null }>;
session: Session | null;
user: User | null;
isMobile: boolean;
}
// interface Platform {}

Expand Down
8 changes: 6 additions & 2 deletions src/components/Header.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
import Moon from 'lucide-svelte/icons/moon';
import { toggleMode } from 'mode-watcher';
let { supabase, authChange = $bindable() }: { supabase: any; authChange: Boolean } = $props();
let {
supabase,
authChange = $bindable(),
isMobile
}: { supabase: any; authChange: Boolean; isMobile: boolean } = $props();
let open: boolean = $state(true);
let open: boolean = $state(isMobile);
let currentUser: { data: { user: { aud: string } } } | undefined = $state();
Expand Down
4 changes: 4 additions & 0 deletions src/hooks.server.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { createServerClient } from '@supabase/ssr';
import { type Handle, redirect } from '@sveltejs/kit';
import { sequence } from '@sveltejs/kit/hooks';
import { UAParser } from 'ua-parser-js';

import { PUBLIC_SUPABASE_URL, PUBLIC_SUPABASE_ANON_KEY } from '$env/static/public';

export const supabase: Handle = async ({ event, resolve }) => {
const parser = new UAParser(event.request.headers.get('user-agent'));
event.locals.isMobile = parser.getDevice().type === 'mobile' || 'dog';

event.locals.supabase = createServerClient(PUBLIC_SUPABASE_URL, PUBLIC_SUPABASE_ANON_KEY, {
cookies: {
getAll() {
Expand Down
5 changes: 3 additions & 2 deletions src/routes/+layout.server.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import type { LayoutServerLoad } from './$types';

export const load: LayoutServerLoad = async ({ locals: { safeGetSession } }) => {
export const load: LayoutServerLoad = async ({ locals: { safeGetSession, isMobile } }) => {
const { session, user } = await safeGetSession();

return {
session,
user
user,
isMobile
};
};
4 changes: 2 additions & 2 deletions src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
inject({ mode: dev ? 'development' : 'production' });
let { data, children, authChange } = $props();
let { session, supabase } = data;
let { session, supabase, isMobile } = data;
onMount(() => {
const { data } = supabase.auth.onAuthStateChange((_, newSession) => {
Expand Down Expand Up @@ -50,7 +50,7 @@
<div class="dark:bg-gray-900 dark:text-gray-100 text-gray-900 bg-white">
<ModeWatcher defaultMode={'light'} />

<Header {supabase} bind:authChange />
<Header {supabase} {isMobile} bind:authChange />

<div class="min-h-screen">
<div class="wrap">
Expand Down
2 changes: 1 addition & 1 deletion src/routes/+layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ export const load: LayoutLoad = async ({ fetch, data, depends }) => {
data: { session }
} = await supabase.auth.getSession();

return { supabase, session };
return { supabase, session, isMobile: data.isMobile };
};

0 comments on commit fea4e04

Please sign in to comment.