Pages can be starred from their header; favorites show in the sidebar above the spaces, and Home lists the pages visited last. Both are per user and per workspace, and are filtered by the caller's current rights, so pages that moved out of reach or into the trash drop out. Visits are trimmed to the newest 50 per workspace. The icon set gains the glyphs the rest of Phase 1 needs, and DwIcon can draw a filled variant for on/off states. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
96 lines
4.3 KiB
Vue
96 lines
4.3 KiB
Vue
<!-- SPDX-License-Identifier: AGPL-3.0-or-later -->
|
|
<script setup lang="ts">
|
|
import type { PageItem } from "@docwell/api-client";
|
|
import { DwBadge, DwCallout, DwIcon } from "@docwell/ui";
|
|
import { computed, onMounted, ref, watch } from "vue";
|
|
import { useApi } from "../api";
|
|
import { useAuthStore } from "../stores/auth";
|
|
import { useSpacesStore } from "../stores/spaces";
|
|
import { atLeast, useWorkspacesStore } from "../stores/workspaces";
|
|
|
|
const auth = useAuthStore();
|
|
const workspaces = useWorkspacesStore();
|
|
const spaces = useSpacesStore();
|
|
const api = useApi();
|
|
const ws = computed(() => workspaces.current);
|
|
onMounted(() => (spaces.active = { space: "", page: "" }));
|
|
|
|
const recent = ref<PageItem[]>([]);
|
|
watch(
|
|
() => ws.value?.id,
|
|
async (id) => {
|
|
recent.value = [];
|
|
if (id) recent.value = await api.workspaces.recent(id, 8).catch(() => []);
|
|
},
|
|
{ immediate: true },
|
|
);
|
|
</script>
|
|
|
|
<template>
|
|
<article class="mx-auto max-w-doc-wide px-4 pt-6 pb-16 sm:px-16 sm:pt-10">
|
|
<div class="flex items-center gap-3">
|
|
<DwIcon name="drop" :size="28" class="text-spring" />
|
|
<h1 class="font-serif text-doc-h1">{{ ws?.name ?? $t("app.name") }}</h1>
|
|
</div>
|
|
<p v-if="ws" class="mt-2 text-ui-md text-ink-muted">
|
|
{{ $t("workspace.yourRole", { role: $t(`workspace.roles.${ws.role}`), org: ws.organizationName }) }}
|
|
</p>
|
|
<DwCallout v-else-if="workspaces.loaded" class="mt-6" size="ui">
|
|
{{ $t(auth.user?.organization || auth.user?.role === "superadmin" ? "sidebar.noWorkspaces" : "sidebar.noOrg") }}
|
|
</DwCallout>
|
|
|
|
<template v-if="ws">
|
|
<section v-if="recent.length" class="mt-10" data-testid="recent">
|
|
<h2 class="dw-label">{{ $t("home.recent") }}</h2>
|
|
<ul class="mt-3 grid gap-2 sm:grid-cols-2">
|
|
<li v-for="p in recent" :key="p.id">
|
|
<RouterLink
|
|
:to="{ name: 'page', params: { id: p.id } }"
|
|
class="flex items-center gap-3 rounded-sm border border-line bg-surface-raised px-3 py-2 hover:border-line-strong"
|
|
>
|
|
<span v-if="p.icon" class="w-5 shrink-0 text-center">{{ p.icon }}</span>
|
|
<DwIcon v-else name="page" :size="18" class="text-ink-muted" />
|
|
<span class="min-w-0 flex-1">
|
|
<span class="block truncate text-ui-md font-medium text-ink">{{ p.title || $t("home.untitled") }}</span>
|
|
<span class="block truncate text-ui-sm text-ink-muted">{{ p.spaceName }}</span>
|
|
</span>
|
|
</RouterLink>
|
|
</li>
|
|
</ul>
|
|
</section>
|
|
|
|
<div class="mt-10 flex items-center justify-between gap-2">
|
|
<h2 class="dw-label">{{ $t("sidebar.spaces") }}</h2>
|
|
<RouterLink
|
|
v-if="atLeast(ws.role, 'admin')"
|
|
:to="{ name: 'new-space', params: { id: ws.id } }"
|
|
class="inline-flex h-control-sm items-center gap-1 rounded-sm px-2 text-ui-sm font-semibold text-ink-muted hover:bg-surface-hover hover:text-ink"
|
|
>
|
|
<DwIcon name="plus" :size="16" />{{ $t("space.new") }}
|
|
</RouterLink>
|
|
</div>
|
|
<ul class="mt-3 grid gap-3 sm:grid-cols-2 lg:grid-cols-3" data-testid="space-cards">
|
|
<li v-for="s in spaces.items" :key="s.id">
|
|
<RouterLink
|
|
:to="{ name: 'space', params: { id: s.id } }"
|
|
class="flex h-full flex-col rounded-md border border-line bg-surface-raised p-4 transition-colors duration-[120ms] hover:border-line-strong"
|
|
>
|
|
<span class="flex items-center gap-2 text-ui-lg text-ink">
|
|
<span class="truncate">{{ s.icon ? `${s.icon} ` : "" }}{{ s.name }}</span>
|
|
</span>
|
|
<span v-if="s.description" class="mt-1 line-clamp-2 text-ui-md text-ink-muted">{{ s.description }}</span>
|
|
<span class="mt-auto flex flex-wrap items-center gap-2 pt-3 text-ui-sm text-ink-muted">
|
|
{{ $t("space.pageCount", { n: spaces.trees[s.id]?.length ?? 0 }, spaces.trees[s.id]?.length ?? 0) }}
|
|
<DwBadge v-if="s.visibility === 'private'">{{ $t("space.private") }}</DwBadge>
|
|
<DwBadge tone="accent">{{ $t(`space.roles.${s.role}`) }}</DwBadge>
|
|
</span>
|
|
</RouterLink>
|
|
</li>
|
|
</ul>
|
|
<DwCallout v-if="spaces.loaded && !spaces.items.length" class="mt-3" size="ui">
|
|
{{ atLeast(ws.role, "admin") ? $t("space.noneAdmin") : $t("space.none") }}
|
|
</DwCallout>
|
|
</template>
|
|
</article>
|
|
</template>
|