From b54de79563dcf4ed61718a4cf63bd9970c881d2a Mon Sep 17 00:00:00 2001 From: hyochan Date: Thu, 19 Sep 2024 02:24:03 +0900 Subject: [PATCH] refactor: handle auth layers and migrate header --- app/(auth)/_layout.tsx | 2 +- app/(home)/(tabs)/_layout.tsx | 5 +++-- app/(home)/_layout.tsx | 11 ++++++++--- app/(home)/onboarding.tsx | 25 ++++++++++++++----------- app/(home)/post/[id]/index.tsx | 11 +++++++---- app/(home)/post/[id]/update.tsx | 1 - app/(home)/post/write.tsx | 2 +- app/(home)/settings/login-info.tsx | 10 ++++++++++ app/(home)/settings/profile-update.tsx | 1 - app/_layout.tsx | 9 ++++----- app/{(home) => }/picture.tsx | 12 ++++++------ src/apis/postQueries.ts | 8 +++++++- 12 files changed, 61 insertions(+), 36 deletions(-) rename app/{(home) => }/picture.tsx (84%) diff --git a/app/(auth)/_layout.tsx b/app/(auth)/_layout.tsx index 66323f6..84248d7 100644 --- a/app/(auth)/_layout.tsx +++ b/app/(auth)/_layout.tsx @@ -8,7 +8,7 @@ export default function AuthLayout() { const {isSignedIn} = useAuth(); if (isSignedIn) { - return ; + return ; } return ( diff --git a/app/(home)/(tabs)/_layout.tsx b/app/(home)/(tabs)/_layout.tsx index a793b09..966f4f5 100644 --- a/app/(home)/(tabs)/_layout.tsx +++ b/app/(home)/(tabs)/_layout.tsx @@ -21,9 +21,9 @@ function SettingsMenu(): JSX.Element { style={css` align-items: center; justify-content: center; - padding: 8px; + padding: 2px; border-radius: 99px; - margin-right: 4px; + margin-right: 8px; `} > @@ -58,6 +58,7 @@ export default function TabLayout(): JSX.Element { return ( ; + } return ( + + + + ); + } + if (user?.display_name) { - return ; + return ; } if (error) { return ; } - if (!data) { - return ( - - - - ); - } - return ( ( p.id === id); useEffect(() => { - if (id) { - incrementViewCount(id); + if (id && supabase) { + incrementViewCount({ + postId: id, + supabase, + }); setPosts((prevPosts) => prevPosts.map((p) => @@ -69,7 +72,7 @@ export default function PostDetails(): JSX.Element { ), ); } - }, [id, setPosts]); + }, [id, setPosts, supabase]); useEffect(() => { if (post) { @@ -341,9 +344,9 @@ export default function PostDetails(): JSX.Element { diff --git a/app/(home)/post/[id]/update.tsx b/app/(home)/post/[id]/update.tsx index 441f796..fe8378e 100644 --- a/app/(home)/post/[id]/update.tsx +++ b/app/(home)/post/[id]/update.tsx @@ -314,7 +314,6 @@ export default function PostUpdate(): JSX.Element { style={css` align-items: center; justify-content: center; - padding: 6px; margin-right: -4px; border-radius: 99px; `} diff --git a/app/(home)/post/write.tsx b/app/(home)/post/write.tsx index 8dbf374..c5d7abc 100644 --- a/app/(home)/post/write.tsx +++ b/app/(home)/post/write.tsx @@ -123,10 +123,10 @@ export default function PostWrite(): JSX.Element { => { diff --git a/app/(home)/settings/profile-update.tsx b/app/(home)/settings/profile-update.tsx index 414c631..d3877e9 100644 --- a/app/(home)/settings/profile-update.tsx +++ b/app/(home)/settings/profile-update.tsx @@ -567,7 +567,6 @@ export default function ProfileUpdate(): JSX.Element { style={css` align-items: center; justify-content: center; - padding: 6px; margin-right: -4px; border-radius: 99px; `} diff --git a/app/_layout.tsx b/app/_layout.tsx index ae70b78..9089059 100644 --- a/app/_layout.tsx +++ b/app/_layout.tsx @@ -26,7 +26,7 @@ import {authRecoilState, reportModalRecoilState} from '../src/recoil/atoms'; import {AsyncStorageKey} from '../src/utils/constants'; import CustomLoadingIndicator from '../src/components/uis/CustomLoadingIndicator'; import useAppState from '../src/hooks/useAppState'; -import {ClerkProvider, ClerkLoaded, useUser} from '@clerk/clerk-expo'; +import {ClerkProvider, ClerkLoaded, useUser, useAuth} from '@clerk/clerk-expo'; import ReportModal from '../src/components/modals/ReportModal'; import {getLocale, t} from '../src/STRINGS'; import {fetchUserProfile} from '../src/apis/profileQueries'; @@ -48,6 +48,7 @@ Notifications.setNotificationHandler({ function App(): JSX.Element | null { const {user} = useUser(); const {assetLoaded, snackbar} = useDooboo(); + const {signOut} = useAuth(); const [, setAuth] = useRecoilState(authRecoilState); const [checkEasUpdate, setCheckEasUpdate] = useState(false); const {isUpdateAvailable, isUpdatePending} = useUpdates(); @@ -130,8 +131,6 @@ function App(): JSX.Element | null { }) .single(); - console.log('data', data); - if (data) { existingUser = data; } @@ -148,7 +147,7 @@ function App(): JSX.Element | null { if (profile) { if (profile?.deleted_at) { - await supabase.auth.signOut(); + signOut(); snackbar.open({ text: t('common.deletedAccount'), @@ -201,7 +200,7 @@ function App(): JSX.Element | null { }; checkUser(); - }, [setAuth, snackbar, supabase, user]); + }, [setAuth, signOut, snackbar, supabase, user]); useEffect(() => { if (assetLoaded) { diff --git a/app/(home)/picture.tsx b/app/picture.tsx similarity index 84% rename from app/(home)/picture.tsx rename to app/picture.tsx index 7cf68d6..e3879b5 100644 --- a/app/(home)/picture.tsx +++ b/app/picture.tsx @@ -4,13 +4,13 @@ import {useSafeAreaInsets} from 'react-native-safe-area-context'; import {css} from '@emotion/native'; import {IconButton} from 'dooboo-ui'; import {Stack, useLocalSearchParams, useRouter} from 'expo-router'; -import CustomLoadingIndicator from '../../src/components/uis/CustomLoadingIndicator'; -import Wrapper from '../../src/components/uis/Wrapper'; -import ImageZoomView from '../../src/components/uis/ImageZoomView'; -import {isDesktopDevice} from '../../src/utils/common'; -import {t} from '../../src/STRINGS'; +import CustomLoadingIndicator from '../src/components/uis/CustomLoadingIndicator'; +import Wrapper from '../src/components/uis/Wrapper'; +import ImageZoomView from '../src/components/uis/ImageZoomView'; +import {isDesktopDevice} from '../src/utils/common'; +import {t} from '../src/STRINGS'; import ErrorBoundary from 'react-native-error-boundary'; -import FallbackComponent from '../../src/components/uis/FallbackComponent'; +import FallbackComponent from '../src/components/uis/FallbackComponent'; export default function Picture(): JSX.Element { const {imageUrl} = useLocalSearchParams(); diff --git a/src/apis/postQueries.ts b/src/apis/postQueries.ts index 9177e78..8564599 100644 --- a/src/apis/postQueries.ts +++ b/src/apis/postQueries.ts @@ -267,7 +267,13 @@ BEGIN UPDATE posts SET view_count = view_count + 1 WHERE id = post_id; END; */ -export const incrementViewCount = async (postId: string) => { +export const incrementViewCount = async ({ + postId, + supabase, +}: { + postId: string; + supabase: SupabaseClient; +}) => { //@ts-ignore const {data, error} = await supabase.rpc('increment_view_count', { post_id: postId,