Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
Apply cookie
Browse files Browse the repository at this point in the history
  • Loading branch information
hhhello0507 committed Aug 27, 2024
1 parent 841863c commit 725857e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 13 deletions.
2 changes: 2 additions & 0 deletions web/src/lib/cookie.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import cookie from "js-cookie";

export const nameKey = 'namekey';

class Cookie {
public getCookie(key: string): string | undefined {
let item = undefined;
Expand Down
8 changes: 3 additions & 5 deletions web/src/page/play/PlayPage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, {useEffect, useState} from "react";
import {useLocation} from "react-router-dom";
import EndDialog from "@src/component/dialog/enddialog/EndDialog";
import Scene1Page from "@src/page/play/scene/scene1/Scene1Page";
import Scene2Page from "@src/page/play/scene/scene2/Scene2Page";
Expand All @@ -16,22 +15,21 @@ import Scene12Page from "@src/page/play/scene/scene12/Scene12Page";
import Scene13Page from "@src/page/play/scene/scene13/Scene13Page";
import FutureDialog from "@src/component/dialog/futuredialog/FutureDialog";
import useNav from "@hook/useNav";
import cookie1, {nameKey} from "@lib/cookie";

export default function PlayPage() {

const {toHome} = useNav();
const [scene, setScene] = useState(1);
const location = useLocation();
const name = location.state.name;
let name = cookie1.getCookie(nameKey);
if (!name) {
toHome();
}
name = name ?? '';
const [isShowEndDialog, setIsShowEndDialog] = useState(false);

const [isShowFutureDialog, setIsShowFutureDialog] = useState(false)

const [playData, setPlayData] = useState<string[]>([])

function nextScene() {
setScene(scene + 1);
}
Expand Down
5 changes: 2 additions & 3 deletions web/src/page/play/scene/ScenePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import TypingText from "@src/component/TypingText";
import PlaySong from "@src/designsystem/util/PlaySong";
import SelectText from "@src/component/SelectText";
import Loader from "@src/component/loader/Loader";
import {useLocation} from "react-router-dom";
import useNav from "@hook/useNav";
import cookie1, {nameKey} from "@lib/cookie";

interface ScenePageProps {
backgroundUrl: string;
Expand All @@ -17,8 +17,7 @@ interface ScenePageProps {

function ScenePage(props: ScenePageProps) {
const {toHome} = useNav();
const location = useLocation();
const name = location.state.name;
const name = cookie1.getCookie(nameKey);
if (!name) {
toHome();
}
Expand Down
8 changes: 3 additions & 5 deletions web/src/page/start/StartPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {Background} from "@src/component/Background.style";
import ExpandRight from "@designsystem/foundation/iconography/icons/ExpandRight";
import {useNavigate} from "react-router-dom";
import {StartButton} from "@src/component/StartButton.style";
import cookie1, {nameKey} from "@lib/cookie";

export default function StartPage() {

Expand Down Expand Up @@ -101,11 +102,8 @@ export default function StartPage() {
<S.StartButtonContainer>
<StartButton
onClick={() => {
navigate('play', {
state: {
name
}
});
navigate('play');
cookie1.setCookie(nameKey, name);
}}
>
시작하기
Expand Down

0 comments on commit 725857e

Please sign in to comment.