Skip to content

Commit

Permalink
fix(ceremony): changes to allowance handling
Browse files Browse the repository at this point in the history
Swepool committed Sep 14, 2024
1 parent aa677f5 commit 95f6f60
Showing 4 changed files with 13 additions and 15 deletions.
2 changes: 1 addition & 1 deletion ceremony/src/lib/stores/state.svelte.ts
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ type State =
| "offline"
| "noClient"

export type AllowanceState = "invited" | "waitingList" | undefined
export type AllowanceState = "invited" | "waitingList" | "join" | undefined

export type ContributionState = "contribute" | "contributed" | "verifying" | "notContributed"

4 changes: 2 additions & 2 deletions ceremony/src/lib/supabase/index.ts
Original file line number Diff line number Diff line change
@@ -104,7 +104,7 @@ export const getContributionState = async (): Promise<ContributionState> => {
export const getAllowanceState = async (userId: string | undefined): Promise<AllowanceState> => {
if (!userId) {
console.log("Need to be logged in to get allowance state")
return
return undefined
}

const { data, error } = await queryAllowance()
@@ -113,5 +113,5 @@ export const getAllowanceState = async (userId: string | undefined): Promise<All
if (data.in_waitlist) return "waitingList"
if (data.has_redeemed) return "invited"

return undefined
return "join"
}
20 changes: 9 additions & 11 deletions ceremony/src/routes/+page.svelte
Original file line number Diff line number Diff line change
@@ -4,30 +4,28 @@ import H1 from "$lib/components/typography/H1.svelte"
import { ContributorState } from "$lib/stores/state.svelte.ts"
import Ceremony from "$lib/components/Ceremony.svelte"
import Join from "$lib/components/Join.svelte"
import Spinner from "$lib/components/Spinner.svelte"
//Improvements
//Only start polling depending on allowance, no need to poll if not allowed.
//
//This could be set with context API if we expand the app a lot.
let contributor: ContributorState = new ContributorState()
$effect(() => {
$effect.pre(() => {
const userId = user.session?.user.id
if (userId) contributor.setUserId(userId)
})
</script>

<!--Maybe add loading state to handle text jump-->
<!--Fix jump between state on load-->
{#if contributor.loggedIn}
{#if contributor.allowanceState === "invited"}
{#if !contributor.allowanceState}
<Spinner class="text-union-accent-500 size-6"/>
{:else if contributor.allowanceState === "invited"}
<Ceremony {contributor}/>
{:else if contributor.allowanceState === "waitingList"}
<H1>Your on the list</H1>
{:else}
<H1>You're on the list</H1>
{:else if contributor.allowanceState === "join"}
<Join {contributor}/>
{/if}
{:else}
<H1>Welcome to union ceremony</H1>
<H1>Welcome to the union ceremony</H1>
{/if}

2 changes: 1 addition & 1 deletion ceremony/src/routes/auth/register/+page.svelte
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ let loading = false
async function register() {
loading = true
await auth(`${$page.url.origin}/app`)
await auth(`${$page.url.origin}/`)
}
</script>

0 comments on commit 95f6f60

Please sign in to comment.