@@ -15,15 +15,16 @@ import {
1515import { Button } from '@/components/ui/button' ;
1616import { SquarePlus } from 'lucide-react' ;
1717
18- export function List ( { data, listPath, listName } ) {
18+ export function List ( { data, listPath, listName, isLoading , setIsLoading } ) {
1919 const [ search , setSearch ] = useState ( '' ) ;
2020 const [ allData , setAllData ] = useState ( [ ] ) ;
2121 const [ displayData , setDisplayData ] = useState ( [ ] ) ;
2222 const [ isOpen , setIsOpen ] = useState ( false ) ;
2323 const [ openItemId , setOpenItemId ] = useState ( null ) ;
24- const [ isLoading , setIsLoading ] = useState ( true ) ;
24+ const [ noData , setNoData ] = useState ( false ) ;
2525
2626 useEffect ( ( ) => {
27+ setIsLoading ( true ) ;
2728 const arrayWithIndicator = data . map ( ( item ) => ( {
2829 ...item ,
2930 indicator : getIndicator ( item ) ,
@@ -39,6 +40,13 @@ export function List({ data, listPath, listName }) {
3940 }
4041 } , [ displayData ] ) ;
4142
43+ setTimeout ( ( ) => {
44+ if ( data . length === 0 ) {
45+ setIsLoading ( false ) ;
46+ setNoData ( true ) ;
47+ }
48+ } , 2000 ) ;
49+
4250 const handleAddModal = ( ) => {
4351 if ( search . length > 0 ) {
4452 setDisplayData ( allData ) ;
@@ -75,9 +83,14 @@ export function List({ data, listPath, listName }) {
7583 < span className = "relative inline-block" > { listName } </ span >
7684 </ h1 >
7785 < img
78- src = "/img/underline.png"
86+ src = "/img/ruby-underline.png"
87+ alt = "Description"
88+ className = "absolute bottom-[-12px] -right-3 w-14 h-3 dark:hidden"
89+ />
90+ < img
91+ src = "/img/light-pink-underline.png"
7992 alt = "Description"
80- className = "absolute bottom-[-12px] -right-3 w-14 h-3"
93+ className = "absolute bottom-[-12px] -right-3 w-14 h-3 hidden dark:block "
8194 />
8295 </ div >
8396 </ div >
@@ -89,9 +102,9 @@ export function List({ data, listPath, listName }) {
89102 search = { search }
90103 />
91104 < Dialog open = { isOpen } onOpenChange = { handleAddModal } >
92- < DialogTrigger asChild >
105+ < DialogTrigger asChild className = "items-start mt-[19px]" >
93106 < Button className = "bg-transparen hover:bg-transparen p-0" >
94- < SquarePlus className = "h-7 w-7 text-pink dark:text-green transition-opacity hover:opacity-75" />
107+ < SquarePlus className = "h-10 w-10 text-primary-green dark:text-primary-pink transition-opacity hover:opacity-75" />
95108 </ Button >
96109 </ DialogTrigger >
97110 < DialogContent >
@@ -110,27 +123,7 @@ export function List({ data, listPath, listName }) {
110123 </ DialogContent >
111124 </ Dialog >
112125 </ div >
113- < ul className = "flex flex-col justify-center space-y-4 w-full max-w-md" >
114- { displayData . map ( ( item ) => (
115- < ListItem
116- key = { item . id }
117- name = { item . name }
118- listPath = { listPath }
119- id = { item . id }
120- quantity = { item . quantity }
121- isChecked = { item . checked }
122- dateLastPurchased = { item . dateLastPurchased }
123- totalPurchases = { item . totalPurchases }
124- dayInterval = { item . dayInterval }
125- dateCreated = { item . dateCreated }
126- dateNextPurchased = { item . dateNextPurchased }
127- indicator = { item . indicator }
128- isOpen = { openItemId === item . id }
129- handleOpenModal = { handleEditModal }
130- />
131- ) ) }
132- </ ul >
133- { data . length === 0 && isLoading && (
126+ { isLoading ? (
134127 < div role = "status" >
135128 < svg
136129 aria-hidden = "true"
@@ -150,26 +143,47 @@ export function List({ data, listPath, listName }) {
150143 </ svg >
151144 < span className = "sr-only" > Loading...</ span >
152145 </ div >
146+ ) : (
147+ < ul className = "flex flex-col justify-center space-y-4 w-full max-w-md" >
148+ { displayData . map ( ( item ) => (
149+ < ListItem
150+ key = { item . id }
151+ name = { item . name }
152+ listPath = { listPath }
153+ id = { item . id }
154+ quantity = { item . quantity }
155+ isChecked = { item . checked }
156+ dateLastPurchased = { item . dateLastPurchased }
157+ totalPurchases = { item . totalPurchases }
158+ dayInterval = { item . dayInterval }
159+ dateCreated = { item . dateCreated }
160+ dateNextPurchased = { item . dateNextPurchased }
161+ indicator = { item . indicator }
162+ isOpen = { openItemId === item . id }
163+ handleOpenModal = { handleEditModal }
164+ />
165+ ) ) }
166+ </ ul >
153167 ) }
154- { displayData . length === 0 && search . length > 0 && (
155- < div className = "flex flex-col items-center" >
156- < p > No items found. Try searching for a different item!</ p >
157- </ div >
158- ) }
159- { data . length === 0 && ! isLoading && (
168+ { ! isLoading && noData && displayData . length === 0 && (
160169 < div className = "flex flex-col justify-center items-center gap-4 w-full mx-auto" >
161170 < p className = "text-grey text-center" >
162171 Your list is empty. Start adding some items now!
163172 </ p >
164173 < Button
165- className = "bg-pink text-white rounded-xl w-full hover:bg-pink hover:bg-opacity-75 text-sm font-semibold max-w-[150px]"
174+ className = "bg-primary- pink text-white rounded-xl dark:bg-primary-green dark:text-black w-full hover:bg-primary -pink hover:bg-opacity-75 text-sm font-semibold max-w-[150px]"
166175 id = "addFirstItem"
167176 onClick = { ( ) => setIsOpen ( ( prev ) => ! prev ) }
168177 >
169178 Add Item
170179 </ Button >
171180 </ div >
172181 ) }
182+ { displayData . length === 0 && search . length > 0 && (
183+ < div className = "flex flex-col items-center" >
184+ < p > No items found. Try searching for a different item!</ p >
185+ </ div >
186+ ) }
173187 </ div >
174188 ) }
175189 </ >
0 commit comments