mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-09-26 17:11:03 +00:00
add pagination component
This commit is contained in:
46
web/src/components/layout/Pagination.vue
Normal file
46
web/src/components/layout/Pagination.vue
Normal file
@@ -0,0 +1,46 @@
|
||||
<template>
|
||||
<div>
|
||||
<div v-if="loading">loading ...</div>
|
||||
<div v-else>
|
||||
<slot :data="data" />
|
||||
</div>
|
||||
|
||||
<Button v-if="hasMore" :is-loading="loading" text="Load more" class="mx-auto mt-4" @click="nextPage" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { nextTick } from 'vue';
|
||||
|
||||
import Button from '~/components/atomic/Button.vue';
|
||||
|
||||
import { usePagination } from '~/compositions/usePaginate';
|
||||
|
||||
const props = defineProps<{
|
||||
loadData: () => Promise<unknown[] | null>;
|
||||
}>();
|
||||
|
||||
const {
|
||||
loading,
|
||||
data,
|
||||
nextPage: _nextPage,
|
||||
hasMore,
|
||||
} = usePagination(props.loadData, () => true, {
|
||||
name: 'secrets',
|
||||
each: ['repo', 'org', 'global'],
|
||||
});
|
||||
|
||||
function scrollDown() {
|
||||
window.scrollTo({
|
||||
top: document.body.scrollHeight,
|
||||
behavior: 'smooth',
|
||||
});
|
||||
}
|
||||
|
||||
function nextPage() {
|
||||
_nextPage();
|
||||
nextTick(() => {
|
||||
setTimeout(scrollDown, 100);
|
||||
});
|
||||
}
|
||||
</script>
|
Reference in New Issue
Block a user