11<template >
2- <ClientOnly >
3- <div class =" actions-container" >
4- <button
5- @click =" confirmDelete"
6- class =" action-button delete-all"
7- :disabled =" !hasTodos"
8- >
9- Delete All Tasks
10- </button >
11- <button
12- @click =" toggleAllCompletion"
13- class =" action-button toggle-all"
14- :disabled =" !hasTodos"
15- >
16- {{ allCompleted ? 'Uncomplete All' : 'Complete All' }}
17- </button >
18- </div >
19- </ClientOnly >
20- </template >
21-
22- <script setup lang="ts">
23- import { computed } from ' vue'
24- import { storeToRefs } from ' pinia'
25- import { useTodoStore } from ' ~/stores/todo-store'
26-
27- const store = useTodoStore ()
28- const { todos } = storeToRefs (store )
29-
30- const hasTodos = computed (() => todos .value .length > 0 )
31- const allCompleted = computed (() =>
32- todos .value .length > 0 && todos .value .every (todo => todo .completed )
33- )
34-
35- const confirmDelete = () => {
36- if (confirm (' Are you sure you want to delete all tasks?' )) {
37- store .deleteAllTodos ()
38- }
2+ <ClientOnly >
3+ <div class =" actions-container" >
4+ <button @click =" confirmDelete" class =" action-button delete-all" :disabled =" !hasTodos" >
5+ Delete All Tasks
6+ </button >
7+ <button @click =" toggleAllCompletion" class =" action-button toggle-all" :disabled =" !hasTodos" >
8+ {{ allCompleted ? 'Uncomplete All' : 'Complete All' }}
9+ </button >
10+ </div >
11+ </ClientOnly >
12+ </template >
13+
14+ <script setup lang="ts">
15+ import { computed } from ' vue'
16+ import { storeToRefs } from ' pinia'
17+ import { useTodoStore } from ' ~/stores/todo-store'
18+
19+ const store = useTodoStore ()
20+ const { todos } = storeToRefs (store )
21+
22+ const hasTodos = computed (() => todos .value .length > 0 )
23+ const allCompleted = computed (() =>
24+ todos .value .length > 0 && todos .value .every ((todo : { completed: any }) => todo .completed )
25+ )
26+
27+ const confirmDelete = () => {
28+ if (confirm (' Are you sure you want to delete all tasks?' )) {
29+ store .deleteAllTodos ()
3930 }
40-
41- const toggleAllCompletion = () => {
42- if ( allCompleted . value ) {
43- store . uncompleteAllTodos ()
44- } else {
45- store . completeAllTodos ()
46- }
31+ }
32+
33+ const toggleAllCompletion = () => {
34+ if ( allCompleted . value ) {
35+ store . uncompleteAllTodos ()
36+ } else {
37+ store . completeAllTodos ()
4738 }
48- </script >
49-
50- <style scoped>
51- .actions-container {
52- display : flex ;
53- gap : 1rem ;
54- margin : 1rem 0 ;
55- justify-content : center ;
56- }
57-
58- .action-button {
59- padding : 0.5rem 1rem ;
60- border-radius : 4px ;
61- border : none ;
62- cursor : pointer ;
63- font-weight : bold ;
64- transition : all 0.2s ;
65- }
66-
67- .action-button :disabled {
68- opacity : 0.5 ;
69- cursor : not-allowed ;
70- }
71-
72- .action-button :not (:disabled ) {
73- opacity : 1 ;
74- }
75-
76- .delete-all {
77- background-color : #ff4444 ;
78- color : white ;
79- }
80-
81- .delete-all :hover:not (:disabled ) {
82- background-color : #ff6666 ;
83- }
84-
85- .toggle-all {
86- background-color : #4CAF50 ;
87- color : white ;
88- }
89-
90- .toggle-all :hover:not (:disabled ) {
91- background-color : #45a049 ;
92- }
93- </style >
39+ }
40+ </script >
41+
42+ <style scoped>
43+ .actions-container {
44+ display : flex ;
45+ gap : 1rem ;
46+ margin : 1rem 0 ;
47+ justify-content : center ;
48+ }
49+
50+ .action-button {
51+ padding : 0.5rem 1rem ;
52+ border-radius : 4px ;
53+ border : none ;
54+ cursor : pointer ;
55+ font-weight : bold ;
56+ transition : all 0.2s ;
57+ }
58+
59+ .action-button :disabled {
60+ opacity : 0.5 ;
61+ cursor : not-allowed ;
62+ }
63+
64+ .action-button :not (:disabled ) {
65+ opacity : 1 ;
66+ }
67+
68+ .delete-all {
69+ background-color : #ff4444 ;
70+ color : white ;
71+ }
72+
73+ .delete-all :hover:not (:disabled ) {
74+ background-color : #ff6666 ;
75+ }
76+
77+ .toggle-all {
78+ background-color : #4CAF50 ;
79+ color : white ;
80+ }
81+
82+ .toggle-all :hover:not (:disabled ) {
83+ background-color : #45a049 ;
84+ }
85+ </style >
0 commit comments