diff --git a/src/components/navigation/AppNavigationBoard.vue b/src/components/navigation/AppNavigationBoard.vue index 70ca1efc6..d62d75446 100644 --- a/src/components/navigation/AppNavigationBoard.vue +++ b/src/components/navigation/AppNavigationBoard.vue @@ -21,7 +21,7 @@ --> @@ -74,8 +84,10 @@ export default { classes: [], deleted: false, loading: false, + editing: false, menuOpen: false, - undoTimeoutHandle: null + undoTimeoutHandle: null, + editTitle: '' } }, computed: { @@ -96,7 +108,11 @@ export default { if (this.loading === false) { actions.push({ - action: () => {}, + action: () => { + this.hideMenu() + this.editTitle = this.board.title + this.editing = true + }, icon: 'icon-edit', text: t('deck', 'Edit board') }) @@ -160,11 +176,20 @@ export default { hideMenu() { this.menuOpen = false }, - cancelEdit(e) { - const editingIdx = this.classes.indexOf('editing') - if (editingIdx !== -1) { - this.classes.splice(editingIdx, 1) + applyEdit(e) { + this.editing = false + if (this.editTitle) { + this.loading = true + const copy = JSON.parse(JSON.stringify(this.board)) + copy.title = this.editTitle + this.$store.dispatch('updateBoard', copy) + .then(() => { + this.loading = false + }) } + }, + cancelEdit(e) { + this.editing = false } }, inject: [ @@ -172,3 +197,9 @@ export default { ] } + + diff --git a/src/store/main.js b/src/store/main.js index b34b65cbd..08ab878cc 100644 --- a/src/store/main.js +++ b/src/store/main.js @@ -82,6 +82,13 @@ export default new Vuex.Store({ } }, mutations: { + /** + * Adds or replaces a board in the store. + * Matches a board by it's id. + * + * @param state + * @param board + */ addBoard(state, board) { const indexExisting = state.boards.findIndex((b) => { return board.id === b.id @@ -137,6 +144,17 @@ export default new Vuex.Store({ commit('addBoard', board) }) }, + /** + * Updates a board API side. + * + * @param commit + * @param board The board to update. + * @return {Promise} + */ + async updateBoard({ commit }, board) { + const storedBoard = await apiClient.updateBoard(board) + commit('addBoard', storedBoard) + }, createBoard({ commit }, boardData) { apiClient.createBoard(boardData) .then((board) => {