-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from sharknoon/account
Account
- Loading branch information
Showing
19 changed files
with
318 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<template> | ||
<ClientOnly> | ||
<div v-if="!authStore.isLoggedIn" class="dropdown"> | ||
<button | ||
class="btn btn-sm btn-outline-light dropdown-toggle" | ||
type="button" | ||
data-bs-toggle="dropdown" | ||
aria-expanded="false" | ||
> | ||
{{ $t("login") }} | ||
</button> | ||
<ul class="dropdown-menu dropdown-menu-end"> | ||
<li v-for="provider in authProviders" :key="provider.name"> | ||
<button class="dropdown-item" @click="loginWith(provider.name)"> | ||
{{ $t("login-with-provider", { provider: provider.displayName }) }} | ||
</button> | ||
</li> | ||
</ul> | ||
</div> | ||
|
||
<div v-if="authStore.isLoggedIn" class="dropdown"> | ||
<button | ||
class="btn btn-sm btn-outline-light dropdown-toggle" | ||
type="button" | ||
data-bs-toggle="dropdown" | ||
aria-expanded="false" | ||
> | ||
{{ authStore.user?.name }} | ||
</button> | ||
<ul class="dropdown-menu dropdown-menu-end"> | ||
<li> | ||
<button class="dropdown-item" @click="authStore.logout()"> | ||
{{ $t("logout") }} | ||
</button> | ||
</li> | ||
</ul> | ||
</div> | ||
<template #fallback> | ||
<button | ||
class="btn btn-sm btn-outline-light dropdown-toggle" | ||
type="button" | ||
aria-expanded="false" | ||
> | ||
{{ $t("loading") }} | ||
</button> | ||
</template> | ||
</ClientOnly> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
const authStore = useAuthStore(); | ||
const favoriteTilesStore = useFavoriteTilesStore(); | ||
onMounted(() => { | ||
authStore.refresh(); | ||
}); | ||
const authProviders = await authStore.authProviders; | ||
async function loginWith(provider: string) { | ||
try { | ||
const authData = await authStore.login(provider); | ||
// get local and cloud favorite tiles | ||
const localFavoriteTiles = favoriteTilesStore.favoriteTiles; | ||
let cloudFavoriteTiles: number[] = []; | ||
if (authData?.record?.favorite_tiles) { | ||
try { | ||
cloudFavoriteTiles = authData.record.favorite_tiles; | ||
} catch (error) { | ||
console.log("Failed to parse cloud favorite tiles: " + error); | ||
} | ||
} | ||
// merge local and cloud favorite tiles | ||
const mergedFavoriteTiles = Array.from( | ||
new Set([...localFavoriteTiles, ...cloudFavoriteTiles]), | ||
); | ||
// save merged favorite tiles | ||
favoriteTilesStore.favoriteTiles = mergedFavoriteTiles; | ||
} catch (error) { | ||
console.log("Login failed: " + error); | ||
} | ||
} | ||
</script> | ||
|
||
<style lang="scss" scoped> | ||
a { | ||
text-shadow: 0rem 0.25rem 0.75rem rgba(0, 0, 0, 0.95); | ||
svg { | ||
filter: drop-shadow(0rem 0.25rem 0.25rem rgba(0, 0, 0, 0.95)); | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import PocketBase from "pocketbase"; | ||
|
||
let pb: PocketBase | undefined = undefined; | ||
|
||
export default function () { | ||
if (!pb) { | ||
const runtimeConfig = useRuntimeConfig(); | ||
pb = new PocketBase(runtimeConfig.public.pocketbaseUrl); | ||
pb.autoCancellation(false); | ||
} | ||
|
||
return pb; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.