frontend/app.vue

122 lines
5.7 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 />
</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",
},
noscript: [
{
innerHTML: `<div class="grid min-h-screen place-items-center px-6 py-24 sm:py-32 lg:px-8 fixed inset-0 z-[1000000] bg-dark-900" data-v-inspector="components/errors/noscript.vue:2:5"><svg class="absolute inset-0 h-full w-full stroke-white/10 [mask-image:radial-gradient(100%_100%_at_top_right,white,transparent)]" aria-hidden="true" data-v-inspector="components/graphics/square-pattern.vue:2:5"><defs data-v-inspector="components/graphics/square-pattern.vue:4:9"><pattern id="983e3e4c-de6d-4c3f-8d64-b9761d1534cc" width="200" height="200" x="50%" y="-1" patternUnits="userSpaceOnUse" data-v-inspector="components/graphics/square-pattern.vue:5:13"><path d="M.5 200V.5H200" fill="none" data-v-inspector="components/graphics/square-pattern.vue:7:17"></path></pattern></defs><svg x="50%" y="-1" class="overflow-visible fill-gray-800/20" data-v-inspector="components/graphics/square-pattern.vue:9:16"><path d="M-200 0h201v201h-201Z M600 0h201v201h-201Z M-400 600h201v201h-201Z M200 800h201v201h-201Z" stroke-width="0" data-v-inspector="components/graphics/square-pattern.vue:10:13"></path></svg><rect width="100%" height="100%" stroke-width="0" fill="url(#983e3e4c-de6d-4c3f-8d64-b9761d1534cc)" data-v-inspector="components/graphics/square-pattern.vue:13:9"></rect></svg><div class="prose prose-invert max-w-lg" data-v-inspector="components/errors/noscript.vue:4:9"><h1 class="mt-4 text-3xl font-bold tracking-tight text-gray-100 sm:text-5xl" data-v-inspector="components/errors/noscript.vue:5:13">JavaScript is disabled </h1><p class="mt-6 text-base leading-7 text-gray-400" data-v-inspector="components/errors/noscript.vue:7:13"> This website requires JavaScript to function properly. Please enable JavaScript in your browser settings. </p><p class="mt-6 text-base leading-7 text-gray-400" data-v-inspector="components/errors/noscript.vue:11:13"> If you are using a browser that does not support JavaScript, please consider using a modern browser like <a href="https://www.mozilla.org/firefox/new/" class="underline" data-v-inspector="components/errors/noscript.vue:13:22">Firefox</a> or <a href="https://www.google.com/chrome/" class="underline" data-v-inspector="components/errors/noscript.vue:13:102">Chrome</a>. </p><p class="mt-6 text-base leading-7 text-gray-400" data-v-inspector="components/errors/noscript.vue:16:13"> This application does not track you, collect user data, use cookies of any kind or send requests to servers outside of your account&#39;s instance. </p></div></div>`,
},
],
2024-05-12 08:13:35 +02:00
});
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>