Skip to content

Commit d041a62

Browse files
authored
Merge pull request #16 from deanfchung/master
User can delete routes now.
2 parents d08b89f + 2d03288 commit d041a62

File tree

6 files changed

+23
-3
lines changed

6 files changed

+23
-3
lines changed

src/components/HomeSideDropDown.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,5 +137,4 @@ export default {
137137
.input-container {
138138
margin-top: 1rem;
139139
}
140-
141140
</style>

src/components/RouteDisplay.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,13 @@ export default {
3636
}
3737
},
3838
methods: {
39-
...mapActions(['addRouteToRouteMap']),
39+
...mapActions(['addRouteToRouteMap', 'setRoutes']),
4040
handleEnterKeyPress () {
4141
this.addRouteToRouteMap(this.newRoute)
4242
.then(() => {
4343
this.newRoute = ''
4444
})
45+
4546
.catch(err => console.log(err))
4647
}
4748
}

src/components/Routes.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
v-for="route in Object.keys(routes)"
77
:key="route"
88
@click="handleClick(route)"
9+
v-on:keyup.delete="deleteSelectedRoute(route)"
910
>
1011
<!--
1112
<span class="panel-icon">
@@ -34,9 +35,13 @@ export default {
3435
...mapState(['routes', 'activeRoute'])
3536
},
3637
methods: {
37-
...mapActions(['setActiveRoute']),
38+
...mapActions(['setActiveRoute', 'deleteRoute']),
3839
handleClick (route) {
3940
this.setActiveRoute(route)
41+
},
42+
deleteSelectedRoute (route) {
43+
this.deleteRoute(route)
44+
this.setActiveRoute('')
4045
}
4146
}
4247
}

src/store/actions.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ const actions = {
112112
},
113113
[types.parentSelected]: ({ commit }, payload) => {
114114
commit(types.PARENT_SELECTED, payload)
115+
},
116+
[types.deleteRoute]: ({ state, commit }, payload) => {
117+
console.log('stat in actions:', state)
118+
commit(types.DELETE_ROUTE, payload)
115119
}
116120
}
117121

src/store/mutations.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ const mutations = {
103103
...state.routes,
104104
[payload]: []
105105
}
106+
console.log('payload in add_route', payload)
106107
},
107108
// Changes the component map
108109
[types.ADD_ROUTE_TO_COMPONENT_MAP]: (state, payload) => {
@@ -128,6 +129,7 @@ const mutations = {
128129
state.activeComponent = payload
129130
},
130131
[types.SET_ROUTES]: (state, payload) => {
132+
console.log('setroutespayload:', payload)
131133
state.routes = Object.assign({}, payload)
132134
},
133135
// invoked when a component is deleted
@@ -179,6 +181,13 @@ const mutations = {
179181
},
180182
[types.PARENT_SELECTED]: (state, payload) => {
181183
state.parentSelected = payload
184+
},
185+
[types.DELETE_ROUTE]: (state, payload) => {
186+
const stateCopy = state
187+
delete stateCopy.routes[payload]
188+
delete stateCopy.componentMap[payload]
189+
state = stateCopy
190+
console.log('aftermutations state', state)
182191
}
183192
}
184193

src/store/types.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export const ADD_COMPONENT_TO_COMPONENT_CHILDREN =
3939
'ADD_COMPONENT_TO_COMPONENT_CHILDREN'
4040
export const UPDATE_OPEN_MODAL = 'UPDATE_OPEN_MODAL'
4141
export const PARENT_SELECTED = 'PARENT_SELECTED'
42+
export const DELETE_ROUTE = 'DELETE_ROUTE'
4243

4344
// Actions
4445
export const registerComponent = 'registerComponent'
@@ -71,3 +72,4 @@ export const updateComponentChildrenValue = 'updateComponentChildrenValue'
7172
export const updateComponentNameInputValue = 'updateComponentNameInputValue'
7273
export const updateOpenModal = 'updateOpenModal'
7374
export const parentSelected = 'parentSelected'
75+
export const deleteRoute = 'deleteRoute'

0 commit comments

Comments
 (0)