[api] Match store functions with new pagination API for events
This commit is contained in:
parent
7b622f96ea
commit
f87c691f61
|
@ -164,8 +164,8 @@ export default defineComponent({
|
||||||
const end = date.addToDate(start, { days: calendarDays.value });
|
const end = date.addToDate(start, { days: calendarDays.value });
|
||||||
|
|
||||||
events.value = {};
|
events.value = {};
|
||||||
const list = await store.getEvents({ from: start, to: end });
|
const { result } = await store.getEvents({ from: start, to: end });
|
||||||
list.forEach((event) => {
|
result.forEach((event) => {
|
||||||
const day = event.start.getDay();
|
const day = event.start.getDay();
|
||||||
|
|
||||||
if (!events.value[day]) {
|
if (!events.value[day]) {
|
||||||
|
|
|
@ -94,21 +94,24 @@ export default defineComponent({
|
||||||
async function load(index: number, done?: (stop: boolean) => void) {
|
async function load(index: number, done?: (stop: boolean) => void) {
|
||||||
const start = new Date();
|
const start = new Date();
|
||||||
if (index < 0) {
|
if (index < 0) {
|
||||||
events.value.unshift(...(await store.getEvents({ to: start, limit: 5, descending: true })));
|
const { result } = await store.getEvents({ to: start, limit: 5, descending: true });
|
||||||
|
events.value.unshift(...result);
|
||||||
if (done) done(false);
|
if (done) done(false);
|
||||||
} else {
|
} else {
|
||||||
const len = events.value.length;
|
const len = events.value.length;
|
||||||
if (
|
const { result } = await store.getEvents({
|
||||||
len ==
|
from: start,
|
||||||
events.value.push(
|
offset: (index - 1) * 10,
|
||||||
...(await store.getEvents({ from: start, offset: (index - 1) * 10, limit: 10 }))
|
limit: 10,
|
||||||
)
|
});
|
||||||
) {
|
if (len == events.value.push(...result)) {
|
||||||
if (done) return done(true);
|
if (done) return done(true);
|
||||||
} else if (done) done(false);
|
} else if (done) done(false);
|
||||||
}
|
}
|
||||||
if (index <= 1) {
|
if (index <= 1) {
|
||||||
window.setTimeout(() => {(<Element>scrollDiv.value).scrollTop = document.getElementById("bbb")?.scrollHeight || 0}, 150);
|
window.setTimeout(() => {
|
||||||
|
(<Element>scrollDiv.value).scrollTop = document.getElementById('bbb')?.scrollHeight || 0;
|
||||||
|
}, 150);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -107,13 +107,15 @@ export const useEventStore = defineStore({
|
||||||
},
|
},
|
||||||
|
|
||||||
async getEvents(
|
async getEvents(
|
||||||
filter:
|
filter?: FG.PaginationFilter & {
|
||||||
| { from?: Date; to?: Date; limit?: number; offset?: number; descending?: boolean }
|
user?: string;
|
||||||
| undefined = undefined
|
}
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
const { data } = await api.get<FG.Event[]>('/events', { params: filter });
|
const { data } = await api.get<FG.PaginationResponse<FG.Event>>('/events', {
|
||||||
data.forEach((element) => fixEvent(element));
|
params: <unknown>filter,
|
||||||
|
});
|
||||||
|
data.result.forEach((element) => fixEvent(element));
|
||||||
return data;
|
return data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw error;
|
throw error;
|
||||||
|
|
Loading…
Reference in New Issue