@@ -11,13 +11,22 @@ import { getSocialPoints } from "../_services/action";
1111export default function SocialPointsCard ( ) {
1212 const posts = useFeedsStore ( ( state ) => state . posts , shallow ) ;
1313 const { user } = useUserStore ( ) ;
14- const [ points , setPoints ] = useState ( 0 ) ;
14+ const [ points , setPoints ] = useState < number | null > ( null ) ;
15+ const [ loading , setLoading ] = useState ( true ) ;
1516
1617 useEffect ( ( ) => {
1718 const fetchSocialPoints = async ( ) => {
18- if ( ! user ) return ;
19- const fetchedPoints = await getSocialPoints ( user . id ) ;
20- setPoints ( fetchedPoints || 0 ) ;
19+ if ( ! user ) {
20+ setLoading ( false ) ;
21+ return ;
22+ }
23+ setLoading ( true ) ;
24+ try {
25+ const fetchedPoints = await getSocialPoints ( user . id ) ;
26+ setPoints ( fetchedPoints || 0 ) ;
27+ } finally {
28+ setLoading ( false ) ;
29+ }
2130 } ;
2231
2332 if ( user ) fetchSocialPoints ( ) ;
@@ -36,13 +45,23 @@ export default function SocialPointsCard() {
3645 < p className = "text-xs text-gray-500" > Feed Engagement</ p >
3746 </ div >
3847 </ div >
48+
3949 < div className = "text-right" >
40- < p className = "bg-gradient-to-r from-blue-600 to-cyan-600 bg-clip-text text-2xl font-bold text-transparent" >
41- { points }
42- </ p >
43- < p className = "text-xs text-gray-500" > points</ p >
50+ { loading ? (
51+ < div className = "flex justify-end" >
52+ < div className = "h-5 w-5 animate-spin rounded-full border-2 border-cyan-500 border-t-transparent" />
53+ </ div >
54+ ) : (
55+ < >
56+ < p className = "bg-gradient-to-r from-blue-600 to-cyan-600 bg-clip-text text-2xl font-bold text-transparent" >
57+ { points ?? 0 }
58+ </ p >
59+ < p className = "text-xs text-gray-500" > points</ p >
60+ </ >
61+ ) }
4462 </ div >
4563 </ div >
64+
4665 < div className = "space-y-1" >
4766 < p className = "text-xs text-gray-500 dark:text-gray-400" >
4867 Earn more points by posting and getting likes and comments!
0 commit comments