Skip to content

Commit

Permalink
Fixed missing context cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
amyjko committed Oct 19, 2024
1 parent e060264 commit 4e49e70
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/lib/Tip.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
const user = getUser();
const context = getOrg();
let org = $derived(context.org);
let org = $derived(context?.org);
let isMember = $derived($user && org?.hasPerson($user.id));
let isAdmin = $derived($user && org?.hasAdminPerson($user.id));
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Title.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
let { title, kind = undefined, label = true, edit = undefined, children }: Props = $props();
const context = getOrg();
let org = $derived(context.org);
let org = $derived(context?.org);
</script>

<svelte:head>
Expand Down
6 changes: 3 additions & 3 deletions src/lib/contexts.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import type OrganizationsDB from '$database/OrganizationsDB';
import type Organization from '$types/Organization';

export const OrgSymbol = Symbol('organization');

export function getOrg(): { org: Organization } {
return getContext<{ org: Organization }>(OrgSymbol);
export type OrgContext = { org: Organization };
export function getOrg(): OrgContext {
return getContext<OrgContext>(OrgSymbol);
}

export const UserSymbol = Symbol('user');
Expand Down
12 changes: 7 additions & 5 deletions src/routes/org/[orgid]/team/[teamid]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@
import Header from '$lib/Header.svelte';
const user = getUser();
const org = getOrg();
const context = getOrg();
const org = $derived(context.org);
const db = getDB();
const errors = getErrors();
let teamID = $derived($page.params.teamid);
let team = $derived(org.org.getTeam(teamID));
let isAdmin = $derived($user && org.org.hasAdminPerson($user.id));
let team = $derived(org.getTeam(teamID));
let isAdmin = $derived($user && org.hasAdminPerson($user.id));
</script>

{#if team}
Expand Down Expand Up @@ -53,7 +55,7 @@
: undefined}
/>

{#each org.org.getTeamRoles(team.id).sort((a, b) => a.title.localeCompare(b.title)) as role}
{#each org.getTeamRoles(team.id).sort((a, b) => a.title.localeCompare(b.title)) as role}
<RoleLink roleID={role.id} />
{:else}
<Notice>This team has no roles.</Notice>
Expand All @@ -69,7 +71,7 @@
tip="Delete this team from the organization. Any roles on the team will remain, but be teamless."
action={async () => {
const error = await queryOrError(errors, db.deleteTeam(teamID), "Couldn't delete the team.");
if (error === null) goto(`/org/${org.org.getPath()}/roles`);
if (error === null) goto(`/org/${org.getPath()}/roles`);
}}
warning>{Delete} Delete this team</Button
>
Expand Down

0 comments on commit 4e49e70

Please sign in to comment.