[api] Match store functions with new pagination API for events

This commit is contained in:
Ferdinand Thiessen 2021-11-25 15:37:34 +01:00
parent 7b622f96ea
commit f87c691f61
3 changed files with 21 additions and 16 deletions

View File

@ -164,8 +164,8 @@ export default defineComponent({
const end = date.addToDate(start, { days: calendarDays.value });
events.value = {};
const list = await store.getEvents({ from: start, to: end });
list.forEach((event) => {
const { result } = await store.getEvents({ from: start, to: end });
result.forEach((event) => {
const day = event.start.getDay();
if (!events.value[day]) {

View File

@ -94,21 +94,24 @@ export default defineComponent({
async function load(index: number, done?: (stop: boolean) => void) {
const start = new Date();
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);
} else {
const len = events.value.length;
if (
len ==
events.value.push(
...(await store.getEvents({ from: start, offset: (index - 1) * 10, limit: 10 }))
)
) {
const { result } = await store.getEvents({
from: start,
offset: (index - 1) * 10,
limit: 10,
});
if (len == events.value.push(...result)) {
if (done) return done(true);
} else if (done) done(false);
}
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);
}
}

View File

@ -107,13 +107,15 @@ export const useEventStore = defineStore({
},
async getEvents(
filter:
| { from?: Date; to?: Date; limit?: number; offset?: number; descending?: boolean }
| undefined = undefined
filter?: FG.PaginationFilter & {
user?: string;
}
) {
try {
const { data } = await api.get<FG.Event[]>('/events', { params: filter });
data.forEach((element) => fixEvent(element));
const { data } = await api.get<FG.PaginationResponse<FG.Event>>('/events', {
params: <unknown>filter,
});
data.result.forEach((element) => fixEvent(element));
return data;
} catch (error) {
throw error;