Skip to content

Commit

Permalink
adding pagination in images
Browse files Browse the repository at this point in the history
  • Loading branch information
mauriciomb97 committed Oct 15, 2024
1 parent 3788ecc commit 6cfbfba
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions pages/createimages.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,20 @@
<FormSubmitImage @response="() => refresh()" />
</template>
</Card>
<Paginator
:template="{
'640px': 'PrevPageLink CurrentPageReport NextPageLink',
'960px': 'FirstPageLink PrevPageLink CurrentPageReport NextPageLink LastPageLink',
'1300px': 'FirstPageLink PrevPageLink PageLinks NextPageLink LastPageLink',
default: 'FirstPageLink PrevPageLink PageLinks NextPageLink LastPageLink'
}"
:rows="rows"
:totalRecords="data.length"
:first="first"
@page="onPageChange"
/>
<div class="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-6 2xl:grid-cols-8 gap-2 px-2">
<ImageCard v-for="i in data" :key="i.id" :image="i" />
<ImageCard v-for="i in paginatedImages" :key="i.id" :image="i" />
</div>
</div>
<Toast />
Expand All @@ -26,7 +38,8 @@ const { data, refresh } = await useFetch("/api/inference", {
const interval = useIntervalFn(() => refresh(), 5_000); // refresh every 5s
useTimeoutFn(() => interval.pause(), 3_600_000); // stops refreshing after 1h
const first = ref(0);
const rows = ref(15);
const toast = useToast();
const showLimitationsToast = () => {
Expand All @@ -38,6 +51,15 @@ const showLimitationsToast = () => {
});
};
const paginatedImages = computed(() => {
return data.value?.slice(first.value, first.value + rows.value) || [];
});
const onPageChange = (event: any) => {
first.value = event.first;
rows.value = event.rows;
};
</script>

<style scoped>
Expand Down

0 comments on commit 6cfbfba

Please sign in to comment.