Skip to content

Commit bb08353

Browse files
committed
feat(ui): show toast on error
1 parent ea745a0 commit bb08353

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

src/App.vue

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<script setup lang="ts">
22
import { computed, onMounted, reactive, ref, watch } from 'vue'
33
import { PhPlus } from '@phosphor-icons/vue'
4+
import { useToast } from 'vue-toastification'
45
import Todo from './components/TodoItem.vue'
56
import { slugger } from './lib/slugger'
67
@@ -18,14 +19,22 @@ const completedPercentage = computed(() => {
1819
return (completedTodos / totalOfTodos) * 100
1920
})
2021
22+
const toast = useToast()
23+
2124
function addNewTodo() {
2225
// Prevent todo names less than 2 characters
23-
if (todoInput.value.length < 2) return
26+
if (todoInput.value.length < 2) {
27+
toast.warning("The to-do name has to be more than 2 characters")
28+
return
29+
}
2430
2531
// Prevent repeated todos
2632
const repeatedList = todoList.todos.filter(todo => slugger(todo.name) === slugger(todoInput.value))
2733
console.log(repeatedList)
28-
if (repeatedList.length > 0) return
34+
if (repeatedList.length > 0) {
35+
toast.warning("There is already a to-do with that name")
36+
return
37+
}
2938
3039
3140
todoList.todos.push({

src/main.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
import './assets/main.css'
2-
31
import { createApp } from 'vue'
2+
import Toast, { type PluginOptions } from 'vue-toastification'
43
import App from './App.vue'
54

6-
createApp(App).mount('#app')
5+
import './assets/main.css'
6+
import 'vue-toastification/dist/index.css'
7+
''
8+
const app = createApp(App)
9+
10+
const toastOptions: PluginOptions = {}
11+
12+
app.use(Toast, toastOptions)
13+
app.mount('#app')

0 commit comments

Comments
 (0)