Files
archie/ui/src/App.vue
T

151 lines
8.1 KiB
Vue

<script setup lang="ts">
import { computed, nextTick, onBeforeUnmount, onMounted, ref, watch } from "vue";
import { errors } from "@/copy/errors";
import { START_LOCATION, useRoute, useRouter } from "vue-router";
import AccountEntry from "@/accounts/AccountEntry.vue";
import { useAccountsStore } from "@/accounts/accounts";
import ChatDock from "@/chat/ChatDock.vue";
import AlertsBell from "@/alerts/AlertsBell.vue";
import CommandPalette from "@/components/command-palette/CommandPalette.vue";
import AccountMenu from "@/components/topbar/AccountMenu.vue";
import OrgCrumb from "@/components/topbar/OrgCrumb.vue";
import ChatTopbarButton from "@/chat/ChatTopbarButton.vue";
import SectionCrumb from "@/components/topbar/SectionCrumb.vue";
import Brand from "@/components/topbar/Brand.vue";
import Logo from "@/components/topbar/Logo.vue";
import ConnectionPill from "@/components/topbar/ConnectionPill.vue";
import { Breadcrumb, BreadcrumbItem, BreadcrumbList, BreadcrumbPage, BreadcrumbSeparator } from "@/components/ui/breadcrumb";
import { Alert, AlertDescription } from "@/components/ui/alert";
import { Card } from "@/components/ui/card";
import { SidebarInset, SidebarProvider } from "@/components/ui/sidebar";
import NewTaskDialog from "@/tasks/NewTaskDialog.vue";
import SettingsShell from "@/settings/SettingsShell.vue";
import { TooltipProvider } from "@/components/ui/tooltip";
import { hiddenPaths } from "@/lib/nav";
import { loadTaskMeta } from "@/lib/task-meta";
import { useSessionStore } from "@/stores/session";
import { Toaster } from "vue-sonner";
import "vue-sonner/style.css";
const reauthenticate=new URLSearchParams(window.location.search).has("reauth");
const accounts=useAccountsStore();
const session = useSessionStore();
const route = useRoute();
const router = useRouter();
const workflowsPage = computed(() => route.name === "workflow");
const hidden = computed(() => hiddenPaths(session.sections));
const main = ref<HTMLElement | null>(null);
const newTaskOpen = ref(false);
// A page the caller may not open is not reachable by URL either: the nav drops
// it, so a bookmark or a chat link must not land on a form whose saves the
// control plane refuses.
watch([() => route.path, hidden], () => {
if (hidden.value.includes(typeof route.meta.navPath === "string" ? route.meta.navPath : route.path)) void router.replace("/");
});
watch(() => [route.path, accounts.instance], () => {
const scope = route.meta.org ? "Organisation" : route.meta.settings ? "Instance" : "";
document.title = [route.meta.label || errors.base.notFound.title, scope, "Archie", accounts.instance].filter(Boolean).join(" | ");
}, { immediate: true });
// A page load keeps focus at the top so the skip link is the first keyboard
// stop; later navigations move focus to the new page.
router.afterEach(async (to, from) => {
if (from === START_LOCATION || to.path === from.path) return;
await nextTick();
main.value?.focus({ preventScroll: true });
});
onMounted(() => {void accounts.load();});
// A failed startup read retries on an interval, so a proxy or daemon that
// comes back does not need a manual reload.
let retryTimer: ReturnType<typeof setInterval> | undefined;
watch(() => accounts.error, (message) => {
if (message && retryTimer === undefined) retryTimer = setInterval(() => void accounts.load(), 5000);
if (!message && retryTimer !== undefined) { clearInterval(retryTimer); retryTimer = undefined; }
});
onBeforeUnmount(() => { if (retryTimer !== undefined) clearInterval(retryTimer); });
watch(() => accounts.status?.user, (user) => {
if (!user || reauthenticate) return;
session.initialize();
// Asked for once, after the shell is up: the nav paints immediately and
// loses the entries this process cannot back a moment later, rather than
// holding the page behind a request. A failed read hides nothing.
void session.loadCapabilities();
// The lifecycle vocabulary -- status labels, pill severity, "needs you"
// grouping, and the operator actions -- is served by /api/task-meta. Asked
// for once, after the shell is up: the freeze-dried defaults paint
// immediately and this replaces them, so a catalogue change on the server
// reaches the browser without a UI release. loadTaskMeta never throws (a
// failed read keeps the defaults), so it needs no catch here.
void loadTaskMeta();
});
</script>
<template>
<main v-if="!accounts.status" class="mx-auto flex min-h-[90dvh] max-w-md flex-col justify-center px-5 py-10">
<Card class="gap-0 px-6 py-6 shadow-sm">
<div class="mb-2"><Logo /></div>
<template v-if="accounts.error">
<h1 class="text-title font-medium">{{ errors.app.unreachable }}</h1>
<Alert variant="destructive" class="mt-4"><AlertDescription>{{ accounts.error }}</AlertDescription></Alert>
<p class="text-caption mt-3 text-fg-muted">{{ errors.app.retrying }}</p>
</template>
<p v-else class="mt-2" role="status">Connecting to Archie…</p>
</Card>
</main>
<AccountEntry v-else-if="!accounts.status.user || accounts.status.setup_required || reauthenticate" />
<TooltipProvider v-else :delay-duration="350">
<SidebarProvider class="bg-[var(--workspace)]">
<a href="#main-content" class="sr-only focus:not-sr-only focus:fixed focus:top-2 focus:left-4 focus:z-[60] focus:rounded-md focus:bg-card focus:px-3 focus:py-2">Skip to main content</a>
<SidebarInset class="min-w-0 bg-[var(--workspace)] md:ml-[var(--chat-pin-l,0px)] md:mr-[var(--chat-pin-r,0px)]" :class="workflowsPage && 'max-md:h-dvh'">
<header class="bg-card border-border-strong sticky top-0 z-30 flex h-14 shrink-0 items-center gap-2 border-b px-3 shadow-[var(--shadow-sm)] sm:px-4">
<Brand />
<Breadcrumb class="max-md:min-w-0">
<BreadcrumbList class="flex-nowrap gap-1 sm:gap-1">
<BreadcrumbSeparator />
<BreadcrumbItem><OrgCrumb /></BreadcrumbItem>
<BreadcrumbSeparator />
<BreadcrumbItem><SectionCrumb :hidden="hidden" :link="route.name === 'workflow' ? '/workflows' : undefined" /></BreadcrumbItem>
<template v-if="route.name === 'workflow'">
<BreadcrumbSeparator class="max-md:hidden" />
<BreadcrumbItem class="min-w-0 max-md:hidden"><BreadcrumbPage class="truncate">{{ route.params.id }}</BreadcrumbPage></BreadcrumbItem>
</template>
</BreadcrumbList>
</Breadcrumb>
<div class="ml-auto flex shrink-0 items-center gap-4 max-sm:gap-1">
<ConnectionPill />
<CommandPalette :hidden="hidden" @new-task="newTaskOpen = true" />
<NewTaskDialog v-if="!hidden.includes('/workflows')" v-model:open="newTaskOpen" />
<ChatTopbarButton />
<AlertsBell />
<span><AccountMenu /></span>
</div>
</header>
<div id="main-content" ref="main" tabindex="-1" class="@container scroll-mt-16 w-full flex-1 px-6 py-5 pb-[calc(var(--chat-dock-clear,6rem)+1rem)] outline-none max-lg:p-4 max-lg:pb-[calc(var(--chat-dock-clear,6rem)+1rem)]"
:class="workflowsPage && 'max-md:flex max-md:min-h-0 max-md:flex-col'">
<!--
Keyed on the path and its parameters but not the query: a query-only
change is an entry state, so the page keeps the operator's filters,
while two different :id values get fresh instances -- without that
the second id diffs the first one in place and the previous task's
open tab stays open on the next.
-->
<RouterView v-slot="{ Component, route }">
<SettingsShell v-if="route.meta.settings" scope="instance">
<component :is="Component" :key="route.path" />
</SettingsShell>
<SettingsShell v-else-if="route.meta.org" scope="org">
<component :is="Component" :key="route.path" />
</SettingsShell>
<component :is="Component" v-else :key="route.path" />
</RouterView>
</div>
</SidebarInset>
<ChatDock />
</SidebarProvider>
<Toaster position="bottom-right" rich-colors close-button />
</TooltipProvider>
</template>