зеркало из https://github.com/nextcloud/spreed.git
Purge state before loading new conversations
Signed-off-by: Marco Ambrosini <marcoambrosini@pm.me>
This commit is contained in:
Родитель
5e0d24766e
Коммит
04a79c8e52
|
@ -65,6 +65,7 @@ export default {
|
|||
* to the store.
|
||||
*/
|
||||
const conversations = await fetchConversations()
|
||||
this.$store.dispatch('purgeConversationsStore')
|
||||
conversations.data.ocs.data.forEach(conversation => {
|
||||
this.$store.dispatch('addConversation', conversation)
|
||||
})
|
||||
|
|
|
@ -21,10 +21,15 @@
|
|||
*/
|
||||
import Vue from 'vue'
|
||||
|
||||
const getDefaultState = () => {
|
||||
return {
|
||||
conversations: {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const state = {
|
||||
conversations: {
|
||||
},
|
||||
conversationsNames: {
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -43,18 +48,6 @@ const mutations = {
|
|||
addConversation(state, conversation) {
|
||||
Vue.set(state.conversations, conversation.token, conversation)
|
||||
},
|
||||
/**
|
||||
* Creates a key-value pair with conversation id and name
|
||||
* respectively.
|
||||
*
|
||||
* @param {object} state current state object;
|
||||
* @param {object} object destructuring object;
|
||||
* @param {string} object.token conversation token;
|
||||
* @param {string} object.displayName conversation name;
|
||||
*/
|
||||
indexConversationName(state, { token, displayName }) {
|
||||
Vue.set(state.conversationsNames, token, displayName)
|
||||
},
|
||||
/**
|
||||
* Deletes a conversation from the store.
|
||||
* @param {object} state current store state;
|
||||
|
@ -62,7 +55,13 @@ const mutations = {
|
|||
*/
|
||||
deleteConversation(state, conversation) {
|
||||
Vue.delete(state.conversations, conversation.token)
|
||||
Vue.delete(state.conversationsNames, conversation.token)
|
||||
},
|
||||
/**
|
||||
* Resets the store to it's original state
|
||||
* @param {object} state current store state;
|
||||
*/
|
||||
purgeConversationsStore(state) {
|
||||
Object.assign(state, getDefaultState())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -75,7 +74,6 @@ const actions = {
|
|||
*/
|
||||
addConversation(context, conversation) {
|
||||
context.commit('addConversation', conversation)
|
||||
context.commit('indexConversationName', conversation)
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -86,6 +84,13 @@ const actions = {
|
|||
*/
|
||||
deleteConversation(context, conversation) {
|
||||
context.commit('deleteConversation', conversation)
|
||||
},
|
||||
/**
|
||||
* Resets the store to it's original state.
|
||||
* @param {object} context default store context;
|
||||
*/
|
||||
purgeConversationsStore(context) {
|
||||
context.commit('purgeConversationsStore')
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче