@@ -92,8 +92,15 @@ export function ExpenseList({
92
92
< >
93
93
< SearchBar onChange = { ( e ) => setSearchText ( e . target . value ) } />
94
94
{ Object . values ( EXPENSE_GROUPS ) . map ( ( expenseGroup : string ) => {
95
- const groupExpenses = groupedExpensesByDate [ expenseGroup ]
95
+ let groupExpenses = groupedExpensesByDate [ expenseGroup ]
96
96
if ( ! groupExpenses ) return null
97
+
98
+ groupExpenses = groupExpenses . filter ( ( { title } ) =>
99
+ title . toLowerCase ( ) . includes ( searchText . toLowerCase ( ) ) ,
100
+ )
101
+
102
+ if ( groupExpenses . length === 0 ) return null
103
+
97
104
return (
98
105
< div key = { expenseGroup } >
99
106
< div
@@ -103,83 +110,70 @@ export function ExpenseList({
103
110
>
104
111
{ expenseGroup }
105
112
</ div >
106
- { groupExpenses
107
- . filter (
108
- ( exp ) =>
109
- exp . title . toLowerCase ( ) . match ( searchText . toLowerCase ( ) ) !==
110
- null ,
111
- )
112
- . map ( ( expense : any ) => (
113
- < div
114
- key = { expense . id }
115
- className = { cn (
116
- 'flex justify-between sm:mx-6 px-4 sm:rounded-lg sm:pr-2 sm:pl-4 py-4 text-sm cursor-pointer hover:bg-accent gap-1 items-stretch' ,
117
- expense . isReimbursement && 'italic' ,
118
- ) }
119
- onClick = { ( ) => {
120
- router . push (
121
- `/groups/${ groupId } /expenses/${ expense . id } /edit` ,
122
- )
123
- } }
124
- >
125
- < CategoryIcon
126
- category = { expense . category }
127
- className = "w-4 h-4 mr-2 mt-0.5 text-muted-foreground"
128
- />
129
- < div className = "flex-1" >
130
- < div
131
- className = { cn (
132
- 'mb-1' ,
133
- expense . isReimbursement && 'italic' ,
134
- ) }
135
- >
136
- { expense . title }
137
- </ div >
138
- < div className = "text-xs text-muted-foreground" >
139
- Paid by{ ' ' }
140
- < strong > { getParticipant ( expense . paidById ) ?. name } </ strong > { ' ' }
141
- for{ ' ' }
142
- { expense . paidFor . map ( ( paidFor : any , index : number ) => (
143
- < Fragment key = { index } >
144
- { index !== 0 && < > , </ > }
145
- < strong >
146
- {
147
- participants . find (
148
- ( p ) => p . id === paidFor . participantId ,
149
- ) ?. name
150
- }
151
- </ strong >
152
- </ Fragment >
153
- ) ) }
154
- </ div >
113
+ { groupExpenses . map ( ( expense : any ) => (
114
+ < div
115
+ key = { expense . id }
116
+ className = { cn (
117
+ 'flex justify-between sm:mx-6 px-4 sm:rounded-lg sm:pr-2 sm:pl-4 py-4 text-sm cursor-pointer hover:bg-accent gap-1 items-stretch' ,
118
+ expense . isReimbursement && 'italic' ,
119
+ ) }
120
+ onClick = { ( ) => {
121
+ router . push ( `/groups/${ groupId } /expenses/${ expense . id } /edit` )
122
+ } }
123
+ >
124
+ < CategoryIcon
125
+ category = { expense . category }
126
+ className = "w-4 h-4 mr-2 mt-0.5 text-muted-foreground"
127
+ />
128
+ < div className = "flex-1" >
129
+ < div
130
+ className = { cn ( 'mb-1' , expense . isReimbursement && 'italic' ) }
131
+ >
132
+ { expense . title }
155
133
</ div >
156
- < div className = "flex flex-col justify-between items-end" >
157
- < div
158
- className = { cn (
159
- 'tabular-nums whitespace-nowrap' ,
160
- expense . isReimbursement ? 'italic' : 'font-bold' ,
161
- ) }
162
- >
163
- { currency } { ( expense . amount / 100 ) . toFixed ( 2 ) }
164
- </ div >
165
- < div className = "text-xs text-muted-foreground" >
166
- { formatDate ( expense . expenseDate ) }
167
- </ div >
134
+ < div className = "text-xs text-muted-foreground" >
135
+ Paid by{ ' ' }
136
+ < strong > { getParticipant ( expense . paidById ) ?. name } </ strong > { ' ' }
137
+ for{ ' ' }
138
+ { expense . paidFor . map ( ( paidFor : any , index : number ) => (
139
+ < Fragment key = { index } >
140
+ { index !== 0 && < > , </ > }
141
+ < strong >
142
+ {
143
+ participants . find (
144
+ ( p ) => p . id === paidFor . participantId ,
145
+ ) ?. name
146
+ }
147
+ </ strong >
148
+ </ Fragment >
149
+ ) ) }
168
150
</ div >
169
- < Button
170
- size = "icon"
171
- variant = "link"
172
- className = "self-center hidden sm:flex"
173
- asChild
151
+ </ div >
152
+ < div className = "flex flex-col justify-between items-end" >
153
+ < div
154
+ className = { cn (
155
+ 'tabular-nums whitespace-nowrap' ,
156
+ expense . isReimbursement ? 'italic' : 'font-bold' ,
157
+ ) }
174
158
>
175
- < Link
176
- href = { `/groups/${ groupId } /expenses/${ expense . id } /edit` }
177
- >
178
- < ChevronRight className = "w-4 h-4" />
179
- </ Link >
180
- </ Button >
159
+ { currency } { ( expense . amount / 100 ) . toFixed ( 2 ) }
160
+ </ div >
161
+ < div className = "text-xs text-muted-foreground" >
162
+ { formatDate ( expense . expenseDate ) }
163
+ </ div >
181
164
</ div >
182
- ) ) }
165
+ < Button
166
+ size = "icon"
167
+ variant = "link"
168
+ className = "self-center hidden sm:flex"
169
+ asChild
170
+ >
171
+ < Link href = { `/groups/${ groupId } /expenses/${ expense . id } /edit` } >
172
+ < ChevronRight className = "w-4 h-4" />
173
+ </ Link >
174
+ </ Button >
175
+ </ div >
176
+ ) ) }
183
177
</ div >
184
178
)
185
179
} ) }
0 commit comments