Skip to content

Commit

Permalink
fix: reset page flag for infinite scroll whenever document list is fe…
Browse files Browse the repository at this point in the history
…tched

(cherry picked from commit e4c599c)
  • Loading branch information
ruchamahabal authored and mergify[bot] committed Dec 21, 2023
1 parent 71913e8 commit 995f0bd
Showing 1 changed file with 39 additions and 36 deletions.
75 changes: 39 additions & 36 deletions frontend/src/components/ListView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,41 @@ const defaultFilters = computed(() => {
return filters
})
// resources
const documents = createResource({
url: "frappe.desk.reportview.get",
onSuccess: (data) => {
if (data.values?.length < listOptions.value.page_length) {
hasNextPage.value = false
}
},
transform(data) {
if (data.length === 0) {
return []
}
// convert keys and values arrays to docs object
const fields = data["keys"]
const values = data["values"]
const docs = values.map((value) => {
const doc = {}
fields.forEach((field, index) => {
doc[field] = value[index]
})
return doc
})
let pagedData
if (!documents.params.start || documents.params.start === 0) {
pagedData = docs
} else {
pagedData = documents.data.concat(docs)
}
return pagedData
},
})
// helper functions
function initializeFilters() {
props.filterConfig.forEach((filter) => {
Expand Down Expand Up @@ -270,6 +305,10 @@ function clearFilters() {
}
function fetchDocumentList(start = 0) {
if (start === 0) {
hasNextPage.value = true
}
const filters = [[props.doctype, "docstatus", "!=", "2"]]
filters.push(...defaultFilters.value)
Expand All @@ -286,40 +325,6 @@ function fetchDocumentList(start = 0) {
})
}
const documents = createResource({
url: "frappe.desk.reportview.get",
onSuccess: (data) => {
if (data.values?.length < listOptions.value.page_length) {
hasNextPage.value = false
}
},
transform(data) {
if (data.length === 0) {
return []
}
// convert keys and values arrays to docs object
const fields = data["keys"]
const values = data["values"]
const docs = values.map((value) => {
const doc = {}
fields.forEach((field, index) => {
doc[field] = value[index]
})
return doc
})
let pagedData
if (!documents.params.start || documents.params.start === 0) {
pagedData = docs
} else {
pagedData = documents.data.concat(docs)
}
return pagedData
},
})
const handleScroll = debounce(() => {
if (!hasNextPage.value) return
Expand All @@ -342,7 +347,6 @@ const handleRefresh = (event) => {
watch(
() => activeTab.value,
(_value) => {
hasNextPage.value = true
fetchDocumentList()
}
)
Expand All @@ -352,7 +356,6 @@ onMounted(async () => {
await workflow.workflowDoc.promise
workflowStateField.value = workflow.getWorkflowStateField()
hasNextPage.value = true
fetchDocumentList()
socket.emit("doctype_subscribe", props.doctype)
Expand Down

0 comments on commit 995f0bd

Please sign in to comment.