Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ceremony): save terminal progress
Browse files Browse the repository at this point in the history
Swepool committed Sep 25, 2024

Verified

This commit was signed with the committer’s verified signature.
Swepool Lukas
1 parent 09bc2ad commit 8705d07
Showing 8 changed files with 36 additions and 75 deletions.
27 changes: 10 additions & 17 deletions ceremony/src/lib/components/Terminal/Contributors.svelte
Original file line number Diff line number Diff line change
@@ -27,23 +27,16 @@ onMount(() => {
unsubscribe = terminal.keys.subscribe(event => {
if (event) {
if (event.type === "keydown") {
switch (event.key) {
case "ArrowUp": {
selectedIndex =
(selectedIndex - 1 + contributions.data.length) % contributions.data.length
buttons[selectedIndex]?.focus()
break
}
case "ArrowDown": {
selectedIndex = (selectedIndex + 1) % contributions.data.length
buttons[selectedIndex]?.focus()
break
}
case "Enter": {
if (buttons[selectedIndex]) {
fireEvent(contributions.data[selectedIndex])
}
break
if (event.key === "ArrowUp") {
selectedIndex =
(selectedIndex - 1 + contributions.data.length) % contributions.data.length
buttons[selectedIndex]?.focus()
} else if (event.key === "ArrowDown") {
selectedIndex = (selectedIndex + 1) % contributions.data.length
buttons[selectedIndex]?.focus()
} else if (event.key === "Enter") {
if (buttons[selectedIndex]) {
fireEvent(contributions.data[selectedIndex])
}
}
}
19 changes: 7 additions & 12 deletions ceremony/src/lib/components/Terminal/Install/SelectOS.svelte
Original file line number Diff line number Diff line change
@@ -22,18 +22,13 @@ onMount(() => {
function handleKeyDown(event: KeyEvent) {
if (event.type === "keydown") {
switch (event.key) {
case "ArrowUp":
currentFocusIndex = (currentFocusIndex - 1 + selections.length) % selections.length
break
case "ArrowDown":
currentFocusIndex = (currentFocusIndex + 1) % selections.length
break
case "Enter": {
showButtons = false
select(selections[currentFocusIndex])
break
}
if (event.key === "ArrowUp") {
currentFocusIndex = (currentFocusIndex - 1 + selections.length) % selections.length
} else if (event.key === "ArrowDown") {
currentFocusIndex = (currentFocusIndex + 1) % selections.length
} else if (event.key === "Enter") {
showButtons = false
select(selections[currentFocusIndex])
}
}
}
16 changes: 6 additions & 10 deletions ceremony/src/lib/components/Terminal/Thanks.svelte
Original file line number Diff line number Diff line change
@@ -28,16 +28,12 @@ onMount(() => {
unsubscribe = terminal.keys.subscribe(event => {
if (event) {
if (event.type === "keydown" && terminal.tab === 1) {
switch (event.key) {
case "ArrowUp":
selectedButton = (selectedButton - 1 + buttons.length) % buttons.length
break
case "ArrowDown":
selectedButton = (selectedButton + 1) % buttons.length
break
case "Enter":
triggerAction(selectedButton)
break
if (event.key === "ArrowUp") {
selectedButton = (selectedButton - 1 + buttons.length) % buttons.length
} else if (event.key === "ArrowDown") {
selectedButton = (selectedButton + 1) % buttons.length
} else if (event.key === "Enter") {
triggerAction(selectedButton)
}
}
}
31 changes: 10 additions & 21 deletions ceremony/src/lib/components/Terminal/index.svelte
Original file line number Diff line number Diff line change
@@ -27,27 +27,16 @@ const changeTab = async (tab: number) => {
const unsubscribe = terminal.keys.subscribe(event => {
if (event) {
if (event.type === "keydown" && (event.shiftKey || event.ctrlKey)) {
switch (event.key) {
case "!": {
changeTab(1)
break
}
case "@": {
changeTab(2)
break
}
case "#": {
changeTab(3)
break
}
case "$": {
changeTab(4)
break
}
case "X": {
logout(terminal)
break
}
if (event.key === "!") {
changeTab(1)
} else if (event.key === "@") {
changeTab(2)
} else if (event.key === "#") {
changeTab(3)
} else if (event.key === "$") {
changeTab(4)
} else if (event.key === "X") {
logout(terminal)
}
}
}
12 changes: 1 addition & 11 deletions ceremony/src/lib/state/contributor.svelte.ts
Original file line number Diff line number Diff line change
@@ -142,20 +142,10 @@ export class Contributor {
}

this.pollingState = "stopped"
this.stopClientStatePolling()
this.stopQueueInfoPolling()
this.stopContributionStatePolling()
}


private stopClientStatePolling() {
if (this.pollIntervals.client) {
clearInterval(this.pollIntervals.client)
this.pollIntervals.client = null
}
}


private startQueueInfoPolling() {
this.pollQueueInfo()
this.pollIntervals.queue = setInterval(
@@ -206,7 +196,6 @@ export class Contributor {
}
}


private updateQueueInfo(queueInfo: QueueInfoResult) {
if (queueInfo.inQueue) {
this.queueState = {
@@ -238,6 +227,7 @@ export class Contributor {

private updateState() {
if (this.contributionState === "contribute") {
this.state = "contribute"
} else if (this.queueState.position !== null) {
this.state = "inQueue"
} else if (this.contributionState === "contributed") {
2 changes: 0 additions & 2 deletions ceremony/src/lib/state/terminal.svelte.ts
Original file line number Diff line number Diff line change
@@ -76,8 +76,6 @@ export class Terminal {
setContribution(contribution: any) {
this.contribution = contribution
}

private updateState() {}
}

const TERMINAL_KEY = Symbol("TERMINAL")
2 changes: 1 addition & 1 deletion ceremony/src/lib/supabase/index.ts
Original file line number Diff line number Diff line change
@@ -121,11 +121,11 @@ export const getCurrentUserState = async (userId: string | undefined): Promise<A
const { data, error } = await queryCurrentUserState()
if (error || !data) return undefined

return "inQueue"
if (data.has_redeemed) return "hasRedeemed"
if (data.in_queue) return "inQueue"
if (data.in_waitlist) return "inWaitlist"

return "join"
}

export const getContributions = async () => {
2 changes: 1 addition & 1 deletion ceremony/src/routes/0____0/[hash]/+page.svelte
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ const { terminal } = getState()
let hash = $derived($page.params.hash)
onMount(async () => {
onMount(() => {
terminal.setTab(4)
terminal.setHash(hash)
})

0 comments on commit 8705d07

Please sign in to comment.