Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ Mypage ] 내기록보기 selectOption query parameter로 받아오기 #357

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/Enter/page/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,13 @@ function Enter() {
}
};

const handleHeaderBackBtn = () => {
navigate('/');
};

return (
<React.Fragment>
<Header headerTitle="마이페이지" />
<Header headerTitle="마이페이지" handleFn={handleHeaderBackBtn} />
{isLogin ? (
<S.MypageBodyWrapper>
<S.NicknameWrapper>
Expand Down
7 changes: 5 additions & 2 deletions src/History/components/SelectModal/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useState } from 'react';
import { useNavigate } from 'react-router-dom';

import { IcMypageArrowRight, IcMypageTouchbar } from '../../../assets';
import { optionList } from '../../constants/optionList';
Expand All @@ -8,8 +9,8 @@ import * as S from './SelectModal.style';
interface SelectModalProps {
modalOn: boolean;
closeModal: () => void;
selectOption: (option: number) => void;
selectedModalOptionList: Array<number>;
selectOption: (section: string) => void;
selectedModalOptionList: Array<string>;
}

function SelectModal({
Expand All @@ -19,6 +20,7 @@ function SelectModal({
selectedModalOptionList,
}: SelectModalProps) {
const [animationDirection, setAnimationDirection] = useState('slideUp');
const navigate = useNavigate();

const handleCloseModal = () => {
setAnimationDirection('slideDown');
Expand Down Expand Up @@ -46,6 +48,7 @@ function SelectModal({
onClick={() => {
selectOption(item);
handleCloseModal();
navigate(`/mypage/history/${item}`);
}}
>
<S.OptionListItemText>{optionList[item]}</S.OptionListItemText>
Expand Down
6 changes: 3 additions & 3 deletions src/History/constants/optionList.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const optionList: Record<string, string> = {
1: '즐겨찾기한 레큐북',
2: '내가 만든 레큐북',
3: '내가 남긴 레터',
'favorite': '즐겨찾기한 레큐북',
'myBook': '내가 만든 레큐북',
'myLetter': '내가 남긴 레터',
};
33 changes: 20 additions & 13 deletions src/History/page/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useState } from 'react';
import { useLocation } from 'react-router-dom';
import { useNavigate, useParams } from 'react-router-dom';

import { IcArrowDownBlack } from '../../assets';
import Header from '../../components/common/Header';
Expand All @@ -11,27 +11,35 @@ import { optionList } from '../constants/optionList';
import * as S from './History.style';

function History() {
const location = useLocation();
const SECTION_LIST = ['favorite', 'myBook', 'myLetter'];

const navigate = useNavigate();
const { section } = useParams() as { section: string };

const [modalOn, setModalOn] = useState(false);
const [selectedOption, setSelectedOption] = useState<number>(location.state);
const [selectedOption, setSelectedOption] = useState<string>(section);

const handleClickHistorySelectButton = () => {
setModalOn(true);
};

const handleHeaderBackBtn = () => {
navigate('/mypage/select-history');
};

return (
<React.Fragment>
{modalOn && (
<SelectModal
modalOn={modalOn}
closeModal={() => setModalOn(false)}
selectOption={(option: number) => setSelectedOption(option)}
selectedModalOptionList={[1, 2, 3].filter(
(num) => num !== selectedOption,
selectOption={(section: string) => setSelectedOption(section)}
selectedModalOptionList={SECTION_LIST.filter(
(item) => item !== selectedOption,
)}
/>
)}
<Header headerTitle="내 기록보기" />
<Header headerTitle="내 기록보기" handleFn={handleHeaderBackBtn} />
<S.HistoryPageBodyWrapper>
<S.HistorySelectButton
type="button"
Expand All @@ -42,13 +50,12 @@ function History() {
</S.CurrentHistoryOption>
<IcArrowDownBlack />
</S.HistorySelectButton>
{
{section &&
{
1: <MyFavoriteBookList />,
2: <MyLecueBookList />,
3: <MyLetterList />,
}[selectedOption]
}
favorite: <MyFavoriteBookList />,
myBook: <MyLecueBookList />,
myLetter: <MyLetterList />,
}[section]}
</S.HistoryPageBodyWrapper>
</React.Fragment>
);
Expand Down
12 changes: 8 additions & 4 deletions src/HistoryEnter/page/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,37 @@ import * as S from './HistoryEnter.style';
function HistoryEnter() {
const navigate = useNavigate();

const handleHeaderBackBtn = () => {
navigate('/mypage');
};

const HistoryEnterList = useMemo(
() => [
{
title: '즐겨찾기한 레큐북',
variant: 'book',
image: <ImgMypageFavoriteLecueBook />,
handleClickTab: () => navigate('/mypage/history', { state: 1 }),
handleClickTab: () => navigate('/mypage/history/favorite'),
},
{
title: '내가 만든 레큐북',
variant: 'book',
image: <ImgMypageMakeLecueBook />,
handleClickTab: () => navigate('/mypage/history', { state: 2 }),
handleClickTab: () => navigate('/mypage/history/myBook'),
},
{
title: '내가 남긴 레터',
variant: 'letter',
image: <ImgMypageLetter />,
handleClickTab: () => navigate('/mypage/history', { state: 3 }),
handleClickTab: () => navigate('/mypage/history/myLetter'),
},
],
[],
);

return (
<React.Fragment>
<Header headerTitle="내 기록보기" />
<Header headerTitle="내 기록보기" handleFn={handleHeaderBackBtn} />
<S.HistoryEnterPageBodyWrapper>
{HistoryEnterList.map((element) => {
return (
Expand Down
2 changes: 1 addition & 1 deletion src/Router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function Router() {
<Route path="" element={<Enter />} />
<Route path="edit-nickname" element={<EditNickname />} />
<Route path="select-history" element={<HistoryEnter />} />
<Route path="history" element={<History />} />
<Route path="history/:section" element={<History />} />
</Route>
<Route path="/lecue-book/:bookUuid" element={<DetailPage />} />
<Route path="/target" element={<TargetPage />} />
Expand Down