Skip to content

Commit

Permalink
feat: 학습하기 메인 탭 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
cjy3458 committed Aug 26, 2024
1 parent d19e4e5 commit c67e2d1
Show file tree
Hide file tree
Showing 16 changed files with 251 additions and 56 deletions.
6 changes: 4 additions & 2 deletions src/apis/createTales.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,13 @@ export const getTale = async (lanId: number, taleId: number) => {
}
};

export const getRecentTale = async () => {
export const getRecentTale = async (count?: number) => {
try {
const access = LocalStorage.getItem("access");
const authAxios = getAuthAxios(access);
const response = await authAxios.get(`${baseURL}/tales/recently`);
const response = await authAxios.get(
`${baseURL}/tales/recently${count ? `&count=${count}` : ""}`
);
console.log(response.data.data.tales);
return response.data.data.tales;
} catch (error) {
Expand Down
8 changes: 4 additions & 4 deletions src/apis/home.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const getWord = async (count?: number) => {
const response = await authAxios.get(
`${baseURL}/tales/word${count ? `?count=${count}` : ""}`
);
return response.data;
return response.data.data;
} catch (error) {
throw error;
}
Expand All @@ -32,7 +32,7 @@ export const getUnlearnedTales = async (
const response = await authAxios.get(
`${baseURL}/tales/unlearned?koreanVersion=${koreanVersion}${count ? `&count=${count}` : ""}`
);
return response.data;
return response.data.data;
} catch (error) {
throw error;
}
Expand All @@ -41,7 +41,7 @@ export const getUnlearnedTales = async (
/**
* 최근 학습한 동화 전체 조회
*/
export const getStudiedTales = async (
export const getLearnedTales = async (
koreanVersion: boolean,
count?: number
) => {
Expand All @@ -51,7 +51,7 @@ export const getStudiedTales = async (
const response = await authAxios.get(
`${baseURL}/tales/studied?koreanVersion=${koreanVersion}${count ? `&count=${count}` : ""}`
);
return response.data;
return response.data.data;
} catch (error) {
throw error;
}
Expand Down
1 change: 1 addition & 0 deletions src/components/common/common.styled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,5 @@ export const MainWrapper = styled.div`
align-items: flex-start;
gap: 3rem;
padding-top: 3rem;
padding-bottom: 140px;
`;
18 changes: 18 additions & 0 deletions src/components/home/homeRecentTales/Card.styled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,23 @@ export const CardWrapper = styled.div`
padding: 1.2rem 2.4rem;
margin-left: 1.5rem;
button {
min-width: 80px;
width: 100%;
background-color: #ffffff;
border: none;
border-radius: 4px;
padding: 8px;
font-size: 1.6rem;
font-weight: 700;
margin-bottom: 2rem;
cursor: pointer;
}
`;

export const TitleWrapper = styled.div`
display: flex;
flex-direction: column;
margin-top: 0.5rem;
gap: 1rem;
`;

Expand All @@ -54,3 +60,15 @@ export const CardImg = styled.img`
width: 100%;
margin-bottom: 1rem;
`;

export const BtnWrapper = styled.div`
width: 100%;
display: flex;
justify-content: center;
gap: 1rem;
div {
margin-top: 0.5rem;
font-size: 3rem;
font-weight: 700;
}
`;
9 changes: 8 additions & 1 deletion src/components/home/homeRecentTales/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ const Card = (props: CardProps) => {
<S.CardCreatedAt>{props.createdAt}</S.CardCreatedAt>
</S.TitleWrapper>
{props.btnText ? (
<button onClick={props.learnFunction}>{props.btnText}</button>
props.point ? (
<S.BtnWrapper>
<div>{props.point}</div>
<button onClick={props.learnFunction}>{props.btnText}</button>
</S.BtnWrapper>
) : (
<button onClick={props.unLearnedFunction}>{props.btnText}</button>
)
) : (
<S.CardImg src={imgSrc} />
)}
Expand Down
1 change: 0 additions & 1 deletion src/components/home/homeRecentTales/HomeRecentTales.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ const HomeRecentTales = () => {
<ItemWrapper>
{taleGroup.map((tale) => (
<Card
key={tale.taleId}
taleId={tale.taleId}
title={tale.title}
createdAt={tale.createdAt}
Expand Down
1 change: 0 additions & 1 deletion src/components/home/homeRecentTales/MoreRecentTales.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ const MoreRecentTales = () => {
<ItemWrapper>
{taleGroup.map((tale) => (
<Card
key={tale.taleId}
taleId={tale.taleId}
title={tale.title}
createdAt={tale.createdAt}
Expand Down
53 changes: 7 additions & 46 deletions src/components/learn/learnMain/Learn.tsx
Original file line number Diff line number Diff line change
@@ -1,55 +1,16 @@
import {
CommonTitle,
CommonTitleWrapper,
ItemWrapper,
MainWrapper,
} from "@components/common/common.styled";
import * as S from "./Learn.styeld";
import { MainWrapper } from "@components/common/common.styled";
import TabBar from "@components/common/tabBar/TabBar";
import Word from "./word/Word";
import UnLearned from "./unLearned/UnLearned";
import Learned from "./learned/Learned";

const Learn = () => {
const handleMoreClick = () => {
console.log(1);
};
return (
<>
<MainWrapper>
<CommonTitleWrapper>
<CommonTitle>단어장</CommonTitle>
<div className="more" onClick={handleMoreClick}>
{"더보기 >"}
</div>
</CommonTitleWrapper>
<S.GridWrapper>
<S.WordCard>단어장</S.WordCard>
<S.WordCard>단어장</S.WordCard>
<S.WordCard>단어장</S.WordCard>
<S.WordCard>단어장</S.WordCard>
</S.GridWrapper>
<CommonTitleWrapper>
<CommonTitle>아직 학습하지 않은 동화</CommonTitle>
<div className="more" onClick={handleMoreClick}>
{"더보기 >"}
</div>
</CommonTitleWrapper>
<ItemWrapper>
<S.WordCard>단어장</S.WordCard>
<S.WordCard>단어장</S.WordCard>
<S.WordCard>단어장</S.WordCard>
<S.WordCard>단어장</S.WordCard>
</ItemWrapper>
<CommonTitleWrapper>
<CommonTitle>최근 학습한 동화</CommonTitle>
<div className="more" onClick={handleMoreClick}>
{"더보기 >"}
</div>
</CommonTitleWrapper>
<ItemWrapper>
<S.WordCard>단어장</S.WordCard>
<S.WordCard>단어장</S.WordCard>
<S.WordCard>단어장</S.WordCard>
<S.WordCard>단어장</S.WordCard>
</ItemWrapper>
<Word />
<UnLearned />
<Learned />
</MainWrapper>
<TabBar />
</>
Expand Down
54 changes: 54 additions & 0 deletions src/components/learn/learnMain/learned/Learned.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { getLearnedTales } from "@apis/home";
import {
CommonTitle,
CommonTitleWrapper,
ItemWrapper,
} from "@components/common/common.styled";
import Card from "@components/home/homeRecentTales/Card";
import { LearnedProps } from "@type/card";

import { useEffect, useState } from "react";
import { useNavigate } from "react-router-dom";

const Learned = () => {
const navigate = useNavigate();
const handleMoreClick = () => {
navigate("/more", { state: { learned } });
};

const [learned, setLearned] = useState<LearnedProps[]>([]);
const sliceLearned = learned.slice(0, 3);

useEffect(() => {
const fetchGetStudiedTales = async () => {
const response: LearnedProps[] = await getLearnedTales(true);
setLearned(response);
};
fetchGetStudiedTales();
}, []);

return (
<>
<CommonTitleWrapper>
<CommonTitle>최근 학습한 동화</CommonTitle>
<div className="more" onClick={handleMoreClick}>
{"더보기 >"}
</div>
</CommonTitleWrapper>
<ItemWrapper>
{sliceLearned.map((learned: LearnedProps) => (
<Card
taleId={learned.tale_id}
title={learned.languageTale.title}
createdAt={learned.createdAt}
point={"4/10"}
btnText="복습하기"
// readFunction={() => handleMoreClick()}
/>
))}
</ItemWrapper>
</>
);
};

export default Learned;
10 changes: 10 additions & 0 deletions src/components/learn/learnMain/learned/LearnedMore.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from "react";
import { useLocation } from "react-router-dom";

const LearnedMore = () => {
const location = useLocation();

return <div>LearnedMore</div>;
};

export default LearnedMore;
52 changes: 52 additions & 0 deletions src/components/learn/learnMain/unLearned/UnLearned.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { getUnlearnedTales } from "@apis/home";
import {
CommonTitle,
CommonTitleWrapper,
ItemWrapper,
} from "@components/common/common.styled";
import Card from "@components/home/homeRecentTales/Card";
import { UnLearnedProps } from "@type/card";

import { useEffect, useState } from "react";
import { useNavigate } from "react-router-dom";

const UnLearned = () => {
const navigate = useNavigate();
const handleMoreClick = () => {
navigate("/more", { state: { unLearned } });
};
const [unLearned, setUnLearned] = useState<UnLearnedProps[]>([]);
const sliceUnLearned = unLearned.slice(0, 3);

useEffect(() => {
const fetchUnLearnTales = async () => {
const response: UnLearnedProps[] = await getUnlearnedTales(true);
setUnLearned(response);
};

fetchUnLearnTales();
}, []);
return (
<>
<CommonTitleWrapper>
<CommonTitle>아직 학습하지 않은 동화</CommonTitle>
<div className="more" onClick={handleMoreClick}>
{"더보기 >"}
</div>
</CommonTitleWrapper>
<ItemWrapper>
{sliceUnLearned.map((unLearned: UnLearnedProps) => (
<Card
taleId={unLearned.tale_id}
title={unLearned.languageTale.title}
createdAt={unLearned.createdAt}
btnText="학습하기✏️"
readFunction={() => handleMoreClick()}
/>
))}
</ItemWrapper>
</>
);
};

export default UnLearned;
10 changes: 10 additions & 0 deletions src/components/learn/learnMain/unLearned/UnLearnedMore.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from "react";
import { useLocation } from "react-router-dom";

const UnLearnedMore = () => {
const location = useLocation();

return <div>UnLearnedMore</div>;
};

export default UnLearnedMore;
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export const GridWrapper = styled.div`
@media (max-width: 768px) {
grid-template-columns: repeat(2, 1fr);
}
@media (max-width: 480px) {
grid-template-columns: 1fr;
}
Expand Down
46 changes: 46 additions & 0 deletions src/components/learn/learnMain/word/Word.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { getWord } from "@apis/home";
import {
CommonTitle,
CommonTitleWrapper,
} from "@components/common/common.styled";
import { WordProps } from "@type/card";
import * as S from "./Word.styled";

import { useEffect, useState } from "react";
import { useNavigate } from "react-router-dom";

const Word = () => {
const navigate = useNavigate();
const handleMoreClick = () => {
navigate("/more", { state: { word } });
};
const [word, setWord] = useState<WordProps[]>([]);
const sliceWord = word.slice(0, 6);

useEffect(() => {
const fetchWord = async () => {
const response: WordProps[] = await getWord();
setWord(response);
};

fetchWord();
}, []);

return (
<>
<CommonTitleWrapper>
<CommonTitle>단어장</CommonTitle>
<div className="more" onClick={handleMoreClick}>
{"더보기 >"}
</div>
</CommonTitleWrapper>
<S.GridWrapper>
{sliceWord.map((word: WordProps) => (
<S.WordCard>{word.word}</S.WordCard>
))}
</S.GridWrapper>
</>
);
};

export default Word;
9 changes: 9 additions & 0 deletions src/components/learn/learnMain/word/WordMore.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { useLocation } from "react-router-dom";

const WordMore = () => {
const location = useLocation();

return <div>WordMore</div>;
};

export default WordMore;
Loading

0 comments on commit c67e2d1

Please sign in to comment.