From 396e53b1a67506f9cc869cc08a503f60d652576d Mon Sep 17 00:00:00 2001 From: "Daniel J. Summers" Date: Fri, 22 Sep 2017 23:30:23 -0500 Subject: [PATCH] Editing request works A "mark prayed" update uses the same fields, so we only have one "update request" action now --- src/app/src/api/index.js | 14 +++-- .../src/components/request/EditRequest.vue | 56 +++++++++++++++++++ src/app/src/components/request/NewRequest.vue | 13 ++++- .../components/request/RequestListItem.vue | 18 ++++-- src/app/src/store/action-types.js | 4 +- src/app/src/store/index.js | 8 +-- 6 files changed, 93 insertions(+), 20 deletions(-) create mode 100644 src/app/src/components/request/EditRequest.vue diff --git a/src/app/src/api/index.js b/src/app/src/api/index.js index 09360ca..ea35b1d 100644 --- a/src/app/src/api/index.js +++ b/src/app/src/api/index.js @@ -32,14 +32,18 @@ export default { addRequest: requestText => http.post('request/', { requestText }), /** - * Mark a prayer request as having been prayed - * @param {string} requestId The Id of the request + * Update a prayer request + * @param request The request (should have requestId, status, and updateText properties) */ - markPrayed: requestId => http.post(`request/${requestId}/history`, { status: 'Prayed', updateText: '' }), + updateRequest: request => http.post(`request/${request.requestId}/history`, { + status: request.status, + updateText: request.updateText + }), /** - * Get a prayer request + * Get a prayer request (journal-style; only latest update) + * @param {string} requestId The Id of the request to retrieve */ - getPrayerRequest: requestId => http.get(`request/${requestId}`) + getRequest: requestId => http.get(`request/${requestId}`) } diff --git a/src/app/src/components/request/EditRequest.vue b/src/app/src/components/request/EditRequest.vue new file mode 100644 index 0000000..a4bcd95 --- /dev/null +++ b/src/app/src/components/request/EditRequest.vue @@ -0,0 +1,56 @@ + + + \ No newline at end of file diff --git a/src/app/src/components/request/NewRequest.vue b/src/app/src/components/request/NewRequest.vue index 4f093e1..5fa69ca 100644 --- a/src/app/src/components/request/NewRequest.vue +++ b/src/app/src/components/request/NewRequest.vue @@ -1,12 +1,12 @@ @@ -27,7 +27,14 @@ export default { } }, methods: { - saveRequest: async function () { + closeDialog () { + this.form.requestText = '' + this.showNewVisible = false + }, + openDialog () { + this.showNewVisible = true + }, + async saveRequest () { await this.$store.dispatch(actions.ADD_REQUEST, { progress: this.$Progress, requestText: this.form.requestText diff --git a/src/app/src/components/request/RequestListItem.vue b/src/app/src/components/request/RequestListItem.vue index 6c51680..ccb9d13 100644 --- a/src/app/src/components/request/RequestListItem.vue +++ b/src/app/src/components/request/RequestListItem.vue @@ -3,7 +3,7 @@ el-col(:span='4') p el-button(icon='check' @click='markPrayed()' title='Pray') - el-button(icon='edit' @click='editRequest()' title='Edit') + edit-request(:request='request') el-button(icon='document' @click='viewHistory()' title='Show History') el-col(:span='16'): p {{ request.text }} el-col(:span='4'): p {{ asOf }} @@ -14,26 +14,32 @@ import moment from 'moment' +import EditRequest from './EditRequest' + import actions from '@/store/action-types' export default { name: 'request-list-item', - props: ['request'], + props: [ 'request' ], data () { return {} }, + components: { + EditRequest + }, methods: { markPrayed () { - this.$store.dispatch(actions.MARK_PRAYED, { + this.$store.dispatch(actions.UPDATE_REQUEST, { progress: this.$Progress, - requestId: this.request.requestId + requestId: this.request.requestId, + status: 'Prayed', + updateText: '' }) } }, computed: { asOf () { - // FIXME: why isn't this already a number? - return moment(parseInt(this.request.asOf)).fromNow() + return moment(this.request.asOf).fromNow() } } } diff --git a/src/app/src/store/action-types.js b/src/app/src/store/action-types.js index 7eb40de..2c2a2a3 100644 --- a/src/app/src/store/action-types.js +++ b/src/app/src/store/action-types.js @@ -5,6 +5,6 @@ export default { ADD_REQUEST: 'add-request', /** Action to load the user's prayer journal */ LOAD_JOURNAL: 'load-journal', - /** Action to mark a request as prayed */ - MARK_PRAYED: 'mark-prayed' + /** Action to update a request */ + UPDATE_REQUEST: 'update-request' } diff --git a/src/app/src/store/index.js b/src/app/src/store/index.js index 7a5759a..3de729e 100644 --- a/src/app/src/store/index.js +++ b/src/app/src/store/index.js @@ -92,11 +92,11 @@ export default new Vuex.Store({ commit(mutations.LOADING_JOURNAL, false) } }, - async [actions.MARK_PRAYED] ({ commit }, { progress, requestId }) { + async [actions.UPDATE_REQUEST] ({ commit }, { progress, requestId, status, updateText }) { + progress.start() try { - progress.start() - await api.markPrayed(requestId) - const request = await api.getPrayerRequest(requestId) + await api.updateRequest({ requestId, status, updateText }) + const request = await api.getRequest(requestId) commit(mutations.REQUEST_UPDATED, request.data) progress.finish() } catch (err) {