Skip to content

Commit 5f9dea2

Browse files
committed
65
1 parent cf2eacf commit 5f9dea2

File tree

5 files changed

+26
-41
lines changed

5 files changed

+26
-41
lines changed

db.json

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -70,36 +70,6 @@
7070
"completed": false,
7171
"body": "go to supermarket and buy milk",
7272
"id": 22
73-
},
74-
{
75-
"subject": "buy milk",
76-
"completed": false,
77-
"body": "buy milk at supermarket",
78-
"id": 23
79-
},
80-
{
81-
"subject": "asdfasdf",
82-
"completed": false,
83-
"body": "asdfasdf",
84-
"id": 24
85-
},
86-
{
87-
"subject": "asdf",
88-
"completed": false,
89-
"body": "asdf",
90-
"id": 25
91-
},
92-
{
93-
"subject": "123123",
94-
"completed": false,
95-
"body": "dfghdfgh",
96-
"id": 26
97-
},
98-
{
99-
"subject": "ab",
100-
"completed": false,
101-
"body": "ffffffdfdfasfff",
102-
"id": 28
10373
}
10474
]
10575
}

public/index.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
<strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
1414
</noscript>
1515
<div id="app"></div>
16-
<div id="modal"></div>
1716
<!-- built files will be auto injected -->
1817
</body>
1918
</html>

src/components/Modal.vue

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
<div class="modal-dialog">
44
<div class="modal-content">
55
<div class="modal-header">
6-
<h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
7-
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
8-
<span @click="onClose">&times;</span>
6+
<h5 class="modal-title">
7+
Delete Todo
8+
</h5>
9+
<button type="button" class="close">
10+
<span @click="onClose">&times;</span>
911
</button>
1012
</div>
1113
<div class="modal-body">
12-
...
14+
Are you sure you want to delete the todo?
1315
</div>
1416
<div class="modal-footer">
1517
<button
@@ -19,7 +21,11 @@
1921
>
2022
Close
2123
</button>
22-
<button type="button" class="btn btn-primary">Save changes</button>
24+
<button
25+
type="button"
26+
class="btn btn-danger"
27+
@click="onDelete"
28+
>Delete</button>
2329
</div>
2430
</div>
2531
</div>
@@ -32,8 +38,14 @@ export default {
3238
const onClose = () => {
3339
emit('close');
3440
}
41+
42+
const onDelete = () => {
43+
emit('delete');
44+
}
45+
3546
return {
36-
onClose
47+
onClose,
48+
onDelete
3749
}
3850
}
3951
}

src/components/TodoList.vue

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
<Modal
3535
v-if="showModal"
3636
@close="closeModal"
37+
@delete="deleteTodo"
3738
/>
3839
</template>
3940

@@ -71,8 +72,11 @@ export default {
7172
showModal.value = false;
7273
};
7374
74-
const deleteTodo = (index) => {
75-
emit('delete-todo', index);
75+
const deleteTodo = () => {
76+
emit('delete-todo', todoDeleteId.value);
77+
78+
showModal.value = false;
79+
todoDeleteId.value = null;
7680
};
7781
7882
const moveToPage = (todoId) => {

src/pages/todos/index.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@ export default {
122122
}
123123
};
124124
125-
const deleteTodo = async (index) => {
125+
const deleteTodo = async (id) => {
126126
error.value = '';
127-
const id = todos.value[index].id;
127+
128128
try {
129129
await axios.delete('http://localhost:3000/todos/' + id);
130130

0 commit comments

Comments
 (0)