Skip to content

Commit dc783cf

Browse files
authored
refactor: code restructuring and cleanup (#453)
* refactor: move around the navigation utils files * refactor: simplify auth context folder structure * feat: start tracking user as soon as available * refactor: better feature flag type separation * refactor: better types for useRunOnMount * chore: leverage doppler default config * fix: proper positioning of overlay components * chore: add placeholder env value * chore: handle PR review
1 parent 47253a4 commit dc783cf

30 files changed

Lines changed: 97 additions & 56 deletions

.coderabbit.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
2+
language: 'en-US'
3+
early_access: false
4+
reviews:
5+
profile: 'chill'
6+
request_changes_workflow: false
7+
high_level_summary: true
8+
poem: false
9+
review_status: true
10+
collapse_walkthrough: false
11+
changed_files_summary: false
12+
estimate_code_review_effort: false
13+
auto_review:
14+
enabled: true
15+
drafts: false
16+
tools:
17+
github-checks:
18+
enabled: true
19+
timeout_ms: 300000
20+
chat:
21+
auto_reply: true
22+
knowledge_base:
23+
linear:
24+
usage: 'enabled'
25+
team_keys:
26+
- 'INO'

.env.development

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
APP_NAME="Dev"
22
EAS_PROJECT_ID=""
33
EXPO_APPLE_TEAM_ID=""
4+
EXPO_UPDATE_URL=""
45

56
API_URL=""
67
ITUNES_ITEM_ID=""

.env.production

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
APP_NAME="RN Starter"
22
EAS_PROJECT_ID=""
33
EXPO_APPLE_TEAM_ID=""
4+
EXPO_UPDATE_URL=""
45

56
API_URL=""
67
ITUNES_ITEM_ID=""

.env.staging

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
APP_NAME="Staging"
22
EAS_PROJECT_ID=""
33
EXPO_APPLE_TEAM_ID=""
4+
EXPO_UPDATE_URL=""
45

56
API_URL=""
67
ITUNES_ITEM_ID=""

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,20 @@
2626
"node": ">=22.14"
2727
},
2828
"scripts": {
29-
"start:dev": "APP_ENV=development doppler run -p rn-starter -c dev -- expo start --dev-client",
29+
"start:dev": "APP_ENV=development doppler run -- expo start --dev-client",
3030
"start:staging": "APP_ENV=staging expo start --no-dev --minify",
3131
"start:production": "APP_ENV=production expo start --no-dev --minify",
3232
"//// BUILDS ////": "",
33-
"build:dev:ios": "doppler run -p rn-starter -c dev -- eas build --profile development --platform ios --local",
34-
"build:dev:android": "doppler run -p rn-starter -c dev -- eas build --profile development --platform android --local",
35-
"build:dev-device:ios": "doppler run -p rn-starter -c dev -- eas build --profile development-device --platform ios --local",
33+
"build:dev:ios": "doppler run -- eas build --profile development --platform ios --local",
34+
"build:dev:android": "doppler run -- eas build --profile development --platform android --local",
35+
"build:dev-device:ios": "doppler run -- eas build --profile development-device --platform ios --local",
3636
"build:staging:ios": "APP_ENV=staging eas build --profile staging --platform ios --local",
3737
"build:staging:android": "APP_ENV=staging eas build --profile staging --platform android --local",
3838
"build:production:ios": "APP_ENV=production eas build --profile production --platform ios --local",
3939
"build:production:android": "APP_ENV=production eas build --profile production --platform android --local",
4040
"//// TESTS ////": "",
4141
"test": "jest --cache --coverage=false",
42-
"test:e2e": "doppler run -p rn-starter -c dev -- maestro test ./e2e/authNavigation.yaml",
42+
"test:e2e": "doppler run -- maestro test ./e2e/authNavigation.yaml",
4343
"test:coverage": "jest",
4444
"//// QUALITY ////": "",
4545
"lint:ts": "yarn tsc",
@@ -52,7 +52,7 @@
5252
"generate:icons": "svgr --config-file src/shared/icons/svgs/config/svgrConfig.js --svgo-config src/shared/icons/svgs/config/svgoConfig.js --index-template src/shared/icons/svgs/config/index-template.js --template src/shared/icons/svgs/config/icon-template.js --out-dir src/shared/icons/components -- src/shared/icons/svgs && eslint './src/shared/icons/components/**/*.{ts,tsx}' --ext .ts,.tsx --fix --quiet && prettier --write './src/shared/icons/components/**/*.{ts,tsx}'",
5353
"//// STORYBOOK ////": "",
5454
"storybook:generate": "sb-rn-get-stories",
55-
"start:storybook": "STORYBOOK_ENABLED=true doppler run -p rn-starter -c dev -- expo start",
55+
"start:storybook": "STORYBOOK_ENABLED=true doppler run -- expo start",
5656
"//// VERSIONNING ////": "",
5757
"version:bump": "standard-version --skip.commit --skip.changelog --skip.tag",
5858
"version:tag": "standard-version",

src/app/(protected)/(tabs)/features/(blogPost)/[blogPostId].tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { Stack, useLocalSearchParams } from 'expo-router';
22
import { useTranslation } from 'react-i18next';
33

4+
import { BlogPostScreenParams } from '$domain/navigation';
45
import { BlogPost as BlogPostComponent } from '$features/blogPost';
5-
import { BlogPostScreenParams } from '$features/navigation';
66
import { Screen } from '$shared/components';
77

88
const BlogPostScreen = () => {

src/app/_layout.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ import { StyleSheet } from 'react-native-unistyles';
1717

1818
import { config } from '$domain/constants';
1919
import { AuthContextProvider } from '$domain/contexts';
20-
import {
21-
useAppScreenTracking,
22-
useAppStateTracking,
23-
} from '$features/navigation';
2420
import { useAppFocusManager } from '$infra/api';
2521
import { persistOptions, queryClient } from '$infra/api/queryClient';
2622
import { ErrorMonitoring } from '$infra/monitoring';
@@ -34,6 +30,8 @@ import {
3430
Splashscreen,
3531
} from '$shared/components';
3632
import {
33+
useAppScreenTracking,
34+
useAppStateTracking,
3735
useCheckNetworkStateOnMount,
3836
useRoutingInstrumentation,
3937
} from '$shared/hooks';

src/domain/contexts/authContext/components/AuthContextProvider.tsx renamed to src/domain/contexts/authContext/AuthContextProvider.tsx

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useQueryClient } from '@tanstack/react-query';
2-
import { useCallback, useMemo, useState } from 'react';
2+
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
33

44
import { User, UserLogin } from '$domain/entities';
55
import { Analytics } from '$infra/analytics';
@@ -15,13 +15,15 @@ import {
1515
} from '$infra/store';
1616
import { sleep } from '$shared/utils';
1717

18-
import AuthContext from '../AuthContext';
18+
import AuthContext from './AuthContext';
1919

2020
interface AuthContextProviderProps {
2121
children: React.ReactNode;
2222
}
2323

2424
export const AuthContextProvider = ({ children }: AuthContextProviderProps) => {
25+
const hasTrackedUserRef = useRef(false);
26+
2527
const [user, setUser] = useState<User | null>(null);
2628

2729
const setIsUserLoggedIn = useAppStore((state) => state.setIsUserLoggedIn);
@@ -55,6 +57,14 @@ export const AuthContextProvider = ({ children }: AuthContextProviderProps) => {
5557
Notifications.removeUserEmail(user.email);
5658
}, []);
5759

60+
useEffect(() => {
61+
if (user && !hasTrackedUserRef.current) {
62+
hasTrackedUserRef.current = true;
63+
64+
void startTrackingUser(user);
65+
}
66+
}, [user, startTrackingUser]);
67+
5868
const signIn = useCallback(
5969
async (data: UserLogin) => {
6070
try {
@@ -68,8 +78,6 @@ export const AuthContextProvider = ({ children }: AuthContextProviderProps) => {
6878

6979
setUser(userDataPayload);
7080
setIsUserLoggedIn(true);
71-
72-
await startTrackingUser(userDataPayload);
7381
} catch (error) {
7482
Logger.error({
7583
error,
@@ -78,7 +86,7 @@ export const AuthContextProvider = ({ children }: AuthContextProviderProps) => {
7886
});
7987
}
8088
},
81-
[setIsUserLoggedIn, startTrackingUser],
89+
[setIsUserLoggedIn],
8290
);
8391

8492
const signOut = useCallback(async () => {
@@ -94,6 +102,8 @@ export const AuthContextProvider = ({ children }: AuthContextProviderProps) => {
94102
queryClient.clear();
95103

96104
await clearAccessAndRefreshTokens();
105+
106+
hasTrackedUserRef.current = false;
97107
} catch (error) {
98108
Logger.error({
99109
error,

src/domain/contexts/authContext/components/index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/domain/contexts/authContext/hooks/index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)