UI updates for item card

This commit is contained in:
Hayden 2022-12-30 22:06:45 -09:00
parent 149f16a600
commit d26118a515
No known key found for this signature in database
GPG key ID: 17CF79474E257545
7 changed files with 126 additions and 101 deletions

View file

@ -72,11 +72,13 @@ github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovk
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ= github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
github.com/mattn/go-sqlite3 v1.14.16 h1:yOQRA0RpS5PFz/oikGwBEqvAWhWg5ufRz4ETLjwpU1Y= github.com/mattn/go-sqlite3 v1.14.16 h1:yOQRA0RpS5PFz/oikGwBEqvAWhWg5ufRz4ETLjwpU1Y=
github.com/mattn/go-sqlite3 v1.14.16/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg= github.com/mattn/go-sqlite3 v1.14.16/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
github.com/mitchellh/go-wordwrap v1.0.1 h1:TLuKupo69TCn6TQSyGxwI1EblZZEsQ0vMlAFQflz0v0= github.com/mitchellh/go-wordwrap v1.0.1 h1:TLuKupo69TCn6TQSyGxwI1EblZZEsQ0vMlAFQflz0v0=
github.com/mitchellh/go-wordwrap v1.0.1/go.mod h1:R62XHJLzvMFRBbcrT7m7WgmE1eOyTSsCt+hzestvNj0= github.com/mitchellh/go-wordwrap v1.0.1/go.mod h1:R62XHJLzvMFRBbcrT7m7WgmE1eOyTSsCt+hzestvNj0=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
@ -88,6 +90,8 @@ github.com/rs/xid v1.4.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/rs/zerolog v1.28.0 h1:MirSo27VyNi7RJYP3078AA1+Cyzd2GB66qy3aUHvsWY= github.com/rs/zerolog v1.28.0 h1:MirSo27VyNi7RJYP3078AA1+Cyzd2GB66qy3aUHvsWY=
github.com/rs/zerolog v1.28.0/go.mod h1:NILgTygv/Uej1ra5XxGf82ZFSLk58MFGAUS2o6usyD0= github.com/rs/zerolog v1.28.0/go.mod h1:NILgTygv/Uej1ra5XxGf82ZFSLk58MFGAUS2o6usyD0=
github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ= github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=
github.com/spf13/cobra v1.6.1 h1:o94oiPyS4KD1mPy2fmcYYHHfCxLqYjJOhGsCHFZtEzA=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=

View file

@ -1,43 +1,42 @@
<template> <template>
<NuxtLink <NuxtLink class="group card rounded-md" :to="`/item/${item.id}`">
class="group card bg-neutral text-neutral-content hover:bg-primary transition-colors duration-300" <div class="rounded-t flex flex-col bg-neutral text-neutral-content p-5">
:to="`/item/${item.id}`" <h2 class="text-base mb-4 last:mb-0 font-bold two-line min-h-[48px]">{{ item.name }}</h2>
> <NuxtLink
<div class="card-body p-4 gap-3"> v-if="item.location"
<h2 class="card-title"> class="inline-flex text-sm items-center hover:link"
{{ item.name }} :to="`/location/${item.location.id}`"
<Icon v-if="item.archived" class="ml-auto" name="mdi-archive-outline" /> >
<Icon v-else class="ml-auto" name="mdi-package-variant" /> <Icon name="heroicons-map-pin" class="mr-1 h-4 w-4"></Icon>
</h2> <span>
<div v-if="colOne" class="flex gap-x-2 items-center justify-between">
<NuxtLink
v-if="item.location"
class="badge badge-primary group-hover:badge-ghost"
:to="`/location/${item.location.id}`"
>
<Icon name="heroicons-map-pin" class="mr-2 swap-on"></Icon>
{{ item.location.name }} {{ item.location.name }}
</NuxtLink> </span>
<div class="flex gap-2 ml-auto items-end"> </NuxtLink>
<div v-if="item.purchasePrice" class="tooltip" data-tip="Purchase Price"> </div>
<span class="badge badge-ghost"> <div class="rounded-b p-4 flex-grow col-span-4 flex flex-col gap-y-2 bg-base-100">
<Currency :amount="item.purchasePrice" /> <div class="flex justify-between gap-2">
</span> <div class="mr-auto tooltip" data-tip="Purchase Price">
</div> <span class="badge badge-sm badge-ghost h-5">
<div v-if="item.insured" class="tooltip" data-tip="Insured"> <Currency :amount="item.purchasePrice" />
<Icon class="h-5 w-5 text-base-200" name="mdi-shield-check" /> </span>
</div> </div>
<div v-if="item.quantity > 1" class="tooltip" data-tip="Quantity"> <div v-if="item.createdAt" class="tooltip z-10" :data-tip="datetime">
<span class="badge badge-ghost"> <Icon class="h-5 w-5 text-primary" name="mdi-calendar" />
{{ item.quantity }} </div>
</span> <div v-if="item.insured" class="tooltip z-10" data-tip="Insured">
</div> <Icon class="h-5 w-5 text-primary" name="mdi-shield-check" />
</div>
<div v-if="item.quantity > 1" class="tooltip" data-tip="Quantity">
<span class="badge h-5 w-5 badge-primary badge-sm text-xs">
{{ item.quantity }}
</span>
</div> </div>
</div> </div>
<span <p class="mb-2 text-clip three-line">
class="w-[100%] group-hover:bg-neutral-content h-[3px] transition-colors duration-300 rounded-box bg-primary" {{ item.description }}
></span> </p>
<div class="flex gap-2 flex-wrap justify-end">
<div class="flex gap-2 flex-wrap -mr-1 mt-auto justify-end">
<LabelChip v-for="label in top3" :key="label.id" :label="label" size="sm" /> <LabelChip v-for="label in top3" :key="label.id" :label="label" size="sm" />
</div> </div>
</div> </div>
@ -47,14 +46,14 @@
<script setup lang="ts"> <script setup lang="ts">
import { ItemOut, ItemSummary } from "~~/lib/api/types/data-contracts"; import { ItemOut, ItemSummary } from "~~/lib/api/types/data-contracts";
const colOne = computed(() => {
return props.item.location || props.item.purchasePrice;
});
const top3 = computed(() => { const top3 = computed(() => {
return props.item.labels.slice(0, 3) || []; return props.item.labels.slice(0, 3) || [];
}); });
const datetime = computed(() => {
return "Created " + fmtDate(props.item.createdAt, "human");
});
const props = defineProps({ const props = defineProps({
item: { item: {
type: Object as () => ItemOut | ItemSummary, type: Object as () => ItemOut | ItemSummary,
@ -62,3 +61,23 @@
}, },
}); });
</script> </script>
<style lang="css">
.three-line {
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 3;
line-clamp: 3;
-webkit-box-orient: vertical;
}
.two-line {
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 2;
line-clamp: 2;
-webkit-box-orient: vertical;
}
</style>

View file

@ -5,64 +5,6 @@
<script setup lang="ts"> <script setup lang="ts">
type DateTimeFormat = "relative" | "long" | "short" | "human"; type DateTimeFormat = "relative" | "long" | "short" | "human";
function ordinalIndicator(num: number) {
if (num > 3 && num < 21) return "th";
switch (num % 10) {
case 1:
return "st";
case 2:
return "nd";
case 3:
return "rd";
default:
return "th";
}
}
const months = [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December",
];
const value = computed(() => {
if (!props.date) {
return "";
}
const dt = typeof props.date === "string" ? new Date(props.date) : props.date;
if (!dt) {
return "";
}
if (!validDate(dt)) {
return "";
}
switch (props.format) {
case "relative":
return useTimeAgo(dt).value + useDateFormat(dt, " (MM-DD-YYYY)").value;
case "long":
return useDateFormat(dt, "MM-DD-YYYY (dddd)").value;
case "short":
return useDateFormat(dt, "MM-DD-YYYY").value;
case "human":
// January 1st, 2021
return `${months[dt.getMonth()]} ${dt.getDate()}${ordinalIndicator(dt.getDate())}, ${dt.getFullYear()}`;
default:
return "";
}
});
const props = defineProps({ const props = defineProps({
date: { date: {
type: [Date, String], type: [Date, String],
@ -73,4 +15,8 @@
default: "relative", default: "relative",
}, },
}); });
const value = computed(() => {
return fmtDate(props.date, props.format);
});
</script> </script>

View file

@ -19,3 +19,59 @@ export async function useFormatCurrency() {
return (value: number | string) => fmtCurrency(value, cache.currency); return (value: number | string) => fmtCurrency(value, cache.currency);
} }
export type DateTimeFormat = "relative" | "long" | "short" | "human";
function ordinalIndicator(num: number) {
if (num > 3 && num < 21) return "th";
switch (num % 10) {
case 1:
return "st";
case 2:
return "nd";
case 3:
return "rd";
default:
return "th";
}
}
export function fmtDate(value: string | Date, fmt: DateTimeFormat = "human"): string {
const months = [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December",
];
const dt = typeof value === "string" ? new Date(value) : value;
if (!dt) {
return "";
}
if (!validDate(dt)) {
return "";
}
switch (fmt) {
case "relative":
return useTimeAgo(dt).value + useDateFormat(dt, " (MM-DD-YYYY)").value;
case "long":
return useDateFormat(dt, "MM-DD-YYYY (dddd)").value;
case "short":
return useDateFormat(dt, "MM-DD-YYYY").value;
case "human":
// January 1st, 2021
return `${months[dt.getMonth()]} ${dt.getDate()}${ordinalIndicator(dt.getDate())}, ${dt.getFullYear()}`;
default:
return "";
}
}

View file

@ -158,7 +158,7 @@
</BaseCard> </BaseCard>
<section class="mt-10"> <section class="mt-10">
<BaseSectionHeader class="mb-5"> Items </BaseSectionHeader> <BaseSectionHeader class="mb-5"> Items </BaseSectionHeader>
<div class="grid grid-cols-1 sm:grid-cols-2 gap-4"> <div class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-4">
<TransitionGroup name="list"> <TransitionGroup name="list">
<ItemCard v-for="item in results" :key="item.id" :item="item" /> <ItemCard v-for="item in results" :key="item.id" :item="item" />
</TransitionGroup> </TransitionGroup>

View file

@ -157,7 +157,7 @@
<section v-if="label"> <section v-if="label">
<BaseSectionHeader class="mb-5"> Items </BaseSectionHeader> <BaseSectionHeader class="mb-5"> Items </BaseSectionHeader>
<div class="grid gap-2 grid-cols-1 sm:grid-cols-2"> <div class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-4">
<ItemCard v-for="item in label.items" :key="item.id" :item="item" /> <ItemCard v-for="item in label.items" :key="item.id" :item="item" />
</div> </div>
</section> </section>

View file

@ -180,7 +180,7 @@
<section v-if="location && location.items.length > 0"> <section v-if="location && location.items.length > 0">
<BaseSectionHeader class="mb-5"> Items </BaseSectionHeader> <BaseSectionHeader class="mb-5"> Items </BaseSectionHeader>
<div class="grid gap-2 grid-cols-1 sm:grid-cols-2"> <div class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-4">
<ItemCard v-for="item in location.items" :key="item.id" :item="item" /> <ItemCard v-for="item in location.items" :key="item.id" :item="item" />
</div> </div>
</section> </section>