Skip to content

Commit c475eb8

Browse files
committed
EventList now is using Vuex
1 parent ac5ce95 commit c475eb8

File tree

3 files changed

+16
-32
lines changed

3 files changed

+16
-32
lines changed

db.json

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -71,24 +71,6 @@
7171
"name": "Mary Gordon"
7272
}
7373
]
74-
},
75-
{
76-
"id": 2564147,
77-
"user": {
78-
"id": "abc123",
79-
"name": "Adam Jahr"
80-
},
81-
"category": "nature",
82-
"organizer": {
83-
"id": "abc123",
84-
"name": "Adam Jahr"
85-
},
86-
"title": "Working?",
87-
"description": "",
88-
"___location": "",
89-
"date": "",
90-
"time": "",
91-
"attendees": []
9274
}
9375
]
9476
}

src/store.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,25 @@ export default new Vuex.Store({
2121
mutations: {
2222
ADD_EVENT(state, event) {
2323
state.events.push(event)
24+
},
25+
SET_EVENTS(state, events) {
26+
state.events = events
2427
}
2528
},
2629
actions: {
2730
createEvent({ commit }, event) {
2831
return EventService.postEvent(event).then(() => {
2932
commit('ADD_EVENT', event)
3033
})
34+
},
35+
fetchEvents({ commit }) {
36+
EventService.getEvents()
37+
.then(response => {
38+
commit('SET_EVENTS', response.data)
39+
})
40+
.catch(error => {
41+
console.log('There was an error:', error.response)
42+
})
3143
}
3244
},
3345
getters: {

src/views/EventList.vue

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,15 @@
77

88
<script>
99
import EventCard from '@/components/EventCard.vue'
10-
import EventService from '@/services/EventService.js'
10+
import { mapState } from 'vuex'
1111
1212
export default {
1313
components: {
1414
EventCard
1515
},
16-
data() {
17-
return {
18-
events: []
19-
}
20-
},
2116
created() {
22-
EventService.getEvents()
23-
.then(response => {
24-
this.events = response.data
25-
})
26-
.catch(error => {
27-
console.log('There was an error:', error.response)
28-
})
29-
}
17+
this.$store.dispatch('fetchEvents')
18+
},
19+
computed: mapState(['events'])
3020
}
3121
</script>

0 commit comments

Comments
 (0)