1
- import React , { useEffect , useState } from 'react' ;
1
+ import React , { useCallback , useEffect , useState } from 'react' ;
2
2
import styled from '@emotion/native' ;
3
3
import { Stack , useLocalSearchParams } from 'expo-router' ;
4
4
import { Button , Icon , Typography , useDooboo } from 'dooboo-ui' ;
5
5
import { css } from '@emotion/native' ;
6
- import { Pressable } from 'react-native' ;
6
+ import { Pressable , RefreshControl } from 'react-native' ;
7
7
import ErrorBoundary from 'react-native-error-boundary' ;
8
- import FallbackComponent from '../src/components/uis/FallbackComponent' ;
9
- import CustomScrollView from '../src/components/uis/CustomScrollView' ;
10
- import { IC_ICON } from '../src/icons' ;
11
- import { openURL , removeLeadingAt } from '../src/utils/common' ;
12
- import DoobooStats from '../src/components/fragments/DoobooStats' ;
13
- import { t } from '../src/STRINGS' ;
14
- import { fetchUserWithDisplayName } from '../src/apis/profileQueries' ;
15
- import CustomLoadingIndicator from '../src/components/uis/CustomLoadingIndicator' ;
8
+ import FallbackComponent from '../../../ src/components/uis/FallbackComponent' ;
9
+ import CustomScrollView from '../../../ src/components/uis/CustomScrollView' ;
10
+ import { IC_ICON } from '../../../ src/icons' ;
11
+ import { openURL , removeLeadingAt } from '../../../ src/utils/common' ;
12
+ import DoobooStats from '../../../ src/components/fragments/DoobooStats' ;
13
+ import { t } from '../../../ src/STRINGS' ;
14
+ import { fetchUserWithDisplayName } from '../../../ src/apis/profileQueries' ;
15
+ import CustomLoadingIndicator from '../../../ src/components/uis/CustomLoadingIndicator' ;
16
16
import { useRecoilValue } from 'recoil' ;
17
- import { authRecoilState } from '../src/recoil/atoms' ;
17
+ import { authRecoilState } from '../../../ src/recoil/atoms' ;
18
18
import {
19
19
fetchFollowCounts ,
20
20
fetchFollowUser ,
21
21
fetchIsAFollowing ,
22
- } from '../src/apis/followQueries' ;
23
- import useSupabase from '../src/hooks/useSupabase' ;
22
+ } from '../../../ src/apis/followQueries' ;
23
+ import useSupabase from '../../../ src/hooks/useSupabase' ;
24
24
25
25
const Container = styled . SafeAreaView `
26
26
flex : 1 ;
@@ -36,7 +36,7 @@ const ProfileHeader = styled.View`
36
36
` ;
37
37
38
38
const Content = styled . View `
39
- padding : 24 px ;
39
+ padding : 16 px ;
40
40
` ;
41
41
42
42
const UserAvatar = styled . Image `
@@ -148,62 +148,83 @@ export default function DisplayName(): JSX.Element {
148
148
}
149
149
} ;
150
150
151
- useEffect ( ( ) => {
152
- async function fetchData ( ) {
153
- if ( ! supabase ) return ;
154
-
155
- try {
156
- const { profile, userTags} = await fetchUserWithDisplayName ( {
157
- displayName,
158
- supabase,
159
- } ) ;
151
+ const fetchData = useCallback ( async ( ) => {
152
+ if ( ! supabase ) return ;
160
153
161
- setUser ( profile ) ;
162
- setTags ( userTags ) ;
163
-
164
- // Check if the current user is following this profile
165
- if ( authId ) {
166
- if ( profile . id !== authId ) {
167
- const isUserFollowing = await fetchIsAFollowing ( {
168
- authId,
169
- followingId : profile . id ,
170
- supabase,
171
- } ) ;
154
+ try {
155
+ const { profile, userTags} = await fetchUserWithDisplayName ( {
156
+ displayName,
157
+ supabase,
158
+ } ) ;
172
159
173
- setIsFollowing ( isUserFollowing ) ;
174
- }
160
+ setUser ( profile ) ;
161
+ setTags ( userTags ) ;
175
162
176
- const followingsData = await fetchFollowCounts ( {
177
- userId : profile . id ,
163
+ // Check if the current user is following this profile
164
+ if ( authId ) {
165
+ if ( profile . id !== authId ) {
166
+ const isUserFollowing = await fetchIsAFollowing ( {
167
+ authId,
168
+ followingId : profile . id ,
178
169
supabase,
179
170
} ) ;
180
171
181
- setFollowingCount ( followingsData . followingCount ) ;
172
+ setIsFollowing ( isUserFollowing ) ;
182
173
}
183
- } catch ( err : any ) {
184
- throw new Error ( err . message ) ;
185
- } finally {
186
- setLoading ( false ) ;
174
+
175
+ const followingsData = await fetchFollowCounts ( {
176
+ userId : profile . id ,
177
+ supabase,
178
+ } ) ;
179
+
180
+ setFollowingCount ( followingsData . followerCount ) ;
187
181
}
182
+ } catch ( err : any ) {
183
+ throw new Error ( err . message ) ;
184
+ } finally {
185
+ setLoading ( false ) ;
188
186
}
187
+ } , [ supabase , displayName , authId ] ) ;
189
188
189
+ const onRefresh = async ( ) => {
190
+ fetchData ( ) ;
191
+ } ;
192
+
193
+ useEffect ( ( ) => {
190
194
fetchData ( ) ;
191
- } , [ authId , displayName , supabase ] ) ;
195
+ } , [ fetchData ] ) ;
192
196
193
197
if ( loading ) {
194
198
return (
195
199
< >
196
- < Stack . Screen options = { { title : displayName || t ( 'common.profile' ) } } />
200
+ < Stack . Screen
201
+ options = { {
202
+ headerShown : true ,
203
+ title : displayName || t ( 'common.profile' ) ,
204
+ } }
205
+ />
197
206
< CustomLoadingIndicator />
198
207
</ >
199
208
) ;
200
209
}
201
210
202
211
return (
203
212
< ErrorBoundary FallbackComponent = { FallbackComponent } >
204
- < Stack . Screen options = { { title : displayName || t ( 'common.profile' ) } } />
205
213
< Container >
206
- < CustomScrollView bounces = { false } >
214
+ < Stack . Screen
215
+ options = { {
216
+ headerShown : true ,
217
+ title : displayName || t ( 'common.profile' ) ,
218
+ } }
219
+ />
220
+ < CustomScrollView
221
+ bounces = { false }
222
+ scrollViewProps = { {
223
+ refreshControl : (
224
+ < RefreshControl refreshing = { loading } onRefresh = { onRefresh } />
225
+ ) ,
226
+ } }
227
+ >
207
228
< ProfileHeader >
208
229
< UserAvatar
209
230
style = { css `
0 commit comments