diff --git a/src/store/index.ts b/src/store/index.ts index 0a5a060ee..54fad49ed 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -95,64 +95,40 @@ export const store = createStore({ }, }, actions: { - async [CURRENT_LIST]({state, commit}, currentList) { + async [CURRENT_LIST]({state, commit}, {list, forceUpdate = false}) { - if (currentList === null) { + if (list === null) { commit(CURRENT_LIST, {}) commit(BACKGROUND, null) commit(BLUR_HASH, null) return } - // Not sure if this is the right way to do it but hey, it works - if ( - // List changed - currentList.id !== state.currentList.id || - // The current list got a new background and didn't have one previously - ( - currentList.backgroundInformation && - !state.currentList.backgroundInformation - ) || - // The current list got a new background and had one previously - ( - currentList.backgroundInformation && - currentList.backgroundInformation.unsplashId && - state.currentList && - state.currentList.backgroundInformation && - state.currentList.backgroundInformation.unsplashId && - currentList.backgroundInformation.unsplashId !== state.currentList.backgroundInformation.unsplashId - ) || - // The new list has a background which is not an unsplash one and did not have one previously - ( - currentList.backgroundInformation && - currentList.backgroundInformation.type && - state.currentList && - state.currentList.backgroundInformation && - state.currentList.backgroundInformation.type - ) - ) { - if (currentList.backgroundInformation) { + // The forceUpdate parameter is used only when updating a list background directly because in that case + // the current list stays the same, but we want to show the new background right away. + if (list.id !== state.currentList.id || forceUpdate) { + if (list.backgroundInformation) { try { - const blurHash = await getBlobFromBlurHash(currentList.backgroundBlurHash) + const blurHash = await getBlobFromBlurHash(list.backgroundBlurHash) if (blurHash) { commit(BLUR_HASH, window.URL.createObjectURL(blurHash)) } const listService = new ListService() - const background = await listService.background(currentList) + const background = await listService.background(list) commit(BACKGROUND, background) } catch (e) { - console.error('Error getting background image for list', currentList.id, e) + console.error('Error getting background image for list', list.id, e) } } } - if (typeof currentList.backgroundInformation === 'undefined' || currentList.backgroundInformation === null) { + if (typeof list.backgroundInformation === 'undefined' || list.backgroundInformation === null) { commit(BACKGROUND, null) commit(BLUR_HASH, null) } - commit(CURRENT_LIST, currentList) + commit(CURRENT_LIST, list) }, async loadApp({dispatch}) { await checkAndSetApiUrl(window.API_URL) diff --git a/src/views/list/ListWrapper.vue b/src/views/list/ListWrapper.vue index 228372421..bd8f09b22 100644 --- a/src/views/list/ListWrapper.vue +++ b/src/views/list/ListWrapper.vue @@ -146,14 +146,14 @@ async function loadList(listIdToLoad: number) { if (listFromStore !== null) { store.commit(BACKGROUND, null) store.commit(BLUR_HASH, null) - store.commit(CURRENT_LIST, listFromStore) + store.dispatch(CURRENT_LIST, {list: listFromStore}) } // We create an extra list object instead of creating it in list.value because that would trigger a ui update which would result in bad ux. const list = new ListModel(listData) try { const loadedList = await listService.value.get(list) - await store.dispatch(CURRENT_LIST, loadedList) + await store.dispatch(CURRENT_LIST, {list: loadedList}) } finally { loadedListId.value = props.listId } diff --git a/src/views/list/settings/background.vue b/src/views/list/settings/background.vue index a574d4c98..cad2428d6 100644 --- a/src/views/list/settings/background.vue +++ b/src/views/list/settings/background.vue @@ -153,7 +153,7 @@ export default defineComponent({ } const list = await this.backgroundService.update({id: backgroundId, listId: this.$route.params.listId}) - await this.$store.dispatch(CURRENT_LIST, list) + await this.$store.dispatch(CURRENT_LIST, {list, forceUpdate: true}) this.$store.commit('namespaces/setListInNamespaceById', list) this.$store.commit('lists/setList', list) this.$message.success({message: this.$t('list.background.success')}) @@ -165,7 +165,7 @@ export default defineComponent({ } const list = await this.backgroundUploadService.create(this.$route.params.listId, this.$refs.backgroundUploadInput.files[0]) - await this.$store.dispatch(CURRENT_LIST, list) + await this.$store.dispatch(CURRENT_LIST, {list, forceUpdate: true}) this.$store.commit('namespaces/setListInNamespaceById', list) this.$store.commit('lists/setList', list) this.$message.success({message: this.$t('list.background.success')}) @@ -173,7 +173,7 @@ export default defineComponent({ async removeBackground() { const list = await this.listService.removeBackground(this.currentList) - await this.$store.dispatch(CURRENT_LIST, list) + await this.$store.dispatch(CURRENT_LIST, {list, forceUpdate: true}) this.$store.commit('namespaces/setListInNamespaceById', list) this.$store.commit('lists/setList', list) this.$message.success({message: this.$t('list.background.removeSuccess')}) diff --git a/src/views/list/settings/edit.vue b/src/views/list/settings/edit.vue index 38fe7a61d..4aff764ea 100644 --- a/src/views/list/settings/edit.vue +++ b/src/views/list/settings/edit.vue @@ -105,7 +105,7 @@ export default defineComponent({ async save() { await this.$store.dispatch('lists/updateList', this.list) - await this.$store.dispatch(CURRENT_LIST, this.list) + await this.$store.dispatch(CURRENT_LIST, {list: this.list}) this.setTitle(this.$t('list.edit.title', {list: this.list.title})) this.$message.success({message: this.$t('list.edit.success')}) this.$router.back() diff --git a/src/views/list/settings/share.vue b/src/views/list/settings/share.vue index 89f054d70..119769515 100644 --- a/src/views/list/settings/share.vue +++ b/src/views/list/settings/share.vue @@ -61,7 +61,7 @@ const userIsAdmin = computed(() => 'owner' in list.value && list.value.owner.id async function loadList(listId: number) { const listService = new ListService() const newList = await listService.get(new ListModel({id: listId})) - await store.dispatch(CURRENT_LIST, newList) + await store.dispatch(CURRENT_LIST, {list: newList}) list.value = newList } diff --git a/src/views/tasks/TaskDetailView.vue b/src/views/tasks/TaskDetailView.vue index 4e0382143..9a5c2f05a 100644 --- a/src/views/tasks/TaskDetailView.vue +++ b/src/views/tasks/TaskDetailView.vue @@ -520,7 +520,7 @@ export default defineComponent({ handler(parent) { const parentList = parent !== null ? parent.list : null if (parentList !== null) { - this.$store.commit(CURRENT_LIST, parentList) + this.$store.dispatch(CURRENT_LIST, {list: parentList}) } }, immediate: true,