From a4b1bc1a82630f5fb36b16a7fbd8abff18530f3d Mon Sep 17 00:00:00 2001 From: Angelina Filippova Date: Tue, 2 Apr 2019 22:26:59 +0300 Subject: [PATCH] Add ability to delete note --- src/api/reports.js | 8 +++ src/api/reportsData.js | 60 +++++++++---------- src/store/modules/reports.js | 9 ++- src/views/reports/components/TimelineItem.vue | 15 +++-- 4 files changed, 55 insertions(+), 37 deletions(-) diff --git a/src/api/reports.js b/src/api/reports.js index 500ecfef..c4d6e84a 100644 --- a/src/api/reports.js +++ b/src/api/reports.js @@ -4,3 +4,11 @@ export function fetchReports(index, size) { const response = reports.slice(index, index + size) return response } + +export function deleteNote(reportId, noteId) { + const updatedNotes = reports + .find(report => report.id === reportId) + .notes + .filter(note => note.id !== noteId) + return updatedNotes +} diff --git a/src/api/reportsData.js b/src/api/reportsData.js index bc86469b..36bc9b66 100644 --- a/src/api/reportsData.js +++ b/src/api/reportsData.js @@ -8,8 +8,8 @@ export const reports = [ header: 'Report #1', // content content: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.', notes: [ - { author: 'Nick', text: 'Lorem ipsum', timestamp: '2019/4/13' }, - { author: 'Val', text: 'dolor sit amet', timestamp: '2019/4/13' } + { author: 'Nick', text: 'Lorem ipsum', id: '1', timestamp: '2019/4/13' }, + { author: 'Val', text: 'dolor sit amet', id: '2', timestamp: '2019/4/13' } ] }, { @@ -21,8 +21,8 @@ export const reports = [ header: 'Report #2', content: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.', notes: [ - { author: 'Tony', text: 'consectetur adipiscing elit', timestamp: '2019/4/2' }, - { author: 'Zac', text: 'sed do eiusmod tempor incididunt', timestamp: '2019/4/3' } + { author: 'Tony', text: 'consectetur adipiscing elit', id: '3', timestamp: '2019/4/2' }, + { author: 'Zac', text: 'sed do eiusmod tempor incididunt', id: '4', timestamp: '2019/4/3' } ] }, { @@ -33,7 +33,7 @@ export const reports = [ object: 'Jen', header: 'Report #3', content: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.', - notes: [{ author: 'Bruce', text: 'ut labore et dolore magna aliqua', timestamp: '2019/3/1' }] + notes: [{ author: 'Bruce', text: 'ut labore et dolore magna aliqua', id: '5', timestamp: '2019/3/1' }] }, { id: '4', @@ -44,8 +44,8 @@ export const reports = [ header: 'Report #4', // content content: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.', notes: [ - { author: 'Nick', text: 'Lorem ipsum', timestamp: '2019/4/13' }, - { author: 'Val', text: 'dolor sit amet', timestamp: '2019/4/13' } + { author: 'Nick', text: 'Lorem ipsum', id: '6', timestamp: '2019/4/13' }, + { author: 'Val', text: 'dolor sit amet', id: '7', timestamp: '2019/4/13' } ] }, { @@ -57,8 +57,8 @@ export const reports = [ header: 'Report #5', content: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.', notes: [ - { author: 'Tony', text: 'consectetur adipiscing elit', timestamp: '2019/4/2' }, - { author: 'Zac', text: 'sed do eiusmod tempor incididunt', timestamp: '2019/4/3' } + { author: 'Tony', text: 'consectetur adipiscing elit', id: '8', timestamp: '2019/4/2' }, + { author: 'Zac', text: 'sed do eiusmod tempor incididunt', id: '9', timestamp: '2019/4/3' } ] }, { @@ -69,7 +69,7 @@ export const reports = [ object: 'Jen', header: 'Report #6', content: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.', - notes: [{ author: 'Bruce', text: 'ut labore et dolore magna aliqua', timestamp: '2019/3/1' }] + notes: [{ author: 'Bruce', text: 'ut labore et dolore magna aliqua', id: '10', timestamp: '2019/3/1' }] }, { id: '7', @@ -80,8 +80,8 @@ export const reports = [ header: 'Report #7', // content content: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.', notes: [ - { author: 'Nick', text: 'Lorem ipsum', timestamp: '2019/4/13' }, - { author: 'Val', text: 'dolor sit amet', timestamp: '2019/4/13' } + { author: 'Nick', text: 'Lorem ipsum', id: '11', timestamp: '2019/4/13' }, + { author: 'Val', text: 'dolor sit amet', id: '12', timestamp: '2019/4/13' } ] }, { @@ -93,8 +93,8 @@ export const reports = [ header: 'Report #8', content: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.', notes: [ - { author: 'Tony', text: 'consectetur adipiscing elit', timestamp: '2019/4/2' }, - { author: 'Zac', text: 'sed do eiusmod tempor incididunt', timestamp: '2019/4/3' } + { author: 'Tony', text: 'consectetur adipiscing elit', id: '13', timestamp: '2019/4/2' }, + { author: 'Zac', text: 'sed do eiusmod tempor incididunt', id: '14', timestamp: '2019/4/3' } ] }, { @@ -105,7 +105,7 @@ export const reports = [ object: 'Jen', header: 'Report #9', content: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.', - notes: [{ author: 'Bruce', text: 'ut labore et dolore magna aliqua', timestamp: '2019/3/1' }] + notes: [{ author: 'Bruce', text: 'ut labore et dolore magna aliqua', id: '15', timestamp: '2019/3/1' }] }, { id: '10', @@ -116,8 +116,8 @@ export const reports = [ header: 'Report #10', // content content: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.', notes: [ - { author: 'Nick', text: 'Lorem ipsum', timestamp: '2019/4/13' }, - { author: 'Val', text: 'dolor sit amet', timestamp: '2019/4/13' } + { author: 'Nick', text: 'Lorem ipsum', id: '16', timestamp: '2019/4/13' }, + { author: 'Val', text: 'dolor sit amet', id: '17', timestamp: '2019/4/13' } ] }, { @@ -129,8 +129,8 @@ export const reports = [ header: 'Report #11', content: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.', notes: [ - { author: 'Tony', text: 'consectetur adipiscing elit', timestamp: '2019/4/2' }, - { author: 'Zac', text: 'sed do eiusmod tempor incididunt', timestamp: '2019/4/3' } + { author: 'Tony', text: 'consectetur adipiscing elit', id: '18', timestamp: '2019/4/2' }, + { author: 'Zac', text: 'sed do eiusmod tempor incididunt', id: '19', timestamp: '2019/4/3' } ] }, { @@ -141,7 +141,7 @@ export const reports = [ object: 'Jen', header: 'Report #12', content: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.', - notes: [{ author: 'Bruce', text: 'ut labore et dolore magna aliqua', timestamp: '2019/3/1' }] + notes: [{ author: 'Bruce', text: 'ut labore et dolore magna aliqua', id: '20', timestamp: '2019/3/1' }] }, { id: '13', @@ -152,8 +152,8 @@ export const reports = [ header: 'Report #13', // content content: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.', notes: [ - { author: 'Nick', text: 'Lorem ipsum', timestamp: '2019/4/13' }, - { author: 'Val', text: 'dolor sit amet', timestamp: '2019/4/13' } + { author: 'Nick', text: 'Lorem ipsum', id: '21', timestamp: '2019/4/13' }, + { author: 'Val', text: 'dolor sit amet', id: '22', timestamp: '2019/4/13' } ] }, { @@ -165,8 +165,8 @@ export const reports = [ header: 'Report #14', content: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.', notes: [ - { author: 'Tony', text: 'consectetur adipiscing elit', timestamp: '2019/4/2' }, - { author: 'Zac', text: 'sed do eiusmod tempor incididunt', timestamp: '2019/4/3' } + { author: 'Tony', text: 'consectetur adipiscing elit', id: '23', timestamp: '2019/4/2' }, + { author: 'Zac', text: 'sed do eiusmod tempor incididunt', id: '24', timestamp: '2019/4/3' } ] }, { @@ -177,7 +177,7 @@ export const reports = [ object: 'Jen', header: 'Report #15', content: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.', - notes: [{ author: 'Bruce', text: 'ut labore et dolore magna aliqua', timestamp: '2019/3/1' }] + notes: [{ author: 'Bruce', text: 'ut labore et dolore magna aliqua', id: '25', timestamp: '2019/3/1' }] }, { id: '16', @@ -188,8 +188,8 @@ export const reports = [ header: 'Report #16', // content content: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.', notes: [ - { author: 'Nick', text: 'Lorem ipsum', timestamp: '2019/4/13' }, - { author: 'Val', text: 'dolor sit amet', timestamp: '2019/4/13' } + { author: 'Nick', text: 'Lorem ipsum', id: '26', timestamp: '2019/4/13' }, + { author: 'Val', text: 'dolor sit amet', id: '27', timestamp: '2019/4/13' } ] }, { @@ -201,8 +201,8 @@ export const reports = [ header: 'Report #17', content: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.', notes: [ - { author: 'Tony', text: 'consectetur adipiscing elit', timestamp: '2019/4/2' }, - { author: 'Zac', text: 'sed do eiusmod tempor incididunt', timestamp: '2019/4/3' } + { author: 'Tony', text: 'consectetur adipiscing elit', id: '28', timestamp: '2019/4/2' }, + { author: 'Zac', text: 'sed do eiusmod tempor incididunt', id: '29', timestamp: '2019/4/3' } ] }, { @@ -213,6 +213,6 @@ export const reports = [ object: 'Jen', header: 'Report #18', content: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.', - notes: [{ author: 'Bruce', text: 'ut labore et dolore magna aliqua', timestamp: '2019/3/1' }] + notes: [{ author: 'Bruce', text: 'ut labore et dolore magna aliqua', id: '30', timestamp: '2019/3/1' }] } ] diff --git a/src/store/modules/reports.js b/src/store/modules/reports.js index 279f1994..f6d9fc16 100644 --- a/src/store/modules/reports.js +++ b/src/store/modules/reports.js @@ -1,4 +1,4 @@ -import { fetchReports } from '@/api/reports' +import { fetchReports, deleteNote } from '@/api/reports' const reports = { state: { @@ -35,6 +35,13 @@ const reports = { report.notes = [...report.notes, note] const reportIndex = state.fetchedReports.findIndex(report => report.id === reportId) commit('SET_REPORT', { reportIndex, report }) + }, + async DeleteNote({ commit, state }, { reportId, noteId }) { + const response = deleteNote(reportId, noteId) + const report = state.fetchedReports.find(report => report.id === reportId) + report.notes = response + const reportIndex = state.fetchedReports.findIndex(report => report.id === reportId) + commit('SET_REPORT', { reportIndex, report }) } } } diff --git a/src/views/reports/components/TimelineItem.vue b/src/views/reports/components/TimelineItem.vue index 93bdabcc..b83d94ea 100644 --- a/src/views/reports/components/TimelineItem.vue +++ b/src/views/reports/components/TimelineItem.vue @@ -9,10 +9,13 @@
- -

{{ $t('reports.from') }} {{ note.author }}

+ +
+

{{ $t('reports.from') }} {{ note.author }}

+ +

{{ note.timestamp }}

-

{{ note.text }}

+

{{ note.text }}

@@ -54,6 +57,9 @@ export default { const note = { author: currentUserNickname, text: this.$data.note, timestamp: '2019/04/01' } this.$store.dispatch('AddNote', { reportId, note }) this.$data.note = '' + }, + deleteNote(reportId, noteId) { + this.$store.dispatch('DeleteNote', { reportId, noteId }) } } } @@ -100,9 +106,6 @@ export default { box-shadow: 0 2px 5px 0 rgba(0,0,0,.1); margin-bottom: 10px; } - .note-text { - margin-bottom: 14px; - } .submit-button { display: block; margin: 7px 0 17px auto;