Skip to content

Commit

Permalink
Improve error handling for open cloud dialog with no saved wheels
Browse files Browse the repository at this point in the history
  • Loading branch information
gomander committed Jan 13, 2024
1 parent 9a92cf3 commit b15f9ca
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 14 deletions.
7 changes: 5 additions & 2 deletions src/lib/components/OpenCloudDialog.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@
}
const response = await getWheels(user.uid)
if (!response.success) {
throw new Error('Failed to fetch wheels')
throw new Error(response.error.message)
}
wheels = response.data.wheels
if (!wheels.length) {
throw new Error('No saved wheels')
}
} catch (error) {
if (error instanceof Error) {
toastStore.trigger({
Expand All @@ -58,7 +61,7 @@
}
const response = await getWheel(path, user.uid)
if (!response.success) {
throw new Error('Error opening wheel')
throw new Error(response.error.message)
}
const { config, entries } = response.data.wheel
wheelStore.setConfig(config)
Expand Down
4 changes: 2 additions & 2 deletions src/lib/components/SaveCloudDialog.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
uid: user.uid
}, user.uid)
if (!response.success) {
throw new Error('Failed to save wheel')
throw new Error(response.error.message)
}
}
if (saveMode === 'overwrite' && $wheelStore.path) {
Expand All @@ -76,7 +76,7 @@
uid: user.uid
}, user.uid)
if (!response.success) {
throw new Error('Failed to save wheel')
throw new Error(response.error.message)
}
}
modalStore.close()
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/ShareDialog.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
uid: user.uid
}, user.uid)
if (!response.success) {
throw new Error('Failed to share wheel')
throw new Error(response.error.message)
}
modalStore.close()
toastStore.trigger({
Expand Down
3 changes: 3 additions & 0 deletions src/lib/server/FirebaseAdmin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ export const getUserWheelsMeta = async (uid: string) => {
return []
}
const user = userSnap.data() as ApiUser
if (!user.wheels.length) {
return []
}
return await getWheelMetaForPaths(user.wheels)
}

Expand Down
23 changes: 14 additions & 9 deletions src/routes/[path=path]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import type { OnStoppedData } from '$lib/utils/Wheel'
export let data
const { wheel } = data
const modalStore = getModalStore()
Expand All @@ -23,27 +24,31 @@
modalStore.trigger(createWinnerModal(e.detail))
}
wheelStore.setConfig(data.wheel.config)
wheelStore.setEntries(data.wheel.entries)
wheelStore.setConfig(wheel.config)
wheelStore.setEntries(wheel.entries)
</script>

<svelte:head>
<title>{data.wheel.config.title} - Svelte Wheel</title>
<meta property="og:title" content={data.wheel.config.title} />
<meta property="og:description" content={data.wheel.config.description} />
<title>{wheel.config.title} - Svelte Wheel</title>
<meta name="title" content={wheel.config.title} />
<meta property="og:title" content={wheel.config.title} />
{#if wheel.config.description}
<meta name="description" content={wheel.config.description} />
<meta property="og:description" content={wheel.config.description} />
{/if}
<!-- <meta
property="og:image"
content="https://sveltewheel.com/thumbnails/{data.wheel.path}"
content="https://sveltewheel.com/thumbnails/{wheel.path}"
/> -->
<meta name="twitter:card" content="summary_large_image" />
<meta name="theme-color" content="{data.wheel.config.colors.at(0)}">
<meta name="theme-color" content="{wheel.config.colors.at(0)}">
</svelte:head>

<div class="min-h-screen flex flex-col">
<main class="flex-grow flex flex-col xl:grid grid-cols-6">
<div class="col-span-1 pb-0 p-4 xl:pb-4 xl:pr-0 flex flex-col">
<h2 class="text-3xl">{data.wheel.config.title}</h2>
<p class="text-lg">{data.wheel.config.description}</p>
<h2 class="text-3xl">{wheel.config.title}</h2>
<p class="text-lg">{wheel.config.description}</p>
</div>

<div class="col-span-4 flex-1 flex flex-col justify-center items-center">
Expand Down
11 changes: 11 additions & 0 deletions tests/playwright/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,14 @@ test('Wheel can be spun and a result is generated', async ({ page }) => {
expect(resultsTextbox).toHaveValue(result as string)
])
})

test('Login dialog opens when user who is not logged in clicks on open button', async ({ page }) => {
await page.goto('/')
const openButton = page.getByRole('button', { name: 'Open' })
const openFromCloudButton = page.getByRole('button', { name: 'Open from the cloud' })
const logInHeading = page.getByRole('heading', { name: 'Log in' })
await openButton.click()
await openFromCloudButton.isVisible()
await openFromCloudButton.click()
await logInHeading.isVisible()
})

0 comments on commit b15f9ca

Please sign in to comment.