From bb903b61b77752331253c32c6eda89a69e8048ed Mon Sep 17 00:00:00 2001 From: Michael Bauer <michael-bauer@posteo.de> Date: Fri, 22 Mar 2024 12:12:18 +0100 Subject: [PATCH] Start with fetchMore --- .../components/coursebook/Coursebook.vue | 35 +++++++++++-------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/aleksis/apps/alsijil/frontend/components/coursebook/Coursebook.vue b/aleksis/apps/alsijil/frontend/components/coursebook/Coursebook.vue index 1c47f5902..286481188 100644 --- a/aleksis/apps/alsijil/frontend/components/coursebook/Coursebook.vue +++ b/aleksis/apps/alsijil/frontend/components/coursebook/Coursebook.vue @@ -293,20 +293,27 @@ export default { assureDate(date) { if (!this.knownDates[date]) { // find missing & fetch missing range - // date +- 5 days ? - const dateRange = Interval - .fromDateTimes(date.minus({ days: 3 }), date.plus({ days: 4 })) - .splitBy({ days: 1 }) - .map((ts) => ts.start); - console.log('assureDate', dateRange.map((ts) => ts.toISODate())); - // look up in docsByDay - console.log('missing', dateRange.map((ts) => this.docsByDay[ts] )); - console.log('missing', dateRange.filter((ts) => !this.docsByDay[ts] )); - // dateRange.forEach((ts) => { this.docsByDay[ts.toISODate()] = 42 }); - console.log('docsByDay', this.docsByDay); - console.log('2024-03-29', this.docsByDay[DateTime.fromISO('2024-03-29')]); - console.log('2024-03-29', dateRange[3], this.docsByDay[dateRange[3]]); - // sort missing and ask for first to last + const missing = this.dateRange(date).filter((ts) => !this.docsByDay[ts] ); + // ask for first to last + this.lastQuery.fetchMore({ + variables: { + dateStart: missing[0].toISODate(), + dateEnd: missing[missing.length - 1].toISODate(), + }, + // Transform the previous result with new data + updateQuery: (previousResult, { fetchMoreResult }) => { + + return { + tagsPage: { + __typename: previousResult.tagsPage.__typename, + // Merging the tag list + tags: [...previousResult.tagsPage.tags, ...newTags], + hasMore, + }, + } + }, + }) + // integrate into docsByDay } }, -- GitLab