Skip to content

Commit

Permalink
shopping load with pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
vabene1111 committed Jan 1, 2025
1 parent 34f3372 commit f97d8ff
Showing 1 changed file with 26 additions and 13 deletions.
39 changes: 26 additions & 13 deletions vue3/src/stores/ShoppingStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,23 +191,13 @@ export const useShoppingStore = defineStore(_STORE_ID, () => {
autoSyncLastTimestamp.value = new Date();

let api = new ApiApi()
let requestParameters = {pageSize: 200} as ApiShoppingListEntryListRequest
let requestParameters = {pageSize: 50, page: 1} as ApiShoppingListEntryListRequest
if (mealPlanId) {
requestParameters.mealplan = mealPlanId
}

api.apiShoppingListEntryList(requestParameters).then((r) => {
entries.value = new Map<number, ShoppingListEntry>
// TODO properly load pages
r.results.forEach((e) => {
entries.value.set(e.id!, e)
})
currentlyUpdating.value = false
initialized.value = true
}).catch((err) => {
currentlyUpdating.value = false
useMessageStore().addError(ErrorMessageType.FETCH_ERROR, err)
})
entries.value = new Map<number, ShoppingListEntry>
recLoadShoppingListEntries(requestParameters)

api.apiSupermarketCategoryList().then(r => {
supermarketCategories.value = r.results
Expand All @@ -223,6 +213,29 @@ export const useShoppingStore = defineStore(_STORE_ID, () => {
}
}

/**
* recursively load shopping list entries from paginated api
* @param requestParameters
*/
function recLoadShoppingListEntries(requestParameters: ApiShoppingListEntryListRequest){
let api = new ApiApi()
api.apiShoppingListEntryList(requestParameters).then((r) => {
r.results.forEach((e) => {
entries.value.set(e.id!, e)
})
if(r.next){
requestParameters.page = requestParameters.page + 1
recLoadShoppingListEntries(requestParameters)
} else {
currentlyUpdating.value = false
initialized.value = true
}
}).catch((err) => {
currentlyUpdating.value = false
useMessageStore().addError(ErrorMessageType.FETCH_ERROR, err)
})
}

/**
* perform auto sync request to special endpoint returning only entries changed since last auto sync
*/
Expand Down

0 comments on commit f97d8ff

Please sign in to comment.