11import ResultCard from "./ResultCard" ;
2-
32import styled from "styled-components" ;
43import { useState , useEffect , useRef } from "react" ;
5-
64import SearchInput from "../../components/SearchInput" ;
75import useRequest from "../../../../services/Hooks/useRequest" ;
86import { getFieldTranslationByNames } from "../../../../services/Utility" ;
7+ import { Skeleton } from "../../../../components/Skeleton" ;
98
109const Wrapper = styled . div `
1110 display: flex;
@@ -22,27 +21,42 @@ const Container = styled.div`
2221 padding: 15px;
2322 overflow-y: auto;
2423` ;
24+
2525const P = styled . p `
2626 color: ${ ( props ) => props . theme . colors . newColors . shades [ 30 ] } ;
2727 font-weight: 500;
2828 text-align: center;
2929 margin-top: 20px;
3030 font-size: 18px;
3131` ;
32+
33+ // اسکلتون برای کارت
34+ const SkeletonCard = styled . div `
35+ background-color: ${ ( props ) =>
36+ props . theme . colors . newColors . otherColors . bgContainer } ;
37+ border-radius: 5px;
38+ padding: 20px;
39+ display: grid;
40+ grid-template-columns: 10fr 1fr;
41+ gap: 20px;
42+ ` ;
43+
3244const CitizenTab = ( ) => {
3345 const debounceRef = useRef ( null ) ;
3446
3547 const [ searched , setSearched ] = useState ( "" ) ;
3648 const [ data , setData ] = useState ( [ ] ) ;
3749 const [ isLoading , setIsLoading ] = useState ( false ) ;
3850 const { Request, HTTP_METHOD } = useRequest ( ) ;
51+
3952 const searchHandler = ( ) => {
4053 if ( ! searched . trim ( ) ) return ;
4154 setIsLoading ( true ) ;
4255 searchAPI ( Request , HTTP_METHOD , searched )
4356 . then ( ( response ) => setData ( response . data . data ) )
4457 . finally ( ( ) => setIsLoading ( false ) ) ;
4558 } ;
59+
4660 useEffect ( ( ) => {
4761 if ( ! searched . trim ( ) ) {
4862 setData ( [ ] ) ;
@@ -66,26 +80,62 @@ const CitizenTab = () => {
6680
6781 return ( ) => clearTimeout ( debounceRef . current ) ;
6882 } , [ searched ] ) ;
83+
6984 const handleInputChange = ( e ) => {
7085 setSearched ( e . target . value ) ;
7186 } ;
7287
7388 return (
7489 < Container >
7590 < SearchInput
76- onchange = { handleInputChange } // Call search on every input change
91+ onchange = { handleInputChange }
7792 value = { searched }
7893 placeholder = { getFieldTranslationByNames ( "36" ) }
79- onSearch = { searchHandler } // You can still keep this for the icon click event
94+ onSearch = { searchHandler }
8095 />
96+
8197 { isLoading ? (
82- < P > درحال دریافت اطلاعات</ P >
98+ // اسکلتون برای 3 کارت
99+ < Wrapper >
100+ { Array . from ( { length : 3 } ) . map ( ( _ , index ) => (
101+ < SkeletonCard key = { index } >
102+ < div style = { { display : "flex" , flexDirection : "column" , gap : "15px" } } >
103+ < div style = { { display : "flex" , gap : "15px" , alignItems : "center" } } >
104+ < Skeleton width = "50px" height = "50px" radius = "50%" />
105+ < div >
106+ < Skeleton width = "120px" height = "18px" radius = "4px" style = { { marginBottom : "8px" } } />
107+ < Skeleton width = "80px" height = "14px" radius = "4px" />
108+ </ div >
109+ </ div >
110+ < div style = { { display : "flex" , gap : "15px" , alignItems : "center" , justifyContent :"space-between" , marginTop :"16px" } } >
111+ < div style = { { display : "flex" , flexDirection : "column" , gap : "10px" , alignItems :"center" } } >
112+ < Skeleton width = "50px" height = "16px" radius = "4px" />
113+ < Skeleton width = "60px" height = "16px" radius = "4px" />
114+ </ div >
115+ < div style = { { display : "flex" , flexDirection : "column" , gap : "10px" , alignItems :"center" } } >
116+ < Skeleton width = "50px" height = "16px" radius = "4px" />
117+ < Skeleton width = "60px" height = "16px" radius = "4px" />
118+ </ div >
119+ < div style = { { display : "flex" , flexDirection : "column" , gap : "10px" , alignItems :"center" } } >
120+ < Skeleton width = "50px" height = "16px" radius = "4px" />
121+ < Skeleton width = "60px" height = "16px" radius = "4px" />
122+ </ div >
123+ </ div >
124+ </ div >
125+ < div style = { { display : "flex" , flexDirection : "column" , gap : "18px" } } >
126+ < Skeleton width = "36px" height = "36px" radius = "1111px" />
127+ < Skeleton width = "36px" height = "36px" radius = "1111px" />
128+ < Skeleton width = "36px" height = "36px" radius = "1111px" />
129+ </ div >
130+ </ SkeletonCard >
131+ ) ) }
132+ </ Wrapper >
83133 ) : data . length === 0 ? (
84134 < P > { getFieldTranslationByNames ( "37" ) } </ P >
85135 ) : (
86136 < Wrapper >
87137 { data . map ( ( item , i ) => (
88- < ResultCard key = { i } user = { item } />
138+ < ResultCard key = { i } user = { item } isLoading = { false } />
89139 ) ) }
90140 </ Wrapper >
91141 ) }
@@ -99,4 +149,4 @@ function searchAPI(request, method, query) {
99149 return request ( url , method . POST , body ) ;
100150}
101151
102- export default CitizenTab ;
152+ export default CitizenTab ;
0 commit comments