@@ -4,7 +4,7 @@ import { settingsAtom, pomodoroAtom, browserSettingsAtom } from '@/lib/atoms'
4
4
import { getTodayInTimezone , isSameDate , t2d , d2t , getNow , parseNaturalLanguageRRule , parseRRule , d2s } from '@/lib/utils'
5
5
import { Card , CardContent , CardDescription , CardFooter , CardHeader , CardTitle } from '@/components/ui/card'
6
6
import { Button } from '@/components/ui/button'
7
- import { Coins , Edit , Trash2 , Check , Undo2 , MoreVertical , Timer } from 'lucide-react'
7
+ import { Coins , Edit , Trash2 , Check , Undo2 , MoreVertical , Timer , Archive , ArchiveRestore } from 'lucide-react'
8
8
import {
9
9
DropdownMenu ,
10
10
DropdownMenuContent ,
@@ -24,7 +24,7 @@ interface HabitItemProps {
24
24
}
25
25
26
26
export default function HabitItem ( { habit, onEdit, onDelete } : HabitItemProps ) {
27
- const { completeHabit, undoComplete } = useHabits ( )
27
+ const { completeHabit, undoComplete, archiveHabit , unarchiveHabit } = useHabits ( )
28
28
const [ settings ] = useAtom ( settingsAtom )
29
29
const [ _ , setPomo ] = useAtom ( pomodoroAtom )
30
30
const completionsToday = habit . completions ?. filter ( completion =>
@@ -59,21 +59,21 @@ export default function HabitItem({ habit, onEdit, onDelete }: HabitItemProps) {
59
59
return (
60
60
< Card
61
61
id = { `habit-${ habit . id } ` }
62
- className = { `h-full flex flex-col transition-all duration-500 ${ isHighlighted ? 'bg-yellow-100 dark:bg-yellow-900' : '' } ` }
62
+ className = { `h-full flex flex-col transition-all duration-500 ${ isHighlighted ? 'bg-yellow-100 dark:bg-yellow-900' : '' } ${ habit . archived ? 'opacity-75' : '' } ` }
63
63
>
64
64
< CardHeader className = "flex-none" >
65
- < CardTitle className = " line-clamp-1" > { habit . name } </ CardTitle >
65
+ < CardTitle className = { ` line-clamp-1 ${ habit . archived ? 'text-gray-400 dark:text-gray-500' : '' } ` } > { habit . name } </ CardTitle >
66
66
{ habit . description && (
67
- < CardDescription className = " whitespace-pre-line" >
67
+ < CardDescription className = { ` whitespace-pre-line ${ habit . archived ? 'text-gray-400 dark:text-gray-500' : '' } ` } >
68
68
{ habit . description }
69
69
</ CardDescription >
70
70
) }
71
71
</ CardHeader >
72
72
< CardContent className = "flex-1" >
73
- < p className = " text-sm text-gray-500" > When: { isRecurRule ? parseRRule ( habit . frequency || INITIAL_RECURRENCE_RULE ) . toText ( ) : d2s ( { dateTime : t2d ( { timestamp : habit . frequency , timezone : settings . system . timezone } ) , timezone : settings . system . timezone , format : DateTime . DATE_MED_WITH_WEEKDAY } ) } </ p >
73
+ < p className = { ` text-sm ${ habit . archived ? ' text-gray-400 dark:text-gray- 500' : 'text-gray-500' } ` } > When: { isRecurRule ? parseRRule ( habit . frequency || INITIAL_RECURRENCE_RULE ) . toText ( ) : d2s ( { dateTime : t2d ( { timestamp : habit . frequency , timezone : settings . system . timezone } ) , timezone : settings . system . timezone , format : DateTime . DATE_MED_WITH_WEEKDAY } ) } </ p >
74
74
< div className = "flex items-center mt-2" >
75
- < Coins className = " h-4 w-4 text-yellow -400 mr-1" />
76
- < span className = " text-sm font-medium" > { habit . coinReward } coins per completion</ span >
75
+ < Coins className = { ` h-4 w-4 mr-1 ${ habit . archived ? ' text-gray -400 dark:text-gray-500' : 'text-yellow-400' } ` } />
76
+ < span className = { ` text-sm font-medium ${ habit . archived ? 'text-gray-400 dark:text-gray-500' : '' } ` } > { habit . coinReward } coins per completion</ span >
77
77
</ div >
78
78
</ CardContent >
79
79
< CardFooter className = "flex justify-between gap-2" >
@@ -83,8 +83,8 @@ export default function HabitItem({ habit, onEdit, onDelete }: HabitItemProps) {
83
83
variant = { isCompletedToday ? "secondary" : "default" }
84
84
size = "sm"
85
85
onClick = { async ( ) => await completeHabit ( habit ) }
86
- disabled = { isCompletedToday && completionsToday >= target }
87
- className = " overflow-hidden w-24 sm:w-auto"
86
+ disabled = { habit . archived || ( isCompletedToday && completionsToday >= target ) }
87
+ className = { ` overflow-hidden w-24 sm:w-auto ${ habit . archived ? 'cursor-not-allowed' : '' } ` }
88
88
>
89
89
< Check className = "h-4 w-4 sm:mr-2" />
90
90
< span >
@@ -116,7 +116,7 @@ export default function HabitItem({ habit, onEdit, onDelete }: HabitItemProps) {
116
116
) }
117
117
</ Button >
118
118
</ div >
119
- { completionsToday > 0 && (
119
+ { completionsToday > 0 && ! habit . archived && (
120
120
< Button
121
121
variant = "outline"
122
122
size = "sm"
@@ -129,33 +129,53 @@ export default function HabitItem({ habit, onEdit, onDelete }: HabitItemProps) {
129
129
) }
130
130
</ div >
131
131
< div className = "flex gap-2" >
132
- < Button
133
- variant = "edit"
134
- size = "sm"
135
- onClick = { onEdit }
136
- className = "hidden sm:flex"
137
- >
138
- < Edit className = "h-4 w-4" />
139
- < span className = "ml-2" > Edit</ span >
140
- </ Button >
132
+ { ! habit . archived && (
133
+ < Button
134
+ variant = "edit"
135
+ size = "sm"
136
+ onClick = { onEdit }
137
+ className = "hidden sm:flex"
138
+ >
139
+ < Edit className = "h-4 w-4" />
140
+ < span className = "ml-2" > Edit</ span >
141
+ </ Button >
142
+ ) }
141
143
< DropdownMenu >
142
144
< DropdownMenuTrigger asChild >
143
145
< Button variant = "ghost" size = "sm" className = "h-8 w-8 p-0" >
144
146
< MoreVertical className = "h-4 w-4" />
145
147
</ Button >
146
148
</ DropdownMenuTrigger >
147
149
< DropdownMenuContent align = "end" >
148
- < DropdownMenuItem onClick = { ( ) => {
149
- setPomo ( ( prev ) => ( {
150
- ...prev ,
151
- show : true ,
152
- selectedHabitId : habit . id
153
- } ) )
154
- } } >
155
- < Timer className = "mr-2 h-4 w-4" />
156
- < span > Start Pomodoro</ span >
157
- </ DropdownMenuItem >
158
- < DropdownMenuItem onClick = { onEdit } className = "sm:hidden" >
150
+ { ! habit . archived && (
151
+ < DropdownMenuItem onClick = { ( ) => {
152
+ setPomo ( ( prev ) => ( {
153
+ ...prev ,
154
+ show : true ,
155
+ selectedHabitId : habit . id
156
+ } ) )
157
+ } } >
158
+ < Timer className = "mr-2 h-4 w-4" />
159
+ < span > Start Pomodoro</ span >
160
+ </ DropdownMenuItem >
161
+ ) }
162
+ { ! habit . archived && (
163
+ < DropdownMenuItem onClick = { ( ) => archiveHabit ( habit . id ) } >
164
+ < Archive className = "mr-2 h-4 w-4" />
165
+ < span > Archive</ span >
166
+ </ DropdownMenuItem >
167
+ ) }
168
+ { habit . archived && (
169
+ < DropdownMenuItem onClick = { ( ) => unarchiveHabit ( habit . id ) } >
170
+ < ArchiveRestore className = "mr-2 h-4 w-4" />
171
+ < span > Unarchive</ span >
172
+ </ DropdownMenuItem >
173
+ ) }
174
+ < DropdownMenuItem
175
+ onClick = { onEdit }
176
+ className = "sm:hidden"
177
+ disabled = { habit . archived }
178
+ >
159
179
< Edit className = "mr-2 h-4 w-4" />
160
180
Edit
161
181
</ DropdownMenuItem >
0 commit comments