= (props) => {
- const { townName2: myTown } = useUserData();
+ const { town } = useUser();
return (
= (props) => {
}}
>
- {props.districtLeaderboardData.slice(0, 10).map((district) => {
- return myTown === district.name2 ? (
+ {props.districtLeaderboardData.slice(0, 10).map((district, i) => {
+ return town.name2 === district.name2 ? (
= (props) => {
/>
) : (
= (props) => {
/>
);
})}
- {props.districtLeaderboardData.slice(10).map((district) => {
- return myTown === district.name2 ? (
+ {props.districtLeaderboardData.slice(10).map((district, i) => {
+ return town.name2 === district.name2 ? (
= (props) => {
/>
) : (
= (props) => {
}}
>
- {props.userLeaderboardData.slice(0, 10).map((user) => {
+ {props.userLeaderboardData.slice(0, 10).map((user, i) => {
return (
= (props) => {
이웃들에게 한 마디를 남겨보세요!
- {props.userLeaderboardData.slice(10).map((user) => {
+ {props.userLeaderboardData.slice(10).map((user, i) => {
return (
{
- const {
- nickname,
- townName1: cityName,
- townName2: districtName,
- } = useUserData();
+ const { user, town } = useUser();
const { score, rank, highestScore, highestRank } = useMyGame2048Data();
return (
@@ -19,10 +15,13 @@ export const MyInfo: React.FC = () => {
{rank}
- {nickname}
+ {user.nickname}
- {cityName.replace(/(특별시|광역시|특별자치시|특별자치도)$/, '')}
- {districtName}
+ {town.name1!.replace(
+ /(특별시|광역시|특별자치시|특별자치도)$/,
+ ''
+ )}
+ {town.name2}
diff --git a/src/pages/Home.tsx b/src/pages/Home.tsx
index 6aec5c4ec..df28b4e15 100644
--- a/src/pages/Home.tsx
+++ b/src/pages/Home.tsx
@@ -2,7 +2,7 @@ import React, { useCallback, useEffect, useState } from 'react';
import styled from '@emotion/styled';
import { useCurrentScreen, useNavigator } from '@karrotframe/navigator';
import { useMinigameApi } from 'services/api/minigameApi';
-import { useAccessToken, useMini, useUserData, useUser } from 'hooks';
+import { useAccessToken, useMini, useUser } from 'hooks';
import { Nav } from 'components/Navigation/Nav';
import { CloseIcon } from 'assets/Icon';
import { rem } from 'polished';
@@ -18,16 +18,11 @@ import WhatsNextCardImgUrl from 'assets/svg/whats_next_card_img.svg';
import ComingSoonCardImgUrl from 'assets/svg/coming_soon_card_img.svg';
import ArrowGame2048Url from 'assets/svg/arrow_game_2048.svg';
import ArrowKarrotClickerUrl from 'assets/svg/arrow_karrot_clicker.svg';
-import { ReactComponent as Bookmark } from 'assets/svg/bookmark_icon.svg';
-import { ReactComponent as BookmarkDone } from 'assets/svg/bookmark_done_icon.svg';
import { ReactComponent as Share } from 'assets/svg/share_icon.svg';
import { ReactComponent as Circle2048Puzzle } from 'assets/svg/platform/comment_icon_2048_puzzle.svg';
import { ReactComponent as CircleKarrotClicker } from 'assets/svg/platform/comment_icon_karrot_clicker.svg';
import { NotificationRequestDtoTypeEnum } from 'services/openapi_generator';
-import {
- SubscribeToastContainer,
- subscribeToastEmitter,
-} from 'components/Toast';
+import { SubscribeToastContainer } from 'components/Toast';
import { Swiper, SwiperSlide } from 'swiper/react/swiper-react.js';
import 'swiper/swiper.scss';
import { Autoplay } from 'swiper';
@@ -37,28 +32,15 @@ import missionEnvelopeClosed from 'assets/svg/mission/mission_envelope_closed.sv
import missionEnvelopeClosed1 from 'assets/svg/mission/mission_envelope_closed_1.svg';
import ReactModal from 'react-modal';
import { Popup as MissionPopup } from './Mission';
-
+import { RefererEnum } from 'redux/user';
export const Home: React.FC = () => {
const analytics = useAnalytics();
const minigameApi = useMinigameApi();
const { isTop } = useCurrentScreen();
const { push } = useNavigator();
- const {
- isInWebEnvironment,
- ejectApp,
- handleThirdPartyAgreement,
- handleSubscribe,
- shareApp,
- } = useMini();
+ const { isInWebEnvironment, ejectApp, handleThirdPartyAgreement, shareApp } =
+ useMini();
const { accessToken } = useAccessToken();
- const {
- userId,
- nickname,
- setUserInfo,
- townName3,
- isInstalled,
- setIsInstalled,
- } = useUserData();
const {
updateMyScore: updateMyGame2048Score,
updateMyComment: updateMyGame2048Comment,
@@ -69,18 +51,11 @@ export const Home: React.FC = () => {
updateMyComment: updateMyKarrotClickerComment,
setGameTypeToKarrotClicker,
} = useMyKarrotClickerData();
- const {
- uuid,
- regionId,
- referer,
- isMissionCheckedOut,
- hasMissionPopupSeen,
- notification,
- setNotificationPreference,
- } = useUser();
+ const { user, town, mission, newGame, setUser, setMission, setNewGame } =
+ useUser();
const [shouldMissionPopupShown, setShouldMissionPopupShown] =
- useState(!hasMissionPopupSeen);
+ useState(!mission.popup?.hasSeen);
// Update user info
const updateUserInfo = useCallback(
@@ -93,44 +68,31 @@ export const Home: React.FC = () => {
data: { data },
} = await minigameApi.userApi.getUserInfoUsingGET();
if (data) {
- setUserInfo(data.id, data.nickname);
- // FA: track user with set user id
- // analytics.setUserId(data.id);
+ setUser({ userId: data.id, nickname: data.nickname });
}
} catch (error) {
console.error(error);
}
}
},
- [minigameApi.userApi, setUserInfo]
+ [minigameApi.userApi, setUser]
);
// Track user with uuid
const trackUser = useCallback(
async ({
- uUID,
+ uuid,
regionId,
referer,
}: {
- uUID: string;
+ uuid: string;
regionId: string;
- referer?:
- | 'FEED'
- | 'SUBSCRIBE_FEED_1'
- | 'SUBSCRIBE_FEED_2'
- | 'SUBSCRIBE_FEED_3'
- | 'NEAR_BY'
- | 'SHARE_GAME_2048'
- | 'SHARE_GAME_KARROT'
- | 'SHARE_PLATFORM'
- | 'SHARE_COMMUNITY'
- | 'LOGIN'
- | 'UNKNOWN';
+ referer?: RefererEnum;
}) => {
try {
analytics.setUserId(uuid);
const data = await minigameApi.visitorApi.visitUsingPOST(
- uUID,
+ uuid,
regionId,
referer
);
@@ -140,47 +102,16 @@ export const Home: React.FC = () => {
console.error(error);
}
},
- [analytics, minigameApi.visitorApi, uuid]
+ [analytics, minigameApi.visitorApi]
);
useEffect(() => {
- trackUser({ uUID: uuid, regionId: regionId, referer: referer });
- }, [referer, regionId, trackUser, uuid]);
-
- // const checkNotificationStatus = useCallback(async () => {
- // if (notification.newGame.isNotificationOn) {
- // return;
- // } else {
- // try {
- // const {
- // data: { data },
- // } = await minigameApi.notificationApi.checkNotificationUsingGET(
- // 'OPEN_GAME'
- // );
- // if (data && data.check) {
- // setNotificationPreference({
- // isNewGameNotificationOn: data.check,
- // });
- // }
- // } catch (error) {
- // console.error(error);
- // }
- // }
- // }, [
- // minigameApi.notificationApi,
- // notification.newGame.isNotificationOn,
- // setNotificationPreference,
- // ]);
-
- // const newGameNotificationPromise = () => {
- // if (notification.newGame.isNotificationOn) {
- // return notification.newGame.isNotificationOn;
- // } else {
- // const data =
- // minigameApi.notificationApi.checkNotificationUsingGET('OPEN_GAME');
- // if (data !== undefined) return data;
- // }
- // };
+ trackUser({
+ uuid: user.uuid as string,
+ regionId: user.regionId as string,
+ referer: user.referer,
+ });
+ }, [trackUser, user.uuid, user.referer, user.regionId]);
// Check user's notification status
// available notifications: new-game, next-mission
@@ -195,19 +126,25 @@ export const Home: React.FC = () => {
]);
try {
const notificationStatus = await notificationPromise;
- setNotificationPreference({
- isNewGameNotificationOn: notificationStatus[0].data.data?.check,
- isNextMissionNotificationOn: notificationStatus[1].data.data?.check,
+ setNewGame({
+ notification: {
+ isOn: notificationStatus[0].data.data?.check as boolean,
+ },
+ });
+ setMission({
+ notification: {
+ isOn: notificationStatus[1].data.data?.check as boolean,
+ },
});
} catch (error) {
console.error(error);
}
- }, [minigameApi.notificationApi, setNotificationPreference]);
+ }, [minigameApi.notificationApi, setMission, setNewGame]);
useEffect(() => {
- updateUserInfo({ userId: userId });
+ updateUserInfo({ userId: user.userId as string });
checkNotificationStatus();
- }, [checkNotificationStatus, updateUserInfo, userId]);
+ }, [checkNotificationStatus, updateUserInfo, user.userId]);
useEffect(() => {
if (isTop) {
@@ -321,7 +258,7 @@ export const Home: React.FC = () => {
location: 'platform_page',
});
const url = 'https://daangn.onelink.me/HhUa/2da74f80';
- const text = `${nickname}님이 이웃님을 동네대회에 초대했어요! 같이 게임할래요?`;
+ const text = `${user.nickname}님이 이웃님을 동네대회에 초대했어요! 같이 게임할래요?`;
shareApp(url, text);
};
const triggerShareHandler = () => {
@@ -332,31 +269,6 @@ export const Home: React.FC = () => {
}
};
- // Installation handler
- // =================================================================
- const onSubscribeSucess = () => {
- analytics.logEvent('click_subscribe_button', {
- location: 'platform_page',
- is_voluntary: true,
- });
- setIsInstalled(true);
- subscribeToastEmitter();
- };
- const runOnSuccess = () => {
- analytics.logEvent('click_third_party_agreement_button', {
- location: 'platform_page',
- button_type: 'subscribe_button',
- });
- handleSubscribe(onSubscribeSucess);
- };
- const triggerInstallationHandler = () => {
- if (accessToken) {
- handleSubscribe(onSubscribeSucess);
- } else {
- handleThirdPartyAgreement(runOnSuccess);
- }
- };
-
// New game notification handler
// =================================================================
const onSuccessHandler = () => {
@@ -364,9 +276,7 @@ export const Home: React.FC = () => {
location: 'platform_page',
button_type: 'notification_button',
});
- setNotificationPreference({
- isNewGameNotificationOn: true,
- });
+ setNewGame({ notification: { isOn: true } });
};
const handleNewGameNotification = async () => {
if (accessToken) {
@@ -378,9 +288,7 @@ export const Home: React.FC = () => {
analytics.logEvent('click_notification_button', {
notification_type: 'new_game',
});
- setNotificationPreference({
- isNewGameNotificationOn: true,
- });
+ setNewGame({ notification: { isOn: true } });
}
} else {
handleThirdPartyAgreement(onSuccessHandler);
@@ -463,22 +371,8 @@ export const Home: React.FC = () => {
border={`1px solid #ECECEC`}
appendLeft={}
onClickLeft={leaveMiniApp}
- appendRight={
-
-
- {isInstalled ? (
-
- ) : (
-
- )}
-
- }
+ appendRight={}
+ onClickRight={triggerShareHandler}
style={{
background: `#fff`,
}}
@@ -486,7 +380,7 @@ export const Home: React.FC = () => {
- {townName3} 이웃들과
+ {town.name3} 이웃들과
같이 게임해요!
@@ -653,7 +547,7 @@ export const Home: React.FC = () => {
새로운 게임을 준비 중이에요
- {notification.newGame.isNotificationOn ? (
+ {newGame.notification?.isOn ? (
{
onClick={goToMissionPage}
style={{ position: `absolute`, right: 0, bottom: 0, zIndex: 99 }}
>
- {isMissionCheckedOut ? (
+ {mission.notification?.isOn ? (
) : (
{
const { isTop } = useCurrentScreen();
const analytics = useAnalytics();
- const { userId, setUserInfo } = useUserData();
const minigameApi = useMinigameApi();
const { score } = useMyKarrotClickerData();
+ const { user, setUser } = useUser();
const { clickCount, updateAnimationPlayState, shouldPause } = useGame();
const [isPaused, setIsPaused] = useState(false);
@@ -51,30 +51,31 @@ export const Game: React.FC = () => {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [score]);
- const updateUserInfo = useCallback(async () => {
- if (userId) {
- return;
- } else {
- try {
- const {
- data: { data },
- } = await minigameApi.userApi.getUserInfoUsingGET();
- if (data) {
- setUserInfo(data.id, data.nickname);
- // FA: track user with set user id
- // analytics.setUserId(data.id);
+ const updateUserInfo = useCallback(
+ async ({ userId }: { userId: string }) => {
+ if (userId) {
+ return;
+ } else {
+ try {
+ const {
+ data: { data },
+ } = await minigameApi.userApi.getUserInfoUsingGET();
+ if (data) {
+ setUser({ userId: data.id, nickname: data.nickname });
+ }
+ } catch (error) {
+ console.error(error);
}
- } catch (error) {
- console.error(error);
}
- }
- }, [minigameApi.userApi, setUserInfo, userId]);
+ },
+ [minigameApi.userApi, setUser]
+ );
useEffect(() => {
- if (userId === '') {
- updateUserInfo();
+ if (user.userId === '') {
+ updateUserInfo({ userId: user.userId });
}
- }, [updateUserInfo, userId]);
+ }, [updateUserInfo, user.userId]);
useEffect(() => {
if (isTop) {
diff --git a/src/pages/KarrotClicker/Game/Modal/CommentModal.tsx b/src/pages/KarrotClicker/Game/Modal/CommentModal.tsx
index 0b4e7b888..46edaba4e 100644
--- a/src/pages/KarrotClicker/Game/Modal/CommentModal.tsx
+++ b/src/pages/KarrotClicker/Game/Modal/CommentModal.tsx
@@ -7,7 +7,7 @@ import karrotImageUrl from 'assets/svg/KarrotClicker/small_circle_karrot.svg';
import React, { useEffect, useState } from 'react';
import { OldButton, OldDisabledButton } from 'components/Button';
import { useCurrentScreen, useNavigator } from '@karrotframe/navigator';
-import { useUserData } from 'hooks';
+import { useUser } from 'hooks';
import { useMyKarrotClickerData } from 'pages/KarrotClicker/hooks';
import { useMinigameApi } from 'services/api/minigameApi';
import { useAnalytics } from 'services/analytics';
@@ -21,6 +21,7 @@ export const CommentModal: React.FC = (props) => {
const { replace } = useNavigator();
const minigameApi = useMinigameApi();
const analytics = useAnalytics();
+ const { town } = useUser();
const {
score,
rank,
@@ -33,7 +34,6 @@ export const CommentModal: React.FC = (props) => {
length: prevComment.length,
});
- const { townName2: districtName } = useUserData();
// Page navigation
const goToLeaderboardPage = () => {
replace(`/karrot-clicker/leaderboard`);
@@ -84,7 +84,7 @@ export const CommentModal: React.FC = (props) => {
- {districtName} 이웃들에게
+ {town.name2} 이웃들에게
하고 싶은 말을 남겨보세요
@@ -95,7 +95,7 @@ export const CommentModal: React.FC = (props) => {
type="text"
onChange={handleCommentInput}
value={currentComment.comment}
- placeholder={`예) 내가 ${districtName}짱!`}
+ placeholder={`예) 내가 ${town.name2}짱!`}
maxLength={20}
/>
{currentComment.length}/20
diff --git a/src/pages/KarrotClicker/Game/NewUser/Guide.tsx b/src/pages/KarrotClicker/Game/NewUser/Guide.tsx
index 0bbaba576..e60651734 100644
--- a/src/pages/KarrotClicker/Game/NewUser/Guide.tsx
+++ b/src/pages/KarrotClicker/Game/NewUser/Guide.tsx
@@ -3,9 +3,8 @@ import { css } from '@emotion/react';
import { useCurrentScreen } from '@karrotframe/navigator';
import { ReactComponent as PointingFinger } from 'assets/svg/KarrotClicker/pointing_finger.svg';
import { OldButton } from 'components/Button/Button';
-import { useUserData } from 'hooks';
+import { useUser } from 'hooks';
import { useEffect } from 'react';
-// import { useAnalytics } from 'services/analytics';
import { useMinigameApi } from 'services/api/minigameApi';
import { useGame } from '../hooks';
@@ -26,9 +25,8 @@ type Props = {
};
export const Guide: React.FC = (props) => {
const { isTop } = useCurrentScreen();
- // const analytics = useAnalytics();
const minigameApi = useMinigameApi();
- const { setUserInfo } = useUserData();
+ const { setUser } = useUser();
const { updateAnimationPlayState } = useGame();
const updateUserInfo = async () => {
@@ -36,9 +34,7 @@ export const Guide: React.FC = (props) => {
data: { data },
} = await minigameApi.userApi.getUserInfoUsingGET();
if (data) {
- setUserInfo(data.id, data.nickname);
- // FA: track user with set user id
- // analytics.setUserId(data.id);
+ setUser({ userId: data.id, nickname: data.nickname });
}
};
diff --git a/src/pages/KarrotClicker/Home/Home.tsx b/src/pages/KarrotClicker/Home/Home.tsx
index 0d9a224e8..65fdb00c8 100644
--- a/src/pages/KarrotClicker/Home/Home.tsx
+++ b/src/pages/KarrotClicker/Home/Home.tsx
@@ -4,10 +4,9 @@ import { BackIcon } from 'assets/Icon';
import { ActiveUserCount } from 'components/ActiveUserCount';
import { OldButton } from 'components/Button';
import { Nav } from 'components/Navigation/Nav';
-import { useAccessToken, useMini, useUserData } from 'hooks';
+import { useAccessToken, useMini, useUser } from 'hooks';
import { rem } from 'polished';
import { useAnalytics } from 'services/analytics';
-// import { useMinigameApi } from 'services/api/minigameApi';
import { useGame } from '../Game/hooks';
import { useMyKarrotClickerData } from '../hooks';
import { LeaderboardTabs } from '../Leaderboard/LeaderboardTabs';
@@ -55,7 +54,7 @@ export const Home = () => {
const { accessToken } = useAccessToken();
const minigameApi = useMinigameApi();
const { isInWebEnvironment, handleThirdPartyAgreement } = useMini();
- const { nickname, townName2: districtName } = useUserData();
+ const { user, town } = useUser();
const { gameType, rank, score, comment } = useMyKarrotClickerData();
const { resumeGame, onResetCount } = useGame();
@@ -135,11 +134,11 @@ export const Home = () => {
{score === 0 ? null : (
)}
diff --git a/src/pages/KarrotClicker/Leaderboard/Leaderboard.tsx b/src/pages/KarrotClicker/Leaderboard/Leaderboard.tsx
index 7ac2a68ed..82f99e94f 100644
--- a/src/pages/KarrotClicker/Leaderboard/Leaderboard.tsx
+++ b/src/pages/KarrotClicker/Leaderboard/Leaderboard.tsx
@@ -5,7 +5,7 @@ import { useCurrentScreen, useNavigator } from '@karrotframe/navigator';
import { OldButton } from 'components/Button';
import { DefaultUserRow, TopUserRow } from './LeaderboardTabs/Row';
import { LeaderboardTabs } from './LeaderboardTabs';
-import { useMini, useUserData } from 'hooks';
+import { useMini, useUser } from 'hooks';
import { useMyKarrotClickerData } from '../hooks';
import { useMinigameApi } from 'services/api/minigameApi';
import { Nav } from 'components/Navigation/Nav';
@@ -50,7 +50,7 @@ export const Leaderboard = () => {
const analytics = useAnalytics();
const minigameApi = useMinigameApi();
const karrotMarketMini = useMini();
- const { nickname, townName2: districtName } = useUserData();
+ const { user, town } = useUser();
const { gameType, score, rank, comment, updateMyKarrotClickerData } =
useMyKarrotClickerData();
const { onResetCount, resumeGame } = useGame();
@@ -79,7 +79,7 @@ export const Leaderboard = () => {
const handleShare = () => {
const url = 'https://daangn.onelink.me/HhUa/8db9923d';
- const text = `${nickname}님은 당근모아에서 전국 ${rank}등!`;
+ const text = `${user.nickname}님은 당근모아에서 전국 ${rank}등!`;
karrotMarketMini.shareApp(url, text);
analytics.logEvent('click_share_button', {
game_type: 'karrot_clicker',
@@ -116,7 +116,7 @@ export const Leaderboard = () => {
} onClickLeft={goBackToPlatform} />
{score === 0 ? null : (
- {nickname}님은
+ {user.nickname}님은
{rank}위
에요!
@@ -125,11 +125,11 @@ export const Leaderboard = () => {
{score === 0 ? null : (
)}
diff --git a/src/pages/KarrotClicker/Leaderboard/LeaderboardTabs/Leaderboard/DistrictLeaderboard.tsx b/src/pages/KarrotClicker/Leaderboard/LeaderboardTabs/Leaderboard/DistrictLeaderboard.tsx
index be69e37c8..f9a8dce85 100644
--- a/src/pages/KarrotClicker/Leaderboard/LeaderboardTabs/Leaderboard/DistrictLeaderboard.tsx
+++ b/src/pages/KarrotClicker/Leaderboard/LeaderboardTabs/Leaderboard/DistrictLeaderboard.tsx
@@ -78,24 +78,23 @@ export const DistrictLeaderboard: React.FC = () => {
- {districtRankData.slice(0, 10).map((district) => {
+ {districtRankData.slice(0, 10).map((district, i) => {
return (
);
})}
- {districtRankData.slice(10).map((district) => {
+ {districtRankData.slice(10).map((district, i) => {
return (
{
- {individualRankData.slice(0, 10).map((user) => {
+ {individualRankData.slice(0, 10).map((user, i) => {
return (
{
이웃들에게 한 마디를 남겨보세요!
- {individualRankData.slice(10).map((user) => {
+ {individualRankData.slice(10).map((user, i) => {
return (
{
const minigameApi = useMinigameApi();
const { accessToken } = useAccessToken();
const { handleThirdPartyAgreement } = useMini();
- const { notification, setMissionPreference, setNotificationPreference } =
- useUser();
+ const { mission, setMission } = useUser();
useEffect(() => {
if (isTop) {
@@ -34,12 +33,12 @@ export const Mission: React.FC = () => {
hasMissionPopupSeen: true,
})
);
- setMissionPreference({
- isMissionCheckedOut: true,
- hasMissionPopupSeen: true,
+ setMission({
+ page: { isCheckedOut: true },
+ popup: { hasSeen: true },
});
}
- }, [setMissionPreference, isTop]);
+ }, [setMission, isTop]);
const goBackToPlatform = () => {
pop();
@@ -51,9 +50,7 @@ export const Mission: React.FC = () => {
location: 'platform_page',
button_type: 'notification_button',
});
- setNotificationPreference({
- isNextMissionNotificationOn: true,
- });
+ setMission({ notification: { isOn: true } });
};
const turnNextMissionNotificationOn = async () => {
if (accessToken) {
@@ -65,9 +62,7 @@ export const Mission: React.FC = () => {
analytics.logEvent('click_notification_button', {
notification_type: 'next_mission',
});
- setNotificationPreference({
- isNextMissionNotificationOn: true,
- });
+ setMission({ notification: { isOn: true } });
}
} else {
handleThirdPartyAgreement(onSuccessHandler);
@@ -91,8 +86,8 @@ export const Mission: React.FC = () => {
}}
>
@@ -106,12 +101,12 @@ export const Mission: React.FC = () => {
}}
>
- {notification.nextMission.isNotificationOn ? (
+ {mission.notification?.isOn ? (