Add luma pagination (#187)

This commit is contained in:
HCode authored and GitHub committed 2025-02-22 14:47:23 +00:00
1 parent f701ae05b1
commit f837700d02
9 files changed
+105 -29

No files matched your search

+38 -10
View File
@@ -14,7 +14,7 @@
@refresh="onGetApplication"
@select="$store.dispatch('luma/setApplication', $event)"
/>
<recent-panel class="panel recent" />
<recent-panel class="panel recent" @reach-top="onReachTop" />
<!-- <operation-panel class="panel operation" @generate="onGenerate" /> -->
</template>
</layout>
@@ -37,6 +37,7 @@ const CALLBACK_URL = 'https://webhook.acedata.cloud/luma';
interface IData {
task: ILumaTask | undefined;
job: number;
timer: NodeJS.Timer;
}
export default defineComponent({
@@ -50,7 +51,9 @@ export default defineComponent({
data(): IData {
return {
task: undefined,
job: 0
job: 0,
// @ts-ignore
timer: undefined
};
},
computed: {
@@ -75,8 +78,20 @@ export default defineComponent({
application() {
return this.$store.state.luma.application;
},
applications() {
return this.$store.state.luma.applications;
tasks() {
return this.$store.state.luma.tasks;
}
},
watch: {
tasks: {
handler(value, oldValue) {
// scroll down if new tasks are added
if (value?.items?.length > oldValue?.items?.length) {
console.debug('new tasks detected');
// this.onScrollDown();
}
},
deep: true
}
},
async mounted() {
@@ -84,7 +99,7 @@ export default defineComponent({
await this.onGetApplication();
await this.onScrollDown();
await this.onGetTasks();
await this.onScrollDown();
// await this.onScrollDown();
// @ts-ignore
this.job = setInterval(() => {
this.onGetTasks();
@@ -92,8 +107,15 @@ export default defineComponent({
},
async unmounted() {
clearInterval(this.job);
clearInterval(this.timer);
},
methods: {
async onReachTop() {
console.debug('reached top');
await this.onGetTasks({
createdAtMax: this.tasks?.items?.[0]?.created_at
});
},
async onGetService() {
console.debug('start onGetService');
await this.$store.dispatch('luma/getService');
@@ -130,14 +152,18 @@ export default defineComponent({
}
}, 500);
},
async onGetTasks() {
async onGetTasks(payload?: { limit?: number; createdAtMin?: number; createdAtMax?: number }) {
if (this.loading) {
console.debug('loading');
return;
}
console.debug('start onGetTasks', payload);
const { limit = 5, createdAtMin, createdAtMax } = payload || {};
console.debug('limit', limit, 'createdAtMin', createdAtMin, 'createdAtMax', createdAtMax);
await this.$store.dispatch('luma/getTasks', {
limit: 30,
offset: 0
limit,
createdAtMin,
createdAtMax
});
},
async onGenerateVideo() {
@@ -170,8 +196,10 @@ export default defineComponent({
}
})
.finally(async () => {
await this.onGetTasks();
await this.onScrollDown();
setTimeout(async () => {
await this.onGetTasks();
await this.onScrollDown();
}, 1000);
});
}
}