Skip to content
Snippets Groups Projects
Commit d9e768d1 authored by permcu's avatar permcu
Browse files

Test fetchMore - broken

fetchMore operates on the raw query result
query update fn is then called on the combined result
this result is then propagated through the page
parent e2d3a338
No related branches found
No related tags found
No related merge requests found
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
:enable-create="false" :enable-create="false"
:enable-edit="false" :enable-edit="false"
:elevated="false" :elevated="false"
@items="docsByDay = groupDocsByDay($event)"
@lastQuery="lastQuery = $event" @lastQuery="lastQuery = $event"
ref="iterator" ref="iterator"
disable-pagination disable-pagination
...@@ -57,9 +56,9 @@ ...@@ -57,9 +56,9 @@
</div> </div>
</div> </div>
</template> </template>
<template #default> <template #default="{ items }">
<v-list-item <v-list-item
v-for="day in listDocsByDay(docsByDay)" v-for="day in groupDocsByDay(items)"
two-line two-line
:key="'day-' + day[0]" :key="'day-' + day[0]"
:id="'documentation_' + day[0].toISODate()" :id="'documentation_' + day[0].toISODate()"
...@@ -199,6 +198,7 @@ export default { ...@@ -199,6 +198,7 @@ export default {
}, },
}, },
methods: { methods: {
// TODO: Scroll to actual first date!
resetDate() { resetDate() {
// Assure current date // Assure current date
console.log('Resetting date range', this.$route.hash); console.log('Resetting date range', this.$route.hash);
...@@ -229,21 +229,20 @@ export default { ...@@ -229,21 +229,20 @@ export default {
}); });
this.resetDate(); this.resetDate();
}, },
// => {dt: [dt doc ...] ...}
groupDocsByDay(docs) { groupDocsByDay(docs) {
return docs.reduce((byDay, doc) => { // => {dt: [dt doc ...] ...}
this.docsByDay = docs.reduce((byDay, doc) => {
// This works with dummy. Does actual doc have dateStart instead? // This works with dummy. Does actual doc have dateStart instead?
const day = DateTime.fromISO(doc.datetimeStart).startOf("day"); const day = DateTime.fromISO(doc.datetimeStart).startOf("day");
byDay[day] ??= [day]; byDay[day] ??= [day];
byDay[day].push(doc); byDay[day].push(doc);
return byDay; return byDay;
}, {}); }, {});
}, // => [[dt doc ...] ...]
// => [[dt doc ...] ...] return Object.keys(this.docsByDay)
listDocsByDay(docsByDay) {
return Object.keys(docsByDay)
.sort() .sort()
.map((key) => docsByDay[key]); .map((key) => this.docsByDay[key]);
// sorting is necessary since backend can send docs unordered
}, },
debounce(fn, delay) { debounce(fn, delay) {
let timer; let timer;
...@@ -347,8 +346,11 @@ export default { ...@@ -347,8 +346,11 @@ export default {
// docsByDay: {dt: [dt doc ...] ...} // docsByDay: {dt: [dt doc ...] ...}
assureDate(date) { assureDate(date) {
if (!this.knownDates[date]) { if (!this.knownDates[date]) {
console.log(this.lastQuery);
console.log('unknown date', date.toISODate());
// find missing & fetch missing range // find missing & fetch missing range
const missing = this.dateRange(date).filter((ts) => !this.docsByDay[ts] ); const missing = this.dateRange(date)
.filter((ts) => !this.docsByDay[ts]);
// ask for first to last // ask for first to last
this.lastQuery.fetchMore({ this.lastQuery.fetchMore({
variables: { variables: {
...@@ -357,18 +359,17 @@ export default { ...@@ -357,18 +359,17 @@ export default {
}, },
// Transform the previous result with new data // Transform the previous result with new data
updateQuery: (previousResult, { fetchMoreResult }) => { updateQuery: (previousResult, { fetchMoreResult }) => {
console.log('previousResult', previousResult);
console.log('fetchMoreResult', fetchMoreResult);
return { return {
tagsPage: { items: [...previousResult.items,
__typename: previousResult.tagsPage.__typename, ...fetchMoreResult.items.filter((doc) => {
// Merging the tag list return previousResult.items.find((prev) => prev.id === doc.id)
tags: [...previousResult.tagsPage.tags, ...newTags], }),
hasMore, ],
}, };
} }
},
}) })
// integrate into docsByDay // integrate into docsByDay
} }
}, },
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment