Add pika hailuo pagination (#173)
This commit is contained in:
1 parent
14efcf4e55
commit
d8fba2afd8
16 files changed
+172
-33
No files matched your search
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"type": "patch",
|
||||||
|
"comment": "add pika hailuo pagination",
|
||||||
|
"packageName": "@acedatacloud/nexior",
|
||||||
|
"email": "1348977728@qq.com",
|
||||||
|
"dependentChangeType": "patch"
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="panel recent">
|
<div ref="panel" class="panel recent" @scroll="onHandleScroll">
|
||||||
<div v-if="tasks?.items === undefined" class="tasks">
|
<div v-if="tasks?.items === undefined" class="tasks">
|
||||||
<div v-for="_ in 3" :key="_" class="task placeholder">
|
<div v-for="_ in 3" :key="_" class="task placeholder">
|
||||||
<div class="left">
|
<div class="left">
|
||||||
@@ -40,6 +40,7 @@ export default defineComponent({
|
|||||||
ElSkeleton,
|
ElSkeleton,
|
||||||
ElSkeletonItem
|
ElSkeletonItem
|
||||||
},
|
},
|
||||||
|
emits: ['reach-top'],
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
job: 0
|
job: 0
|
||||||
@@ -50,9 +51,18 @@ export default defineComponent({
|
|||||||
// reverse the order of the tasks.items
|
// reverse the order of the tasks.items
|
||||||
return {
|
return {
|
||||||
...this.$store.state.hailuo?.tasks,
|
...this.$store.state.hailuo?.tasks,
|
||||||
items: this.$store.state.hailuo?.tasks?.items?.slice().reverse()
|
items: this.$store.state.hailuo?.tasks?.items?.slice()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
onHandleScroll() {
|
||||||
|
const el = this.$refs.panel as HTMLElement;
|
||||||
|
console.log('reach-top reach-top reach-top');
|
||||||
|
if (el.scrollTop === 0) {
|
||||||
|
this.$emit('reach-top');
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -147,7 +147,6 @@ export default defineComponent({
|
|||||||
result.push(audio);
|
result.push(audio);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
console.log('videos', result);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="panel recent">
|
<div ref="panel" class="panel recent" @scroll="onHandleScroll">
|
||||||
<div v-if="tasks?.items === undefined" class="tasks">
|
<div v-if="tasks?.items === undefined" class="tasks">
|
||||||
<div v-for="_ in 3" :key="_" class="task placeholder">
|
<div v-for="_ in 3" :key="_" class="task placeholder">
|
||||||
<div class="left">
|
<div class="left">
|
||||||
@@ -40,6 +40,7 @@ export default defineComponent({
|
|||||||
ElSkeleton,
|
ElSkeleton,
|
||||||
ElSkeletonItem
|
ElSkeletonItem
|
||||||
},
|
},
|
||||||
|
emits: ['reach-top'],
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
job: 0
|
job: 0
|
||||||
@@ -50,9 +51,18 @@ export default defineComponent({
|
|||||||
// reverse the order of the tasks.items
|
// reverse the order of the tasks.items
|
||||||
return {
|
return {
|
||||||
...this.$store.state.pika?.tasks,
|
...this.$store.state.pika?.tasks,
|
||||||
items: this.$store.state.pika?.tasks?.items?.slice().reverse()
|
items: this.$store.state.pika?.tasks?.items?.slice()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
onHandleScroll() {
|
||||||
|
const el = this.$refs.panel as HTMLElement;
|
||||||
|
console.log('reach-top reach-top reach-top');
|
||||||
|
if (el.scrollTop === 0) {
|
||||||
|
this.$emit('reach-top');
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -137,7 +137,6 @@ export default defineComponent({
|
|||||||
result.push(audio);
|
result.push(audio);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
console.log('videos', result);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ export interface IHailuoGenerateResponse {
|
|||||||
|
|
||||||
export interface IHailuoTask {
|
export interface IHailuoTask {
|
||||||
id: string;
|
id: string;
|
||||||
created_at?: string;
|
created_at?: number;
|
||||||
request?: IHailuoGenerateRequest;
|
request?: IHailuoGenerateRequest;
|
||||||
response?: IHailuoGenerateResponse;
|
response?: IHailuoGenerateResponse;
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -43,7 +43,7 @@ export interface IPikaGenerateResponse {
|
|||||||
|
|
||||||
export interface IPikaTask {
|
export interface IPikaTask {
|
||||||
id: string;
|
id: string;
|
||||||
created_at?: string;
|
created_at?: number;
|
||||||
request?: IPikaGenerateRequest;
|
request?: IPikaGenerateRequest;
|
||||||
response?: IPikaGenerateResponse;
|
response?: IPikaGenerateResponse;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,8 @@ class HailuoOperator {
|
|||||||
type?: string;
|
type?: string;
|
||||||
limit?: number;
|
limit?: number;
|
||||||
offset?: number;
|
offset?: number;
|
||||||
|
createdAtMax?: number;
|
||||||
|
createdAtMin?: number;
|
||||||
},
|
},
|
||||||
options: { token: string }
|
options: { token: string }
|
||||||
): Promise<AxiosResponse<IHailuoTasksResponse>> {
|
): Promise<AxiosResponse<IHailuoTasksResponse>> {
|
||||||
@@ -66,6 +68,16 @@ class HailuoOperator {
|
|||||||
? {
|
? {
|
||||||
offset: filter.offset
|
offset: filter.offset
|
||||||
}
|
}
|
||||||
|
: {}),
|
||||||
|
...(filter.createdAtMax !== undefined
|
||||||
|
? {
|
||||||
|
created_at_max: filter.createdAtMax
|
||||||
|
}
|
||||||
|
: {}),
|
||||||
|
...(filter.createdAtMin !== undefined
|
||||||
|
? {
|
||||||
|
created_at_min: filter.createdAtMin
|
||||||
|
}
|
||||||
: {})
|
: {})
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -30,6 +30,8 @@ class PikaOperator {
|
|||||||
type?: string;
|
type?: string;
|
||||||
limit?: number;
|
limit?: number;
|
||||||
offset?: number;
|
offset?: number;
|
||||||
|
createdAtMax?: number;
|
||||||
|
createdAtMin?: number;
|
||||||
},
|
},
|
||||||
options: { token: string }
|
options: { token: string }
|
||||||
): Promise<AxiosResponse<IPikaTasksResponse>> {
|
): Promise<AxiosResponse<IPikaTasksResponse>> {
|
||||||
@@ -66,6 +68,16 @@ class PikaOperator {
|
|||||||
? {
|
? {
|
||||||
offset: filter.offset
|
offset: filter.offset
|
||||||
}
|
}
|
||||||
|
: {}),
|
||||||
|
...(filter.createdAtMax !== undefined
|
||||||
|
? {
|
||||||
|
created_at_max: filter.createdAtMax
|
||||||
|
}
|
||||||
|
: {}),
|
||||||
|
...(filter.createdAtMin !== undefined
|
||||||
|
? {
|
||||||
|
created_at_min: filter.createdAtMin
|
||||||
|
}
|
||||||
: {})
|
: {})
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
class="mb-4"
|
class="mb-4"
|
||||||
@refresh="onGetApplication"
|
@refresh="onGetApplication"
|
||||||
/>
|
/>
|
||||||
<recent-panel class="panel recent" />
|
<recent-panel class="panel recent" @reach-top="onReachTop" />
|
||||||
<!-- <operation-panel class="panel operation" @generate="onGenerate" /> -->
|
<!-- <operation-panel class="panel operation" @generate="onGenerate" /> -->
|
||||||
</template>
|
</template>
|
||||||
</layout>
|
</layout>
|
||||||
@@ -35,6 +35,7 @@ const CALLBACK_URL = 'https://webhook.acedata.cloud/hailuo';
|
|||||||
interface IData {
|
interface IData {
|
||||||
task: IHailuoTask | undefined;
|
task: IHailuoTask | undefined;
|
||||||
job: number;
|
job: number;
|
||||||
|
timer: NodeJS.Timer;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
@@ -48,7 +49,9 @@ export default defineComponent({
|
|||||||
data(): IData {
|
data(): IData {
|
||||||
return {
|
return {
|
||||||
task: undefined,
|
task: undefined,
|
||||||
job: 0
|
job: 0,
|
||||||
|
// @ts-ignore
|
||||||
|
timer: undefined
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@@ -72,6 +75,21 @@ export default defineComponent({
|
|||||||
},
|
},
|
||||||
application() {
|
application() {
|
||||||
return this.$store.state.hailuo.application;
|
return this.$store.state.hailuo.application;
|
||||||
|
},
|
||||||
|
tasks() {
|
||||||
|
return this.$store.state.hailuo.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() {
|
async mounted() {
|
||||||
@@ -87,8 +105,15 @@ export default defineComponent({
|
|||||||
},
|
},
|
||||||
async unmounted() {
|
async unmounted() {
|
||||||
clearInterval(this.job);
|
clearInterval(this.job);
|
||||||
|
clearInterval(this.timer);
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
async onReachTop() {
|
||||||
|
console.debug('reached top');
|
||||||
|
await this.onGetTasks({
|
||||||
|
createdAtMax: this.tasks?.items?.[0]?.created_at
|
||||||
|
});
|
||||||
|
},
|
||||||
async onGetService() {
|
async onGetService() {
|
||||||
console.debug('start onGetService');
|
console.debug('start onGetService');
|
||||||
await this.$store.dispatch('hailuo/getService');
|
await this.$store.dispatch('hailuo/getService');
|
||||||
@@ -125,14 +150,18 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
}, 500);
|
}, 500);
|
||||||
},
|
},
|
||||||
async onGetTasks() {
|
async onGetTasks(payload?: { limit?: number; createdAtMin?: number; createdAtMax?: number }) {
|
||||||
if (this.loading) {
|
if (this.loading) {
|
||||||
console.debug('loading');
|
console.debug('loading');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
console.debug('start onGetTasks', payload);
|
||||||
|
const { limit = 5, createdAtMin, createdAtMax } = payload || {};
|
||||||
|
console.debug('limit', limit, 'createdAtMin', createdAtMin, 'createdAtMax', createdAtMax);
|
||||||
await this.$store.dispatch('hailuo/getTasks', {
|
await this.$store.dispatch('hailuo/getTasks', {
|
||||||
limit: 30,
|
limit,
|
||||||
offset: 0
|
createdAtMin,
|
||||||
|
createdAtMax
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
async onGenerateVideo() {
|
async onGenerateVideo() {
|
||||||
@@ -165,8 +194,10 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.finally(async () => {
|
.finally(async () => {
|
||||||
await this.onGetTasks();
|
setTimeout(async () => {
|
||||||
await this.onScrollDown();
|
await this.onGetTasks();
|
||||||
|
await this.onScrollDown();
|
||||||
|
}, 1000);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
class="mb-4"
|
class="mb-4"
|
||||||
@refresh="onGetApplication"
|
@refresh="onGetApplication"
|
||||||
/>
|
/>
|
||||||
<recent-panel class="panel recent" />
|
<recent-panel class="panel recent" @reach-top="onReachTop" />
|
||||||
<!-- <operation-panel class="panel operation" @generate="onGenerate" /> -->
|
<!-- <operation-panel class="panel operation" @generate="onGenerate" /> -->
|
||||||
</template>
|
</template>
|
||||||
</layout>
|
</layout>
|
||||||
@@ -35,6 +35,7 @@ const CALLBACK_URL = 'https://webhook.acedata.cloud/pika';
|
|||||||
interface IData {
|
interface IData {
|
||||||
task: IPikaTask | undefined;
|
task: IPikaTask | undefined;
|
||||||
job: number;
|
job: number;
|
||||||
|
timer: NodeJS.Timer;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
@@ -48,7 +49,9 @@ export default defineComponent({
|
|||||||
data(): IData {
|
data(): IData {
|
||||||
return {
|
return {
|
||||||
task: undefined,
|
task: undefined,
|
||||||
job: 0
|
job: 0,
|
||||||
|
// @ts-ignore
|
||||||
|
timer: undefined
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@@ -72,6 +75,21 @@ export default defineComponent({
|
|||||||
},
|
},
|
||||||
application() {
|
application() {
|
||||||
return this.$store.state.pika.application;
|
return this.$store.state.pika.application;
|
||||||
|
},
|
||||||
|
tasks() {
|
||||||
|
return this.$store.state.pika.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() {
|
async mounted() {
|
||||||
@@ -79,7 +97,7 @@ export default defineComponent({
|
|||||||
await this.onGetApplication();
|
await this.onGetApplication();
|
||||||
await this.onScrollDown();
|
await this.onScrollDown();
|
||||||
await this.onGetTasks();
|
await this.onGetTasks();
|
||||||
await this.onScrollDown();
|
// await this.onScrollDown();
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
this.job = setInterval(() => {
|
this.job = setInterval(() => {
|
||||||
this.onGetTasks();
|
this.onGetTasks();
|
||||||
@@ -87,8 +105,15 @@ export default defineComponent({
|
|||||||
},
|
},
|
||||||
async unmounted() {
|
async unmounted() {
|
||||||
clearInterval(this.job);
|
clearInterval(this.job);
|
||||||
|
clearInterval(this.timer);
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
async onReachTop() {
|
||||||
|
console.debug('reached top');
|
||||||
|
await this.onGetTasks({
|
||||||
|
createdAtMax: this.tasks?.items?.[0]?.created_at
|
||||||
|
});
|
||||||
|
},
|
||||||
async onGetService() {
|
async onGetService() {
|
||||||
console.debug('start onGetService');
|
console.debug('start onGetService');
|
||||||
await this.$store.dispatch('pika/getService');
|
await this.$store.dispatch('pika/getService');
|
||||||
@@ -125,14 +150,18 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
}, 500);
|
}, 500);
|
||||||
},
|
},
|
||||||
async onGetTasks() {
|
async onGetTasks(payload?: { limit?: number; createdAtMin?: number; createdAtMax?: number }) {
|
||||||
if (this.loading) {
|
if (this.loading) {
|
||||||
console.debug('loading');
|
console.debug('loading');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
console.debug('start onGetTasks', payload);
|
||||||
|
const { limit = 5, createdAtMin, createdAtMax } = payload || {};
|
||||||
|
console.debug('limit', limit, 'createdAtMin', createdAtMin, 'createdAtMax', createdAtMax);
|
||||||
await this.$store.dispatch('pika/getTasks', {
|
await this.$store.dispatch('pika/getTasks', {
|
||||||
limit: 30,
|
limit,
|
||||||
offset: 0
|
createdAtMin,
|
||||||
|
createdAtMax
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
async onGenerateVideo() {
|
async onGenerateVideo() {
|
||||||
@@ -165,8 +194,10 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.finally(async () => {
|
.finally(async () => {
|
||||||
await this.onGetTasks();
|
setTimeout(async () => {
|
||||||
await this.onScrollDown();
|
await this.onGetTasks();
|
||||||
|
await this.onScrollDown();
|
||||||
|
}, 1000);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -149,10 +149,8 @@ export default defineComponent({
|
|||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
// scroll to bottom for `.recent`
|
// scroll to bottom for `.recent`
|
||||||
const el = document.querySelector('.recent');
|
const el = document.querySelector('.recent');
|
||||||
console.log('onScrollDown ', el, el.scrollTop, el.scrollHeight);
|
|
||||||
if (el) {
|
if (el) {
|
||||||
el.scrollTop = el.scrollHeight;
|
el.scrollTop = el.scrollHeight;
|
||||||
console.log('onScrollDown ', el.scrollTop, el.scrollHeight);
|
|
||||||
}
|
}
|
||||||
}, 1000);
|
}, 1000);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { IRootState } from '../common/models';
|
|||||||
import { IApplication, ICredential, IHailuoConfig, IHailuoTask, IService, IApplicationType } from '@/models';
|
import { IApplication, ICredential, IHailuoConfig, IHailuoTask, IService, IApplicationType } from '@/models';
|
||||||
import { Status } from '@/models/common';
|
import { Status } from '@/models/common';
|
||||||
import { HAILUO_SERVICE_ID } from '@/constants';
|
import { HAILUO_SERVICE_ID } from '@/constants';
|
||||||
|
import { mergeAndSortLists } from '@/utils/merge';
|
||||||
|
|
||||||
export const resetAll = ({ commit }: ActionContext<IHailuoState, IRootState>): void => {
|
export const resetAll = ({ commit }: ActionContext<IHailuoState, IRootState>): void => {
|
||||||
commit('resetAll');
|
commit('resetAll');
|
||||||
@@ -113,7 +114,12 @@ export const getService = async ({ commit, state }: ActionContext<IHailuoState,
|
|||||||
|
|
||||||
export const getTasks = async (
|
export const getTasks = async (
|
||||||
{ commit, state, rootState }: ActionContext<IHailuoState, IRootState>,
|
{ commit, state, rootState }: ActionContext<IHailuoState, IRootState>,
|
||||||
{ offset, limit }: { offset?: number; limit?: number }
|
{
|
||||||
|
offset,
|
||||||
|
limit,
|
||||||
|
createdAtMin,
|
||||||
|
createdAtMax
|
||||||
|
}: { offset?: number; limit?: number; createdAtMin?: number; createdAtMax?: number }
|
||||||
): Promise<IHailuoTask[]> => {
|
): Promise<IHailuoTask[]> => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
console.debug('start to get tasks', offset, limit);
|
console.debug('start to get tasks', offset, limit);
|
||||||
@@ -126,6 +132,8 @@ export const getTasks = async (
|
|||||||
.tasks(
|
.tasks(
|
||||||
{
|
{
|
||||||
userId: rootState?.user?.id,
|
userId: rootState?.user?.id,
|
||||||
|
createdAtMin,
|
||||||
|
createdAtMax,
|
||||||
type: 'videos'
|
type: 'videos'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -133,8 +141,15 @@ export const getTasks = async (
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
console.debug('get imagine tasks success', response.data.items);
|
console.debug('get videos tasks success', response.data.items);
|
||||||
commit('setTasksItems', response.data.items);
|
// merge with existing tasks
|
||||||
|
const existingItems = state?.tasks?.items || [];
|
||||||
|
console.debug('existing items', existingItems);
|
||||||
|
const newItems = response.data.items || [];
|
||||||
|
console.debug('new items', newItems);
|
||||||
|
// sort and de-duplicate using created_at
|
||||||
|
const mergedItems = mergeAndSortLists(existingItems, newItems);
|
||||||
|
commit('setTasksItems', mergedItems);
|
||||||
commit('setTasksTotal', response.data.count);
|
commit('setTasksTotal', response.data.count);
|
||||||
resolve(response.data.items);
|
resolve(response.data.items);
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
export default ['hailuo.credential', 'hailuo.application', 'hailuo.tasks'];
|
export default ['hailuo.credential', 'hailuo.application'];
|
||||||
@@ -5,6 +5,7 @@ import { IRootState } from '../common/models';
|
|||||||
import { IApplication, ICredential, IPikaConfig, IPikaTask, IService, IApplicationType } from '@/models';
|
import { IApplication, ICredential, IPikaConfig, IPikaTask, IService, IApplicationType } from '@/models';
|
||||||
import { Status } from '@/models/common';
|
import { Status } from '@/models/common';
|
||||||
import { PIKA_SERVICE_ID } from '@/constants';
|
import { PIKA_SERVICE_ID } from '@/constants';
|
||||||
|
import { mergeAndSortLists } from '@/utils/merge';
|
||||||
|
|
||||||
export const resetAll = ({ commit }: ActionContext<IPikaState, IRootState>): void => {
|
export const resetAll = ({ commit }: ActionContext<IPikaState, IRootState>): void => {
|
||||||
commit('resetAll');
|
commit('resetAll');
|
||||||
@@ -113,7 +114,12 @@ export const getService = async ({ commit, state }: ActionContext<IPikaState, IR
|
|||||||
|
|
||||||
export const getTasks = async (
|
export const getTasks = async (
|
||||||
{ commit, state, rootState }: ActionContext<IPikaState, IRootState>,
|
{ commit, state, rootState }: ActionContext<IPikaState, IRootState>,
|
||||||
{ offset, limit }: { offset?: number; limit?: number }
|
{
|
||||||
|
offset,
|
||||||
|
limit,
|
||||||
|
createdAtMin,
|
||||||
|
createdAtMax
|
||||||
|
}: { offset?: number; limit?: number; createdAtMin?: number; createdAtMax?: number }
|
||||||
): Promise<IPikaTask[]> => {
|
): Promise<IPikaTask[]> => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
console.debug('start to get tasks', offset, limit);
|
console.debug('start to get tasks', offset, limit);
|
||||||
@@ -126,6 +132,8 @@ export const getTasks = async (
|
|||||||
.tasks(
|
.tasks(
|
||||||
{
|
{
|
||||||
userId: rootState?.user?.id,
|
userId: rootState?.user?.id,
|
||||||
|
createdAtMin,
|
||||||
|
createdAtMax,
|
||||||
type: 'videos'
|
type: 'videos'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -133,8 +141,15 @@ export const getTasks = async (
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
console.debug('get imagine tasks success', response.data.items);
|
console.debug('get videos tasks success', response.data.items);
|
||||||
commit('setTasksItems', response.data.items);
|
// merge with existing tasks
|
||||||
|
const existingItems = state?.tasks?.items || [];
|
||||||
|
console.debug('existing items', existingItems);
|
||||||
|
const newItems = response.data.items || [];
|
||||||
|
console.debug('new items', newItems);
|
||||||
|
// sort and de-duplicate using created_at
|
||||||
|
const mergedItems = mergeAndSortLists(existingItems, newItems);
|
||||||
|
commit('setTasksItems', mergedItems);
|
||||||
commit('setTasksTotal', response.data.count);
|
commit('setTasksTotal', response.data.count);
|
||||||
resolve(response.data.items);
|
resolve(response.data.items);
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
export default ['pika.credential', 'pika.application', 'pika.tasks'];
|
export default ['pika.credential', 'pika.application'];
|
||||||
Reference in new issue
Block a user