Skip to content

Commit

Permalink
feat(Bookmark): ✨ Pagination / Caching
Browse files Browse the repository at this point in the history
  • Loading branch information
bKoZii committed Sep 15, 2024
1 parent b30e08a commit 24ce5ad
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions pages/Bookmarks.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,41 @@
<PageHeader title="Bookmarks" description="รวมเว็บไซต์แนว IT, Linux, Tutorials และเว็บไซต์ที่อื่นๆ ที่น่าสนใจ" />
<section class="mt-6 flex flex-col flex-nowrap gap-3">
<ClientOnly>
<div v-for="data in bookmarkItems" :key="data.name">
<BookmarkItem :web-item="data" />
<div v-for="data in bookmarkItems?.data" :key="data.id">
<BookmarkItem :web-item="data.attributes" />
</div>
<template #fallback>
<BookmarkFallback />
</template>
</ClientOnly>
</section>
<section class="mt-5 flex justify-center" v-if="bookmarkItems?.meta">
<UPagination v-model="currentPage" :page-count="itemPerPage" :total="bookmarkItems.meta.pagination.total" />
</section>
</div>
</template>

<script lang="ts" setup>
import type BookmarkItemsInterface from '~/types/BookmarkItemsInterface'
const currentPage = ref(1)
const itemPerPage = 6
const nuxt = useNuxtApp()
const { find } = useStrapi()
const { data: bookmarkItems } = await useLazyAsyncData('bookmarks', () =>
find<BookmarkItemsInterface>('bookmarks').then((item) => item.data.map((item) => item.attributes))
const { data: bookmarkItems } = await useLazyAsyncData(
'bookmarks',
() => find<BookmarkItemsInterface>('bookmarks', { pagination: { page: currentPage.value, pageSize: itemPerPage } }),
{
watch: [currentPage],
getCachedData(key) {
if (nuxt.isHydrating && nuxt.payload.data[key]) {
return nuxt.payload.data[key]
}
if (nuxt.static.data[key]) {
return nuxt.static.data[key]
}
return null
}
}
)
useSeoMeta({
title: 'Bookmarks',
Expand Down

1 comment on commit 24ce5ad

@vercel
Copy link

@vercel vercel bot commented on 24ce5ad Sep 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

konkamon – ./

konkamon-git-main-bkozii.vercel.app
konkamon.vercel.app
konkamon-bkozii.vercel.app

Please sign in to comment.