2023-01-28 20:53:00 +00:00
|
|
|
<script setup lang="ts">
|
2024-03-01 18:08:14 +00:00
|
|
|
import type { ViewType } from "~~/composables/use-preferences";
|
|
|
|
import type { ItemSummary } from "~~/lib/api/types/data-contracts";
|
2024-03-01 01:20:18 +00:00
|
|
|
import MdiDotsVertical from "~icons/mdi/dots-vertical";
|
|
|
|
import MdiCardTextOutline from "~icons/mdi/card-text-outline";
|
|
|
|
import MdiTable from "~icons/mdi/table";
|
2023-01-28 20:53:00 +00:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
view?: ViewType;
|
|
|
|
items: ItemSummary[];
|
|
|
|
};
|
|
|
|
|
|
|
|
const preferences = useViewPreferences();
|
|
|
|
|
|
|
|
const props = defineProps<Props>();
|
|
|
|
const viewSet = computed(() => {
|
|
|
|
return !!props.view;
|
|
|
|
});
|
|
|
|
|
|
|
|
const itemView = computed(() => {
|
|
|
|
return props.view ?? preferences.value.itemDisplayView;
|
|
|
|
});
|
|
|
|
|
|
|
|
function setViewPreference(view: ViewType) {
|
|
|
|
preferences.value.itemDisplayView = view;
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<section>
|
2023-07-27 21:21:28 +00:00
|
|
|
<BaseSectionHeader class="mb-2 flex justify-between items-center">
|
2023-01-28 20:53:00 +00:00
|
|
|
Items
|
|
|
|
<template #description>
|
|
|
|
<div v-if="!viewSet" class="dropdown dropdown-hover dropdown-left">
|
|
|
|
<label tabindex="0" class="btn btn-ghost m-1">
|
2024-03-01 01:20:18 +00:00
|
|
|
<MdiDotsVertical class="h-7 w-7" />
|
2023-01-28 20:53:00 +00:00
|
|
|
</label>
|
|
|
|
<ul tabindex="0" class="dropdown-content menu p-2 shadow bg-base-100 rounded-box w-32">
|
|
|
|
<li>
|
|
|
|
<button @click="setViewPreference('card')">
|
2024-03-01 01:20:18 +00:00
|
|
|
<MdiCardTextOutline class="h-5 w-5" />
|
2023-01-28 20:53:00 +00:00
|
|
|
Card
|
|
|
|
</button>
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
<button @click="setViewPreference('table')">
|
2024-03-01 01:20:18 +00:00
|
|
|
<MdiTable class="h-5 w-5" />
|
2023-01-28 20:53:00 +00:00
|
|
|
Table
|
|
|
|
</button>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
</BaseSectionHeader>
|
|
|
|
|
|
|
|
<template v-if="itemView === 'table'">
|
|
|
|
<ItemViewTable :items="items" />
|
|
|
|
</template>
|
|
|
|
<template v-else>
|
|
|
|
<div class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-4">
|
|
|
|
<ItemCard v-for="item in items" :key="item.id" :item="item" />
|
2023-07-27 21:21:28 +00:00
|
|
|
<div class="first:block hidden text-lg">No Items to Display</div>
|
2023-01-28 20:53:00 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
</section>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<style scoped></style>
|