Skip to content

Commit

Permalink
style: Restyle login page
Browse files Browse the repository at this point in the history
Fixes #116
  • Loading branch information
Perdolique committed Sep 11, 2024
1 parent 90fb561 commit 7d641da
Show file tree
Hide file tree
Showing 2 changed files with 136 additions and 25 deletions.
154 changes: 129 additions & 25 deletions app/pages/login.vue
Original file line number Diff line number Diff line change
@@ -1,47 +1,93 @@
<template>
<div :class="$style.component">
<PerdButton @click="signUp">
Sign up anonymously
</PerdButton>

<PerdLink
to="/api/oauth/twitch"
external
>
Sign in with Twitch
</PerdLink>
<div :class="$style.header">
<div :class="$style.logo">
🐕💨
</div>

<div :class="$style.title">
Welcome to Perd*!
</div>

<div :class="$style.note">
*technical name
</div>
</div>

<div :class="$style.buttons">
<IconButton
icon-name="tabler:brand-among-us"
:class="$style.button"
class="amogus"
:loading="isAuthenticating"
@click="signUp"
/>

<IconButton
:class="$style.button"
class="twitch"
icon-name="tabler:brand-twitch"
:loading="isAuthenticating"
@click="redirectToTwitch"
/>
</div>
</div>
</template>

<script lang="ts" setup>
import { startPagePath } from '~~/constants';
import PerdButton from '~/components/PerdButton.vue';
import PerdLink from '~/components/PerdLink.vue';
import { startViewTransition } from '~/utils/dom';
import IconButton from '~/components/IconButton.vue';
definePageMeta({
layout: false
})
const { user } = useUserStore()
const route = useRoute()
const isAuthenticating = ref(false)
async function signUp() {
const response = await $fetch('/api/auth/create-session', {
method: 'POST'
if (isAuthenticating.value) {
return
}
startViewTransition(() => {
isAuthenticating.value = true
})
if (typeof response.userId === 'string') {
user.value.userId = response.userId
try {
const responsePromise = $fetch('/api/auth/create-session', {
method: 'POST'
})
const response = await withMinimumDelay(responsePromise, 500)
if (typeof response.userId === 'string') {
user.value.userId = response.userId
}
const redirectPath =
typeof route.query.redirectTo === 'string'
? route.query.redirectTo
: startPagePath
await navigateTo(redirectPath, {
replace: true
})
} catch (error) {
// TODO: Handle error properly
console.error(error)
} finally {
isAuthenticating.value = false
}
}
const redirectPath =
typeof route.query.redirectTo === 'string'
? route.query.redirectTo
: startPagePath
function redirectToTwitch() {
isAuthenticating.value = true
await navigateTo(redirectPath, {
replace: true
})
window.location.href = '/api/oauth/twitch'
}
</script>

Expand All @@ -50,7 +96,65 @@
display: grid;
justify-content: center;
text-align: center;
gap: var(--spacing-16);
padding-top: var(--spacing-32);
row-gap: var(--spacing-16);
padding: var(--spacing-32);
}
.logo {
font-size: 4rem;
white-space: nowrap;
}
.header {
display: grid;
gap: var(--spacing-32);
}
.title {
font-size: 1.5rem;
font-weight: bold;
}
.note {
font-size: 0.75rem;
margin-top: calc(-1 * var(--spacing-24));
}
.buttons {
display: flex;
gap: var(--spacing-8);
justify-content: center;
}
.button {
transition: background-color 0.2s;
&:global(.twitch):not(:disabled) {
background-color: #9146FF;
color: #FFFFFF;
&:focus-visible,
&:hover {
background-color: #772ce8;
}
&:active {
background-color: #5b21b6;
}
}
&:global(.amogus):not(:disabled) {
background-color: #4CAF50;
color: #FFFFFF;
&:focus-visible,
&:hover {
background-color: #45a049;
}
&:active {
background-color: #388e3c;
}
}
}
</style>
7 changes: 7 additions & 0 deletions app/utils/dom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export function startViewTransition(callback: () => void) {
if (document.startViewTransition === undefined) {
callback()
} else {
document.startViewTransition(callback)
}
}

0 comments on commit 7d641da

Please sign in to comment.