-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.tsx
More file actions
108 lines (95 loc) · 3.48 KB
/
App.tsx
File metadata and controls
108 lines (95 loc) · 3.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import "./global.css";
import { useEffect, useRef } from "react";
import { StatusBar } from "expo-status-bar";
import {
NavigationContainer,
useNavigationContainerRef,
} from "@react-navigation/native";
import { BottomSheetModalProvider } from "@gorhom/bottom-sheet";
import { GestureHandlerRootView } from "react-native-gesture-handler";
import { SafeAreaProvider, SafeAreaView } from "react-native-safe-area-context";
import { RootNavigator } from "@/navigation";
import QueryProvider from "@/providers/QueryProvider";
import StatusView from "@/components/common/StatusView";
import {
SUPABASE_CONFIG_ERROR_MESSAGE,
isSupabaseConfigured,
} from "@/apis/supabase";
import { useNotificationSettings } from "@/hooks/option/useNotificationApi";
import { debugLog } from "@/utils/debug";
import useTokenStore from "@/stores/useTokenStore";
import { registerDeviceFcmToken, unregisterDeviceFcmToken } from "@/utils/fcm";
function NotificationTokenSync() {
const { accessToken } = useTokenStore();
const { data: notificationSettings } = useNotificationSettings();
const lastSyncedStateRef = useRef<string | null>(null);
useEffect(() => {
if (!accessToken || !notificationSettings) {
lastSyncedStateRef.current = null;
return;
}
const syncKey = `${accessToken}:${notificationSettings.notificationEnabled}`;
if (lastSyncedStateRef.current === syncKey) {
return;
}
lastSyncedStateRef.current = syncKey;
if (notificationSettings.notificationEnabled) {
void registerDeviceFcmToken();
return;
}
void unregisterDeviceFcmToken();
}, [accessToken, notificationSettings]);
return null;
}
export default function App() {
const navigationRef = useNavigationContainerRef();
const currentRouteNameRef = useRef<string | undefined>(undefined);
useEffect(() => {
debugLog("App", "App mounted", { isSupabaseConfigured });
}, []);
if (!isSupabaseConfigured) {
return (
<SafeAreaProvider>
<SafeAreaView style={{ flex: 1, backgroundColor: "#FFFFFF" }}>
<StatusView
title="앱 시작 설정이 누락되었습니다."
description={SUPABASE_CONFIG_ERROR_MESSAGE ?? "Supabase 설정을 확인해주세요."}
/>
</SafeAreaView>
</SafeAreaProvider>
);
}
return (
<GestureHandlerRootView style={{ flex: 1 }}>
<SafeAreaProvider>
<QueryProvider>
<NotificationTokenSync />
<BottomSheetModalProvider>
<NavigationContainer
ref={navigationRef}
onReady={() => {
const routeName = navigationRef.getCurrentRoute()?.name;
currentRouteNameRef.current = routeName;
debugLog("Navigation", "ready", { routeName });
}}
onStateChange={() => {
const previousRouteName = currentRouteNameRef.current;
const nextRouteName = navigationRef.getCurrentRoute()?.name;
if (previousRouteName !== nextRouteName) {
debugLog("Navigation", "route changed", {
from: previousRouteName,
to: nextRouteName,
});
}
currentRouteNameRef.current = nextRouteName;
}}
>
<RootNavigator />
<StatusBar style="auto" />
</NavigationContainer>
</BottomSheetModalProvider>
</QueryProvider>
</SafeAreaProvider>
</GestureHandlerRootView>
);
}