aboutsummaryrefslogtreecommitdiffstats
path: root/apps/settings/src/store
diff options
context:
space:
mode:
authorjulia.kirschenheuter <julia.kirschenheuter@nextcloud.com>2022-11-18 15:32:15 +0100
committernextcloud-command <nextcloud-command@users.noreply.github.com>2022-11-28 10:16:32 +0000
commit7bdac514fd1b288ecb63b3c7e6f5b95abeb77092 (patch)
tree663f8c4e0eea87a183aacf572e046a6a48b7fa60 /apps/settings/src/store
parentd92c5f78cec5465833fa78b6f8494fb42041999f (diff)
downloadnextcloud-server-7bdac514fd1b288ecb63b3c7e6f5b95abeb77092.tar.gz
nextcloud-server-7bdac514fd1b288ecb63b3c7e6f5b95abeb77092.zip
Adapt router.js for setting document title.
Adapt store to store Promise for dynamic requested categories. Create new constants file to store category name with associated translation. Signed-off-by: julia.kirschenheuter <julia.kirschenheuter@nextcloud.com> Signed-off-by: nextcloud-command <nextcloud-command@users.noreply.github.com>
Diffstat (limited to 'apps/settings/src/store')
-rw-r--r--apps/settings/src/store/apps.js31
1 files changed, 23 insertions, 8 deletions
diff --git a/apps/settings/src/store/apps.js b/apps/settings/src/store/apps.js
index 3618fb7919b..29009fc65e0 100644
--- a/apps/settings/src/store/apps.js
+++ b/apps/settings/src/store/apps.js
@@ -34,6 +34,7 @@ const state = {
updateCount: 0,
loading: {},
loadingList: false,
+ gettingCategoriesPromise: null,
}
const mutations = {
@@ -48,6 +49,10 @@ const mutations = {
state.updateCount = updateCount
},
+ updateCategories(state, categoriesPromise) {
+ state.gettingCategoriesPromise = categoriesPromise
+ },
+
setUpdateCount(state, updateCount) {
state.updateCount = updateCount
},
@@ -156,6 +161,9 @@ const getters = {
getUpdateCount(state) {
return state.updateCount
},
+ getCategoryById: (state) => (selectedCategoryId) => {
+ return state.categories.find((category) => category.id === selectedCategoryId)
+ },
}
const actions = {
@@ -313,18 +321,25 @@ const actions = {
.catch((error) => context.commit('API_FAILURE', error))
},
- getCategories(context) {
- context.commit('startLoading', 'categories')
- return api.get(generateUrl('settings/apps/categories'))
- .then((response) => {
- if (response.data.length > 0) {
- context.commit('appendCategories', response.data)
+ async getCategories(context, { shouldRefetchCategories = false } = {}) {
+ if (shouldRefetchCategories || !context.state.gettingCategoriesPromise) {
+ context.commit('startLoading', 'categories')
+ try {
+ const categoriesPromise = api.get(generateUrl('settings/apps/categories'))
+ context.commit('updateCategories', categoriesPromise)
+ const categoriesPromiseResponse = await categoriesPromise
+ if (categoriesPromiseResponse.data.length > 0) {
+ context.commit('appendCategories', categoriesPromiseResponse.data)
context.commit('stopLoading', 'categories')
return true
}
+ context.commit('stopLoading', 'categories')
return false
- })
- .catch((error) => context.commit('API_FAILURE', error))
+ } catch (error) {
+ context.commit('API_FAILURE', error)
+ }
+ }
+ return context.state.gettingCategoriesPromise
},
}