Skip to content

Commit 266b171

Browse files
committed
80
1 parent 61193fc commit 266b171

File tree

5 files changed

+109
-78
lines changed

5 files changed

+109
-78
lines changed

db.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,42 @@
164164
"completed": false,
165165
"body": "asdf",
166166
"id": 35
167+
},
168+
{
169+
"subject": "asd",
170+
"completed": false,
171+
"body": "asdfff",
172+
"id": 36
173+
},
174+
{
175+
"subject": "e",
176+
"completed": false,
177+
"body": "fff",
178+
"id": 37
179+
},
180+
{
181+
"subject": "f",
182+
"completed": false,
183+
"body": "fa",
184+
"id": 38
185+
},
186+
{
187+
"subject": "asdf",
188+
"completed": false,
189+
"body": "asdffffffdf",
190+
"id": 39
191+
},
192+
{
193+
"subject": "asdf",
194+
"completed": false,
195+
"body": "asdf",
196+
"id": 40
197+
},
198+
{
199+
"subject": "asdf",
200+
"completed": false,
201+
"body": "asdffff",
202+
"id": 41
167203
}
168204
]
169205
}

src/App.vue

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -15,58 +15,20 @@
1515
<div class="container">
1616
<router-view/>
1717
</div>
18-
<transition name="slide">
19-
<Toast
20-
v-if="showToast"
21-
:message="toastMessage"
22-
:type="toastAlertType"
23-
/>
24-
</transition>
18+
19+
<Toast />
2520
</template>
2621

2722
<script>
2823
import Toast from '@/components/Toast.vue';
29-
import { useToast } from '@/composables/toast';
3024
3125
export default {
3226
components: {
3327
Toast
3428
},
35-
setup() {
36-
const {
37-
toastMessage,
38-
toastAlertType,
39-
showToast,
40-
triggerToast
41-
} = useToast();
42-
43-
console.log(showToast.value);
44-
45-
return {
46-
toastMessage,
47-
toastAlertType,
48-
showToast,
49-
triggerToast
50-
}
51-
}
5229
}
5330
</script>
5431

5532
<style scoped>
56-
.slide-enter-active,
57-
.slide-leave-active {
58-
transition: all 0.5s ease;
59-
}
60-
61-
.slide-enter-from,
62-
.slide-leave-to {
63-
opacity: 0;
64-
transform: translateY(-30px);
65-
}
6633
67-
.slide-enter-to,
68-
.slide-leave-from {
69-
opacity: 1;
70-
transform: translateY(0px);
71-
}
7234
</style>

src/components/Toast.vue

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,53 @@
11
<template>
2-
<div
3-
class="alert toast-box"
4-
:class="`alert-${type}`"
5-
role="alert"
6-
>
7-
{{ message }}
2+
<div class="toast-box">
3+
<transition-group name="slide">
4+
<div
5+
v-for="toast in toasts"
6+
:key="toast.id"
7+
class="alert"
8+
:class="`alert-${toast.type}`"
9+
role="alert"
10+
>
11+
{{ toast.message }}
12+
</div>
13+
</transition-group>
814
</div>
915
</template>
1016

1117
<script>
18+
import { useToast } from '@/composables/toast';
1219
export default {
13-
props: {
14-
message: {
15-
type: String,
16-
required: true
17-
},
18-
type: {
19-
type: String,
20-
default: 'success'
20+
setup() {
21+
const { toasts } = useToast();
22+
23+
return {
24+
toasts
2125
}
2226
}
2327
}
2428
</script>
2529

26-
<style>
30+
<style scoped>
2731
.toast-box {
2832
position: fixed;
2933
top: 10px;
3034
right: 10px;
3135
}
36+
37+
.slide-enter-active,
38+
.slide-leave-active {
39+
transition: all 0.5s ease;
40+
}
41+
42+
.slide-enter-from,
43+
.slide-leave-to {
44+
opacity: 0;
45+
transform: translateY(-30px);
46+
}
47+
48+
.slide-enter-to,
49+
.slide-leave-from {
50+
opacity: 1;
51+
transform: translateY(0px);
52+
}
3253
</style>

src/composables/toast.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,17 @@ import { useStore } from 'vuex';
33

44
export const useToast = () => {
55
const store = useStore();
6-
const toastMessage = computed(() => store.getters['toast/toastMessageWithSmile']);
7-
const toastAlertType = computed(() => store.state.toast.toastAlertType);
8-
const showToast = computed(() => store.state.toast.showToast);
6+
const toasts = computed(() => store.state.toast.toasts);
7+
// const toastMessage = computed(() => store.getters['toast/toastMessageWithSmile']);
8+
// const toastAlertType = computed(() => store.state.toast.toastAlertType);
9+
// const showToast = computed(() => store.state.toast.showToast);
910

1011
const triggerToast = (message, type = 'success') => {
1112
store.dispatch('toast/triggerToast', message, type);
1213
}
1314

1415
return {
15-
toastMessage,
16-
toastAlertType,
17-
showToast,
16+
toasts,
1817
triggerToast
1918
}
2019
}

src/store/modules/toast/index.js

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,45 @@
11
export default {
22
namespaced: true,
33
state: {
4-
toastMessage: '',
5-
toastAlertType: '',
6-
showToast: false,
4+
toasts: [],
5+
// toastMessage: '',
6+
// toastAlertType: '',
7+
// showToast: false,
78
},
89
mutations: {
9-
UPDATE_TOAST_MESSAGE (state, payload) {
10-
state.toastMessage = payload;
10+
// UPDATE_TOAST_MESSAGE (state, payload) {
11+
// state.toastMessage = payload;
12+
// },
13+
// UPDATE_TOAST_ALERT_TYPE (state, payload) {
14+
// state.toastAlertType = payload;
15+
// },
16+
// UPDATE_TOAST_STATUS (state, payload) {
17+
// state.showToast = payload;
18+
// },
19+
ADD_TOAST(state, payload) {
20+
state.toasts.push(payload);
1121
},
12-
UPDATE_TOAST_ALERT_TYPE (state, payload) {
13-
state.toastAlertType = payload;
22+
REMOVE_TOAST(state) {
23+
state.toasts.shift();
1424
},
15-
UPDATE_TOAST_STATUS (state, payload) {
16-
state.showToast = payload;
17-
}
1825
},
1926
actions: {
2027
triggerToast({ commit }, message, type = 'success') {
21-
commit('UPDATE_TOAST_MESSAGE', message)
22-
commit('UPDATE_TOAST_ALERT_TYPE', type)
23-
commit('UPDATE_TOAST_STATUS', true)
28+
// commit('UPDATE_TOAST_MESSAGE', message)
29+
// commit('UPDATE_TOAST_ALERT_TYPE', type)
30+
// commit('UPDATE_TOAST_STATUS', true)
31+
commit('ADD_TOAST', {
32+
id: Date.now(),
33+
message,
34+
type,
35+
});
2436

2537
setTimeout(() => {
26-
commit('UPDATE_TOAST_MESSAGE', '')
27-
commit('UPDATE_TOAST_ALERT_TYPE', '')
28-
commit('UPDATE_TOAST_STATUS', false)
29-
}, 5000)
38+
// commit('UPDATE_TOAST_MESSAGE', '')
39+
// commit('UPDATE_TOAST_ALERT_TYPE', '')
40+
// commit('UPDATE_TOAST_STATUS', false)
41+
commit('REMOVE_TOAST');
42+
}, 10000)
3043
}
3144
},
3245
getters: {

0 commit comments

Comments
 (0)