All files / apps/wp-editor/app/components ItemRail.vue

0% Statements 0/26
0% Branches 0/11
0% Functions 0/10
0% Lines 0/23

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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94                                                                                                                                                                                           
<template>
    <div class="flex h-full min-h-0 flex-col">
        <div class="border-b border-default p-3">
            <USelect v-model="filter" :items="filterItems" class="w-full" size="sm" />
        </div>
 
        <ul ref="list" class="min-h-0 flex-1 overflow-y-auto">
            <li v-for="item in visible" :key="item.key" :data-key="item.key">
                <button
                    type="button"
                    class="flex w-full gap-3 border-b border-default px-3 py-2.5 text-left transition-colors hover:bg-elevated/60"
                    :class="item.key === selected ? 'bg-elevated' : ''"
                    @click="emit('select', item.key)"
                >
                    <img
                        v-if="Iitem.base.image"
                        :src="item.base.image"
                        alt=""
                        class="size-12 shrink-0 rounded-md object-cover"
                    />
                    <div
                        v-else
                        class="flex size-12 shrink-0 items-center justify-center rounded-md bg-muted"
                    >
                        <UIcon name="i-lucide-file-text" class="size-5 text-dimmed" />
                    </div>
 
                    <div class="flex min-w-0 flex-1 flex-col gap-1">
                        <p class="line-clamp-2 text-sm font-medium">
                            {{ item.base.title || item.key }}
                        </p>
                        <p class="truncate text-xs text-muted">
                            {{ item.base.author }} ยท {{ formatDate(item.base.date) }}
                        </p>
                        <div class="flex items-center gap-1.5">
                            <UBadge v-bind="itemBadge(item)" variant="subtle" size="sm" />
                            <UTooltip
                                v-if="Iitem.proposal?.reviewRequested"
                                :text="item.proposal.reviewRequested"
                            >
                                <UIcon
                                    name="i-lucide-flag"
                                    class="size-3.5 text-warning"
                                    aria-label="Review requested"
                                />
                            </UTooltip>
                            <span class="text-xs text-dimmed">{{ item.key }}</span>
                        </div>
                    </div>
                </button>
            </li>
        </ul>
 
        <UEmpty
            v-if="Ivisible.length === 0"
            icon="i-lucide-filter-x"
            title="Nothing in this filter"
            class="flex-1"
        />
    </div>
</template>
 
<script setup lang="ts">
import type { Item } from "#shared/types/Item.ts";
import type { ItemKey } from "#shared/types/ItemKey.ts";
 
interface Props {
    items: Item[];
    selected: ItemKey | undefined;
}
 
const props = defineProps<Props>();
const emit = defineEmits<{ select: [key: ItemKey] }>();
const filter = defineModel<ItemFilter>("filter", { required: true });
const filterItems = computed(() =>
    ITEM_FILTERS.map((value) => ({
        label: `${value} (${props.items.filter((item) => matchesFilter(item, value)).length})`,
        value,
    })),
);
 
const visible = computed(() => props.items.filter((item) => matchesFilter(item, filter.value)));
 
const list = useTemplateRef<HTMLElement>("list");
 
watch(
    () => props.selected,
    async (key) => {
        await nextTick();
        list.value?.querySelector(`[data-key="${key}"]`)?.scrollIntoView({ block: "nearest" });
    },
);
</script>