Skip to content

Commit 234d4e0

Browse files
committed
Make lists sortable & draggable
1 parent 8f09b6d commit 234d4e0

File tree

5 files changed

+58
-10
lines changed

5 files changed

+58
-10
lines changed

package-lock.json

+13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"uuid": "^3.2.1",
1414
"vue": "^2.5.2",
1515
"vue-router": "^3.0.1",
16+
"vuedraggable": "^2.16.0",
1617
"vuex": "^3.0.1",
1718
"vuex-persistedstate": "^2.4.2"
1819
},

src/App.vue

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ html::-webkit-scrollbar-track
2626
2727
html::-webkit-scrollbar
2828
{
29-
width: 8px;
29+
width: 10px;
30+
height: 10px;
3031
background-color: #F5F5F505;
3132
}
3233

src/components/Project.vue

+28-9
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,20 @@
88
</button>
99
</router-link>
1010
<div class="columns m-4 mt-50">
11-
<list
12-
v-for="list in project.lists"
13-
:key="list.id"
14-
:list="list"
15-
:projectId="projectId"
16-
>
17-
</list>
11+
<draggable
12+
element="span"
13+
v-model="project.lists"
14+
@end="onEnd"
15+
class="d-inherit"
16+
>
17+
<list
18+
v-for="list in project.lists"
19+
:key="list.id"
20+
:list="list"
21+
:projectId="projectId"
22+
>
23+
</list>
24+
</draggable>
1825
<div class="column">
1926
<div class="card">
2027
<div class="card-content new-list-card-content">
@@ -35,11 +42,13 @@
3542
<script>
3643
import ItemListForm from '@/components/ItemListForm';
3744
import List from '@/components/List';
45+
import draggable from 'vuedraggable';
3846
export default {
3947
name: 'Project',
4048
components: {
4149
ItemListForm,
42-
List
50+
List,
51+
draggable
4352
},
4453
computed: {
4554
projects() {
@@ -50,7 +59,7 @@ export default {
5059
return proj.id == this.projectId
5160
});
5261
return currentProject;
53-
}
62+
},
5463
},
5564
data() {
5665
return {
@@ -64,6 +73,12 @@ export default {
6473
//Add list to project
6574
this.$store.dispatch('addList', { list: this.newList, projectId: this.projectId});
6675
this.newList = '';
76+
},
77+
onEnd() {
78+
this.$store.dispatch('updateListPosition', {
79+
projectId: this.projectId,
80+
lists: this.project.lists
81+
});
6782
}
6883
}
6984
}
@@ -121,4 +136,8 @@ export default {
121136
.w100 {
122137
width: 100%;
123138
}
139+
140+
.d-inherit {
141+
display: inherit;
142+
}
124143
</style>

src/store/index.js

+14
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ export const store = new Vuex.Store({
4343
let listIndex = payload.listIndex;
4444
state.projects[projectIndex].lists.splice(listIndex, 1);
4545
},
46+
updateListPosition(state, payload) {
47+
let projectIndex = payload.projectIndex;
48+
let lists = payload.lists;
49+
state.projects[projectIndex].lists = lists;
50+
},
4651
removeItem(state, payload) {
4752
let projectIndex = payload.projectIndex;
4853
let listIndex = payload.listIndex;
@@ -89,6 +94,15 @@ export const store = new Vuex.Store({
8994
}
9095
}
9196
},
97+
updateListPosition({ commit, state }, payload) {
98+
let lists = payload.lists;
99+
let projectIndex = state.projects.findIndex(proj => {
100+
return proj.id == payload.projectId;
101+
});
102+
if(projectIndex > -1) {
103+
commit('updateListPosition', { projectIndex, lists });
104+
}
105+
},
92106
addItem({ commit, state }, payload) {
93107
let item = payload.item;
94108
let listId = payload.listId;

0 commit comments

Comments
 (0)