improvements

This commit is contained in:
vabene1111
2024-01-29 08:37:53 +01:00
parent 4c6410d7ae
commit 0f1a3ba5d8
6 changed files with 34 additions and 23 deletions

View File

@@ -125,8 +125,12 @@ export const useShoppingListStore = defineStore(_STORE_ID, {
return ordered_structure
},
/**
* flattened list of entries used for exporters
* kinda uncool but works for now
* @return {*[]}
*/
get_flat_entries: function () {
//{amount: x.amount, unit: x.unit?.name ?? "", food: x.food?.name ?? ""}
let items = []
for (let i in this.get_entries_by_group) {
for (let f in this.get_entries_by_group[i]['foods']) {
@@ -435,6 +439,21 @@ export const useShoppingListStore = defineStore(_STORE_ID, {
this.deleteObject(this.entries[i])
}
},
deleteShoppingListRecipe(shopping_list_recipe_id) {
let api = new ApiApiFactory()
for (let i in this.entries) {
if (this.entries[i].list_recipe === shopping_list_recipe_id) {
Vue.delete(this.entries, i)
}
}
api.destroyShoppingListRecipe(shopping_list_recipe_id).then((x) => {
// no need to update anything, entries were already removed
}).catch((err) => {
StandardToasts.makeStandardToast(this, StandardToasts.FAIL_DELETE, err)
})
},
/**
* register the change to a set of entries to allow undoing it
* throws an Error if the operation type is not known

View File

@@ -95,10 +95,10 @@ export const useUserPreferenceStore = defineStore(_STORE_ID, {
for (s in settings) {
Vue.set(this.user_settings, s, settings[s])
}
//console.log(`loaded local user settings age ${((new Date().getTime()) - this.user_settings.locally_updated_at) / 1000} `)
console.log(`loaded local user settings age ${((new Date().getTime()) - this.user_settings.locally_updated_at) / 1000} `)
}
if (((new Date().getTime()) - this.user_settings.locally_updated_at) > _STALE_TIME_IN_MS || !allow_cached_results) {
//console.log('refreshing user settings from API')
console.log('refreshing user settings from API')
let apiClient = new ApiApiFactory()
apiClient.retrieveUserPreference(localStorage.getItem('USER_ID')).then(r => {
for (s in r.data) {