Skip to content

Commit

Permalink
Prevented flash on page load.
Browse files Browse the repository at this point in the history
  • Loading branch information
amyjko committed Jun 25, 2024
1 parent bf52493 commit eedcd20
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/routes/+layout.server.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/** @type {import('./$types').LayoutServerLoad} */
export async function load({ locals }) {
return {
session: locals.session
session: locals.session,
user: locals.user
};
}
9 changes: 7 additions & 2 deletions src/routes/org/[orgid]/+layout.server.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import OrganizationsDB, { type OrganizationPayload } from '$database/OrganizationsDB';
import type { User } from '@supabase/supabase-js';

/** @type {import('./$types').LayoutServerLoad} */
export async function load({ params, locals }): Promise<{ payload: OrganizationPayload | null }> {
export async function load({
params,
locals
}): Promise<{ payload: OrganizationPayload | null; user: User | null }> {
/** Get the serializable organization payload from the database */
const org = await new OrganizationsDB(locals.supabase).getPayload(params.orgid);

return {
payload: org
payload: org,
user: locals.user
};
}
10 changes: 5 additions & 5 deletions src/routes/org/[orgid]/+layout.svelte
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
<script lang="ts">
import Oops from '$lib/Oops.svelte';
import Title from '$lib/Title.svelte';
import { OrgSymbol, getDB, getUser } from '$lib/contexts';
import { OrgSymbol, getDB } from '$lib/contexts';
import { onMount, setContext } from 'svelte';
import { page } from '$app/stores';
export let data;
$: ({ payload, user } = data);
const db = getDB();
const user = getUser();
// Save the payload in the database cache.
$: payload = data.payload;
$: org = data.payload ? $db.updateOrg(data.payload) : undefined;
$: if (payload) setContext(OrgSymbol, org);
onMount(() => {
// When this layout mounts, listen to realtime changes on the organization payload.
const orgid = $page.params.orgid;
Expand All @@ -28,9 +27,10 @@
</script>

{#if $org}
{#if $org.getVisibility() === 'public' || ($user && $org.getVisibility() === 'org' && $org.hasPerson($user.id)) || ($user && $org.getVisibility() === 'admin' && $org.hasAdminPerson($user.id))}
{#if $org.getVisibility() === 'public' || (user && (($org.getVisibility() === 'org' && $org.hasPerson(user.id)) || ($org.getVisibility() === 'admin' && $org.hasAdminPerson(user.id))))}
<slot />
{:else}
<Title title="Oops" kind="organization" />
<Oops text="This organization's details aren't visible to you." />
{/if}
{:else}
Expand Down

0 comments on commit eedcd20

Please sign in to comment.