Skip to content

Commit

Permalink
feat: 유저 flow 적용 및 기타 (#38)
Browse files Browse the repository at this point in the history
* 새로고침 대응안하고자 메모리 라우터로 변경

* local storage 키도 한곳에 모으기

* 유저 플로우 홈에다 적용

* 온보딩에서 선택페이지로 이동하도록 변경

* 마이페이지 고양이 이름 적용
  • Loading branch information
young-do authored Aug 18, 2024
1 parent 7b42792 commit 511cf2d
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 57 deletions.
2 changes: 1 addition & 1 deletion src/renderer/app/router.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Navigate, HashRouter as ReactRouter, Route, Routes } from 'react-router-dom';
import { Navigate, MemoryRouter as ReactRouter, Route, Routes } from 'react-router-dom';

import RootLayout from './layout';

Expand Down
6 changes: 5 additions & 1 deletion src/renderer/features/time/hooks/use-focus-notification.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { useLocalStorage } from 'usehooks-ts';

import { CatType } from '@/entities/cat';
import { LOCAL_STORAGE_KEY } from '@/shared/constants';
import { useNotification } from '@/shared/hooks';

export const useFocusNotification = () => {
const { permission, requestPermission, createNotification } = useNotification();
const [isEnabled, setIsEnabled] = useLocalStorage('isPushFocusEnabled', permission === 'granted');
const [isEnabled, setIsEnabled] = useLocalStorage(
LOCAL_STORAGE_KEY.PUSH_FOCUS_ENABLED,
permission === 'granted',
);
const isUnavailable = permission === 'not-supported' || permission === 'denied';

const changeEnabled = async (nextEnabled: boolean) => {
Expand Down
61 changes: 14 additions & 47 deletions src/renderer/pages/home.tsx
Original file line number Diff line number Diff line change
@@ -1,57 +1,24 @@
import { useEffect } from 'react';

import { useNavigate } from 'react-router-dom';
import { useLocalStorage } from 'usehooks-ts';

import { useUser } from '@/features/user';
import { PATH } from '@/shared/constants';
import { useAuthToken, useMachineId } from '@/shared/hooks';
import { Button } from '@/shared/ui';
import { LOCAL_STORAGE_KEY, PATH } from '@/shared/constants';

const Home = () => {
const navigate = useNavigate();
const machineId = useMachineId();
const { data: authToken } = useAuthToken();
const [isCompleted] = useLocalStorage(LOCAL_STORAGE_KEY.ONBOARDING_COMPLETED, false);
const { data: user } = useUser();
console.log('from env:', import.meta.env.VITE_SAMPLE);
console.log('authToken:', authToken, 'user:', user);
return (
<div>
<p>your machine id: {machineId}</p>
<Button
onClick={() => {
navigate(PATH.ONBOARDING);
}}
>
온보딩 페이지로 가기
</Button>
<Button
onClick={() => {
navigate(PATH.SELECTION);
}}
>
선택 페이지로 가기
</Button>
<Button
onClick={() => {
navigate(PATH.POMODORO);
}}
>
뽀모도로 페이지로 가기
</Button>
<Button
onClick={() => {
navigate(PATH.NAMING);
}}
>
이름짓기 페이지로 가기
</Button>
<Button
onClick={() => {
navigate(PATH.MY_PAGE);
}}
>
마이 페이지로 가기
</Button>
</div>
);

useEffect(() => {
if (!user) return;
if (!isCompleted) return navigate(PATH.ONBOARDING);
if (!user.cat) return navigate(PATH.SELECTION);
navigate(PATH.POMODORO);
}, [isCompleted, user]);

return <div>loading... 🐈 🐈‍⬛</div>;
};

export default Home;
4 changes: 3 additions & 1 deletion src/renderer/pages/mypage.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { useNavigate } from 'react-router-dom';

import { useFocusNotification } from '@/features/time';
import { useUser } from '@/features/user';
import { PATH } from '@/shared/constants';
import { Frame, Icon, Toggle } from '@/shared/ui';

const MyPage = () => {
const navigate = useNavigate();
const { data: user } = useUser();
const { isEnabled, isUnavailable, changeEnabled } = useFocusNotification();

return (
Expand All @@ -15,7 +17,7 @@ const MyPage = () => {
<div className="w-full flex flex-col gap-3">
<ActionButton onClick={() => navigate(PATH.MY_CAT)}>
<span className="subBody-r text-text-tertiary">나의 고양이</span>
<span className="header-4 text-text-primary">이이오</span>
<span className="header-4 text-text-primary">{user?.cat?.name}</span>
</ActionButton>

{/* <OfflineStat /> */}
Expand Down
13 changes: 11 additions & 2 deletions src/renderer/pages/onboarding.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useNavigate } from 'react-router-dom';
import { useLocalStorage } from 'usehooks-ts';

import { PATH } from '@/shared/constants';
import { LOCAL_STORAGE_KEY, PATH } from '@/shared/constants';
import {
Button,
Carousel,
Expand Down Expand Up @@ -40,6 +41,7 @@ const contents = [
const OnboardingContent = () => {
const { currentIndex } = useCarousel();
const navigate = useNavigate();
const [, setIsCompleted] = useLocalStorage(LOCAL_STORAGE_KEY.ONBOARDING_COMPLETED, false);

return (
<div className="h-full flex flex-col items-center justify-center gap-12">
Expand Down Expand Up @@ -84,7 +86,14 @@ const OnboardingContent = () => {
</div>

<div className="flex gap-1">
<Button size="lg" className="w-[200px]" onClick={() => navigate(PATH.HOME)}>
<Button
size="lg"
className="w-[200px]"
onClick={() => {
setIsCompleted(true);
navigate(PATH.SELECTION);
}}
>
시작하기
</Button>
</div>
Expand Down
6 changes: 6 additions & 0 deletions src/renderer/shared/constants/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,9 @@ export const MUTATION_KEY = {
// category
UPDATE_CATEGORY: ['updateCategory'],
};

export const LOCAL_STORAGE_KEY = {
PUSH_FOCUS_ENABLED: 'isPushFocusEnabled',
ONBOARDING_COMPLETED: 'isOnboardingCompleted',
GUIDE_SHOWN: 'isGuideShown',
};
7 changes: 2 additions & 5 deletions src/renderer/widgets/pomodoro/ui/home-screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { useCategories, useUpdateCategory, ChangeCategoryDrawer } from '@/featur
import { catNameMap } from '@/features/pomodoro';
import { ChangeTimeDialog } from '@/features/time';
import { useUser } from '@/features/user';
import { PATH } from '@/shared/constants';
import { LOCAL_STORAGE_KEY, PATH } from '@/shared/constants';
import { useDisclosure } from '@/shared/hooks';
import { Button, Guide, Icon, Tooltip } from '@/shared/ui';
import { getCategoryIconName, createIsoDuration } from '@/shared/utils';
Expand Down Expand Up @@ -39,10 +39,7 @@ export const HomeScreen = ({

const [clickedMode, setClickedMode] = useState<'focus' | 'rest'>('focus');

const [showGuide, setShowGuide] = useLocalStorage<boolean>(
'showGuide',
!(localStorage.getItem('showGuide') === 'false'),
);
const [showGuide, setShowGuide] = useLocalStorage<boolean>(LOCAL_STORAGE_KEY.GUIDE_SHOWN, false);

const changeTimeDialogProps = useDisclosure();
const changeCategoryDrawerProps = useDisclosure();
Expand Down

0 comments on commit 511cf2d

Please sign in to comment.