Skip to content

Commit

Permalink
Merge pull request #44 from sharknoon/account
Browse files Browse the repository at this point in the history
Account
  • Loading branch information
sharknoon authored Nov 19, 2024
2 parents 71a5416 + 892eb02 commit cf85eba
Show file tree
Hide file tree
Showing 19 changed files with 318 additions and 104 deletions.
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
# npx onedrive-link <your-shared-onedrive-link>
NUXT_EXCEL_POLL_URL=https://api.onedrive.com/v1.0/shares/<id>/root/content
NUXT_PUBLIC_PIXELHOBBY_TILE_ID=35007450218648
NUXT_EXCEL_POLL_INTERVAL_MS=86400000
NUXT_EXCEL_POLL_INTERVAL_MS=86400000
NUXT_PUBLIC_POCKETBASE_URL=https://some-pocketbase.com
2 changes: 1 addition & 1 deletion components/common/TileThumbnail.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<div
class="tile-thumbnail position-relative shadow-sm rounded"
:id="'tile-' + tile?.number"
class="tile-thumbnail position-relative shadow-sm rounded"
style="--bs-aspect-ratio: 80%"
>
<img
Expand Down
96 changes: 96 additions & 0 deletions components/layout/LoginButton.vue
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>
12 changes: 6 additions & 6 deletions components/templates/TileList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
@click.stop="toggleTileFavorite(tile)"
>
<svg
v-if="favoriteTileStore.favoriteTiles.includes(tile)"
v-if="favoriteTilesStore.favoriteTiles.includes(tile)"
xmlns="http://www.w3.org/2000/svg"
class="text-warning"
style="height: 1.5rem; width: 1.5rem"
Expand Down Expand Up @@ -118,7 +118,7 @@
import type { Progress } from "~/types/progress";
const router = useRouter();
const favoriteTileStore = useFavoriteTilesStore();
const favoriteTilesStore = useFavoriteTilesStore();
const { status, data } = await useLazyFetch<Progress>("/api/v1/progress");
const props = defineProps({
Expand All @@ -135,15 +135,15 @@ const tiles = ref<number[]>([]);
if (props.filter === "favorites") {
onMounted(() => {
watch(
favoriteTileStore,
favoriteTilesStore,
() => {
tiles.value = favoriteTileStore.favoriteTiles
tiles.value = favoriteTilesStore.favoriteTiles
.concat() // basically copies the array
.sort(function (tileA, tileB) {
return tileA - tileB;
});
},
{ immediate: true }
{ immediate: true },
);
});
} else {
Expand All @@ -155,7 +155,7 @@ if (props.filter === "favorites") {
}
function toggleTileFavorite(number: number) {
favoriteTileStore.toggleFavoriteTile(number);
favoriteTilesStore.toggleFavoriteTile(number);
}
function openTile(number: number) {
Expand Down
6 changes: 3 additions & 3 deletions components/templates/number/FavoriteButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<ClientOnly>
<button class="btn btn-dark px-2" @click="toggleFavorite()">
<svg
v-if="store.isFavorite(props.tileNumber)"
v-if="favoriteTilesStore.isFavorite(props.tileNumber)"
xmlns="http://www.w3.org/2000/svg"
style="height: 1.5rem; width: 1.5rem"
viewBox="0 0 20 20"
Expand Down Expand Up @@ -49,7 +49,7 @@
</ClientOnly>
</template>
<script setup lang="ts">
const store = useFavoriteTilesStore();
const favoriteTilesStore = useFavoriteTilesStore();
const props = defineProps({
tileNumber: {
Expand All @@ -59,6 +59,6 @@ const props = defineProps({
});
function toggleFavorite() {
store.toggleFavoriteTile(props.tileNumber);
favoriteTilesStore.toggleFavoriteTile(props.tileNumber);
}
</script>
13 changes: 13 additions & 0 deletions composables/usePocketBase.ts
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;
}
6 changes: 5 additions & 1 deletion i18n/locales/de-DE.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@
"add-to-cart": "Zum Warenkorb hinzufügen",
"invalid-cookie": "Bitte gebe einen gültigen Warenkorb-Cookie-Wert an.",
"donate": "Spenden",
"login": "Anmelden",
"logout": "Abmelden",
"tiles": "Platten",
"finished": "Fertiggestellt",
"in-progress": "In Arbeit",
Expand All @@ -115,5 +117,7 @@
"page-not-found-explanation": "Diese Seite konnte leider nicht gefunden werden. Bitte überprüfe die URL oder kehre zur Startseite zurück.",
"error-occured": "Ein Fehler ist aufgetreten",
"error-explanation": "Dieser Fehler sollte nicht passieren. Bitte gebe Josua Bescheid, damit er den Fehler beheben kann (frank.josua{'@'}gmail.com). Danke!",
"go-back-home": "Zur Startseite"
"go-back-home": "Zur Startseite",
"loading": "Laden...",
"login-with-provider": "Mit {provider} anmelden"
}
6 changes: 5 additions & 1 deletion i18n/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@
"add-to-cart": "Add to Cart",
"invalid-cookie": "Please enter a valid cart cookie.",
"donate": "Donate",
"login": "Login",
"logout": "Logout",
"tiles": "tiles",
"finished": "Finished",
"in-progress": "In progress",
Expand All @@ -115,5 +117,7 @@
"page-not-found-explanation": "This page could not be found. Please check the URL or go back to the home page.",
"error-occured": "An error occurred",
"error-explanation": "This error should not have occured. Please report this error to Josua Frank (frank.josua{'@'}gmail.com) to fix this issue.",
"go-back-home": "Home page"
"go-back-home": "Home page",
"loading": "Loading...",
"login-with-provider": "Login with {provider}"
}
22 changes: 14 additions & 8 deletions layouts/default.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@
</NuxtLink>
</nav>
<div class="mt-auto d-grid gap-2">
<NuxtLink to="/privacy" class="link-light link-underline-opacity-0">{{
$t("privacy")
}}</NuxtLink>
<div class="d-flex justify-content-between align-items-center">
<NuxtLink to="/privacy" class="link-light link-underline-opacity-0">{{
$t("privacy")
}}</NuxtLink>
<LayoutLoginButton />
</div>
<LayoutDonationButton />
<LayoutLanguageDropdown class="d-grid" />
</div>
Expand Down Expand Up @@ -117,11 +120,14 @@
</li>
</ul>
<div class="d-grid gap-2">
<NuxtLink
to="/privacy"
class="link-light link-underline-opacity-0"
>{{ $t("privacy") }}</NuxtLink
>
<div class="d-flex justify-content-between align-items-center">
<NuxtLink
to="/privacy"
class="link-light link-underline-opacity-0"
>{{ $t("privacy") }}</NuxtLink
>
<LayoutLoginButton />
</div>
<LayoutDonationButton />
<LayoutLanguageDropdown class="d-grid" />
</div>
Expand Down
1 change: 1 addition & 0 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default defineNuxtConfig({

public: {
pixelhobbyTileId: 35007450218648, // can be overwritten by NUXT_PUBLIC_PIXELHOBBY_TILE_ID environment variable
pocketbaseUrl: "", // can be overwritten by NUXT_PUBLIC_POCKETBASE_URL environment variable
},
},

Expand Down
Loading

0 comments on commit cf85eba

Please sign in to comment.