frontend/app.vue

120 lines
3.3 KiB
Vue
Raw Normal View History

<template>
2024-05-12 09:30:02 +02:00
<NuxtPwaAssets />
2024-05-12 11:23:38 +02:00
<PwaTransparentImage image="/logo.webp" />
<PwaAppleImage image="/logo.webp" />
<PwaMaskableImage image="/logo.webp" />
<Loading />
<ClientOnly>
<NuxtLayout>
<NuxtPage />
</NuxtLayout>
</ClientOnly>
<NotificationsRenderer />
<noscript>
<ErrorsNoscript />
</noscript>
</template>
<script setup lang="ts">
2024-05-12 08:13:35 +02:00
import { convert } from "html-to-text";
import "iconify-icon";
import { nanoid } from "nanoid";
// Use SSR-safe IDs for Headless UI
provideHeadlessUseId(() => useId());
const code = useRequestURL().searchParams.get("code");
const appData = useAppData();
const identity = useCurrentIdentity();
const identities = useIdentities();
const client = useClient();
const instance = useInstance();
2024-05-12 08:13:35 +02:00
const description = useExtendedDescription(client);
2024-05-12 08:13:35 +02:00
useSeoMeta({
titleTemplate: (titleChunk) => {
return titleChunk ? `${titleChunk} · Lysand` : "Lysand";
},
title: computed(() => instance.value?.title ?? ""),
ogImage: computed(() => instance.value?.banner.url),
2024-05-12 08:13:35 +02:00
twitterTitle: computed(() => instance.value?.title ?? ""),
twitterDescription: computed(() =>
convert(description.value?.content ?? ""),
),
twitterImage: computed(() => instance.value?.banner.url),
2024-05-12 08:13:35 +02:00
description: computed(() => convert(description.value?.content ?? "")),
ogDescription: computed(() => convert(description.value?.content ?? "")),
ogSiteName: "Lysand",
colorScheme: "dark",
2024-05-12 09:30:02 +02:00
themeColor: "#f9a8d4",
2024-05-12 08:13:35 +02:00
});
useHead({
htmlAttrs: {
lang: "en",
},
});
if (code) {
if (appData.value) {
client.value
?.fetchAccessToken(
appData.value.client_id,
appData.value.client_secret,
code,
new URL("/", useRequestURL().origin).toString(),
)
.then(async (res) => {
const tempClient = useClient(res.data).value;
const [accountOutput, instanceOutput] = await Promise.all([
tempClient.verifyAccountCredentials(),
tempClient.getInstance(),
]);
// Get account data
if (
!identities.value.find(
(i) => i.account.id === accountOutput.data.id,
)
)
identity.value = {
id: nanoid(),
tokens: res.data,
account: accountOutput.data,
instance: instanceOutput.data,
permissions: [],
emojis: [],
};
// Remove code from URL
window.history.replaceState(
{},
document.title,
window.location.pathname,
);
// Redirect to home
window.location.pathname = "/";
});
}
}
useListen("identity:change", (newIdentity) => {
identity.value = newIdentity;
window.location.pathname = "/";
});
useCacheRefresh(client);
</script>
<style>
@import url("overlayscrollbars/overlayscrollbars.css");
body {
font-family: Inter, sans-serif;
}
.os-scrollbar .os-scrollbar-handle {
background: #9999;
}
</style>