-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathApp.tsx
More file actions
129 lines (119 loc) · 4.44 KB
/
App.tsx
File metadata and controls
129 lines (119 loc) · 4.44 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import { useEffect, useState } from "react";
import {
BrowserRouter as Router,
Routes,
Route,
useLocation
} from "react-router-dom";
import { initGA, trackPageView } from "@/libs/analytics";
import Home from "@/pages/Home";
import SelectInfo from "@/pages/SelectInfo";
import Chat from "@/pages/Chat";
import ChatRecommend from "@/pages/ChatRecommend";
import ChatTips from "@/pages/ChatTips";
import ChatTemperature from "@/pages/ChatTemperature";
import Content from "@/pages/Content";
import Login from "@/pages/Login";
import MyInfo from "@/pages/MyInfo";
import KaKaoLogin from "@/pages/KaKaoLogin";
import MbtiTestIntro from "@/pages/MbtiTestIntro";
import MbtiTestQuestions from "@/pages/MbtiTestQuestions";
import MbtiTestResult from "@/pages/MbtiTestResult";
import Error from "@/pages/Error";
import CenteredLayout from "@/components/CenteredLayout";
import ToastMessage from "@/components/ToastMessage";
import useAuthStore from "@/store/useAuthStore";
const PageTracker = () => {
const location = useLocation();
const { pathname, state } = location;
const trackedPaths = [
{ path: "/", page: "홈" },
{ path: "/login", page: "로그인/회원가입" },
{ path: "/contents", page: "일반콘텐츠" },
{ path: "/my-info", page: "내 정보" },
{ path: "/chat", page: "채팅방" },
{ path: "/select-info", page: "빠른 대화 설정" },
{ path: "/mbti-test", page: "바이럴 콘텐츠 소개" },
{ path: "/mbti-result", page: "바이럴 콘텐츠 결과" },
{ path: "/chat-recommend", page: "대화주제추천" },
{ path: "/chat-tips", page: "대화 꿀팁" },
{ path: "/chat-temperature", page: "대화 온도" }
];
useEffect(() => {
const trackedContentPaths = ["/contents/1", "/contents/2"];
trackedPaths.forEach(({ path, page }) => {
// 콘텐츠 상세 페이지 (일반 콘텐츠만 추적)
if (trackedContentPaths.includes(pathname)) {
if (path === "/contents") {
trackPageView(path, page);
}
}
// select-info 페이지에서 state로 분기
else if (pathname === "/select-info" && path === pathname) {
if (state === "fastFriend" && page === "빠른 대화 설정") {
trackPageView(path, page);
} else if (state === "virtualFriend" && page === "친구 저장") {
trackPageView(path, page);
}
}
// 나머지 일반 path
else if (pathname === path && path !== "/select-info") {
trackPageView(path, page);
}
});
}, [location.pathname, location.state]);
return null;
};
const App = () => {
const { logout } = useAuthStore();
const [toastMessage, setToastMessage] = useState("");
const storageAuth = localStorage.getItem("auth-storage");
const parsedAuth = storageAuth ? JSON.parse(storageAuth).state : null;
const checkSession = () => {
const expirationTime = new Date(
new Date(parsedAuth.loginTime).getTime() + 24 * 60 * 60 * 1000
);
const now = new Date();
if (now > expirationTime) {
setToastMessage("로그인 세션이 만료되었습니다.");
logout();
}
};
useEffect(() => {
initGA();
if (parsedAuth && parsedAuth.accessToken) checkSession();
}, []);
return (
<Router>
<PageTracker />
<CenteredLayout>
{toastMessage && (
<ToastMessage
message={toastMessage}
onClose={() => setToastMessage("")}
/>
)}
<Routes>
<Route path="/" element={<Home />} />
<Route path="/select-info" element={<SelectInfo />} />
<Route path="/chat" element={<Chat />} />
<Route path="/chat-recommend/:mbti" element={<ChatRecommend />} />
<Route path="/chat-tips/:mbti" element={<ChatTips />} />
<Route
path="/chat-temperature/:conversationId"
element={<ChatTemperature />}
/>
<Route path="/contents/:id" element={<Content />} />
<Route path="/login" element={<Login />} />
<Route path="/my-info" element={<MyInfo />} />
<Route path="/kakao-login" element={<KaKaoLogin />} />
<Route path="/mbti-test" element={<MbtiTestIntro />} />
<Route path="/mbti-test-progress" element={<MbtiTestQuestions />} />
<Route path="/mbti-test-result" element={<MbtiTestResult />} />
<Route path="*" element={<Error statusCode="500" />} />
</Routes>
</CenteredLayout>
</Router>
);
};
export default App;