Skip to content

Commit

Permalink
fix: list grid
Browse files Browse the repository at this point in the history
  • Loading branch information
Barbapapazes authored Dec 1, 2023
1 parent b5c3487 commit 7ffd4ed
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 35 deletions.
2 changes: 1 addition & 1 deletion components/blog/BlogCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ defineProps<{
path: string
title: string
description: string
publishedAt: Date
publishedAt: string
authors: Author[]
}>()
</script>
Expand Down
16 changes: 1 addition & 15 deletions components/list/ListGrid.vue
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
<script lang="ts" setup generic="T extends { title: string }">
withDefaults(defineProps<{
items?: T[]
itemsNotFound?: string
}>(), {
itemsNotFound: 'No items found',
})
</script>

<template>
<ol class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4 lg:gap-8 place-items-stretch">
<li v-for="item in items" :key="item.title">
<slot :item="item" />
</li>
<li v-if="items && items.length === 0" class="col-span-1 md:col-span-2 xl:col-span-3 text-center">
{{ itemsNotFound }}
</li>
<slot />
</ol>
</template>
5 changes: 5 additions & 0 deletions components/list/ListGridEmpty.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<template>
<li class="col-span-1 md:col-span-2 xl:col-span-3 text-center">
<slot />
</li>
</template>
5 changes: 5 additions & 0 deletions components/list/ListGridItem.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<template>
<li>
<slot />
</li>
</template>
21 changes: 13 additions & 8 deletions pages/blog/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,19 @@ const results = sort(filtered)
</template>
</ListTopBar>

<ListGrid v-slot="{ item }" class="mt-8" :items="results" items-not-found="No articles found">
<BlogCard
:path="item._path!"
:title="item.title"
:description="item.description"
:published-at="item.publishedAt"
:authors="item.authors"
/>
<ListGrid class="mt-8">
<ListGridItem v-for="item in results" :key="item._path">
<BlogCard
:path="item._path!"
:title="item.title"
:description="item.description"
:published-at="item.publishedAt"
:authors="item.authors"
/>
</ListGridItem>
<ListGridEmpty v-if="results && results.length === 0">
No articles found
</ListGridEmpty>
</ListGrid>
</section>
</Main>
Expand Down
25 changes: 15 additions & 10 deletions pages/packages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,21 @@ const results = sort(searchResults)

<ListTopBar v-model:search="search" v-model:order="order" v-model:order-by="orderBy" search-placeholder="Search a package" :order-by-options="orderByOptions" />

<ListGrid v-slot="{ item }" class="mt-8" :items="results" items-not-found="No packages found">
<PackageCard
v-if="item.title && item.path"
:title="item.title"
:description="item.description"
:path="item.path"
:stars="item.stars"
:monthly-downloads="item.monthlyDownloads"
:contributors="item.contributors"
/>
<ListGrid class="mt-8">
<ListGridItem v-for="item in results" :key="item._path">
<PackageCard
v-if="item.title && item.path"
:title="item.title"
:description="item.description"
:path="item.path"
:stars="item.stars"
:monthly-downloads="item.monthlyDownloads"
:contributors="item.contributors"
/>
</ListGridItem>
<ListGridEmpty v-if="results && results.length === 0">
No packages found
</ListGridEmpty>
</ListGrid>
</section>
</Main>
Expand Down
2 changes: 1 addition & 1 deletion types/blog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export interface BlogPost extends ParsedContent {
authors: Author[]
categories: string[]
packages: string[]
publishedAt: Date
publishedAt: string
modifiedAt: Date
}

Expand Down

0 comments on commit 7ffd4ed

Please sign in to comment.