All files / apps/developer-portal/layers/wiki/app/components WikiRecent.vue

100% Statements 17/17
75% Branches 6/8
100% Functions 9/9
100% Lines 16/16

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60  5x   5x 2x               3x 5x     3x           3x 2x 2x                                   2x   5x   5x 5x 6x 1x   3x                
<template>
    <UCard variant="flush">
        <template #header>
            <h2 class="font-semibold">{{ $t("wikiRecent.title") }}</h2>
            <p class="mt-1 text-xs text-muted">{{ $t("wikiRecent.note") }}</p>
        </template>
 
        <EmptyState v-if="recent.length === 0">
            <I18nT keypath="wikiRecent.empty" scope="global">
                <template #command>
                    <code class="font-mono">{{ COLLECT }}</code>
                </template>
            </I18nT>
        </EmptyState>
 
        <div v-else class="divide-y divide-default">
            <NuxtLink
                v-for="page in recent"
                :key="page.path"
                :to="page.to"
                class="flex items-center gap-3 px-4 py-2 transition-colors hover:bg-elevated/50"
            >
                <UIcon :name="page.icon" class="size-3.5 shrink-0 text-dimmed" />
                <span class="flex-1 truncate font-mono text-xs">{{ page.path }}</span>
                <span class="shrink-0 text-xs text-dimmed">{{ page.updated }}</span>
            </NuxtLink>
        </div>
    </UCard>
</template>
 
<script setup lang="ts">
import { toCollectionPath } from "#layers/docs/shared/docPages.ts";
import type { DocPage } from "#layers/snapshot/shared/types/DocPage.ts";
 
interface Props {
    pages: DocPage[];
    /** Every path in the wiki tree, so a file the tree leaves out isn't listed. */
    known: Set<string>;
}
 
const { pages, known } = defineProps<Props>();
 
const COLLECT = "pnpm exec nx collect @joinery/developer-portal";
 
const { t } = useI18n();
 
const recent = computed(() =>
    pages
        .filter((page) => page.updatedAt !== null && known.has(toCollectionPath(page.path)))
        .sort((a, b) => (b.updatedAt ?? "").localeCompare(a.updatedAt ?? ""))
        .slice(0, 8)
        .map((page) => ({
            path: page.path,
            to: `/wiki${toCollectionPath(page.path)}`,
            icon: kindIcon(page.kind),
            updated: relativeTime(page.updatedAt, t),
        })),
);
</script>