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

[FEAT] 메인 api 연결 및 카드 구조 변경 #55

Merged
merged 12 commits into from
Aug 27, 2024
13 changes: 13 additions & 0 deletions src/Layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import ScrollToTop from "@utils/ScrollToTop";
import { Outlet } from "react-router-dom";

const Layout = () => {
return (
<>
<ScrollToTop />
<Outlet />
</>
);
};

export default Layout;
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ export const CardContainer = styled.div<CardContainerProps>`
border-radius: 8px;
margin: 5px;
box-sizing: border-box;
@media (max-width: 466px) {
width: 100%;
height: 150px;
overflow: hidden;
}
`;

export const CardWrapper = styled.div`
Expand All @@ -35,13 +40,19 @@ export const CardWrapper = styled.div`
margin-bottom: 2rem;
cursor: pointer;
}
@media (max-width: 466px) {
margin-left: 10%;
}
`;

export const TitleWrapper = styled.div`
display: flex;
flex-direction: column;
margin-top: 0.5rem;
gap: 1rem;
@media (max-width: 466px) {
margin-bottom: 1rem;
}
`;

export const CardTitle = styled.div`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { CardProps } from "@type/card";
import * as S from "./Card.styled";
import { useNavigate } from "react-router-dom";

const pairs = [
["#FFC300", "#FFE249", "250px", "/taleGraphic1.png"],
Expand All @@ -17,10 +18,26 @@ const Card = (props: CardProps) => {
const [backgroundColor1, backgroundColor2, height, imgSrc] =
getRandomColorPair();

const navigate = useNavigate();

const goTaleRead = () => {
navigate(`/readTale`, { state: { response: { taleId: props.taleId } } });
};

const goTaleLearn = () => {
navigate(`/learnTale/pre`, { state: { taleId: props.taleId } });
};

const goTaleQuiz = () => {
navigate(`/learnTale/quiz`, { state: props.languageTaleId });
};

return (
<>
<S.CardContainer
onClick={props.readFunction}
onClick={() => {
goTaleRead();
}}
height={height}
backgroundColor1={backgroundColor1}
backgroundColor2={backgroundColor2}
Expand All @@ -31,13 +48,27 @@ const Card = (props: CardProps) => {
<S.CardCreatedAt>{props.createdAt}</S.CardCreatedAt>
</S.TitleWrapper>
{props.btnText ? (
props.point ? (
props.firstQuizCount !== undefined ? (
<S.BtnWrapper>
<div>{props.point}</div>
<button onClick={props.learnFunction}>{props.btnText}</button>
<div>{props.firstQuizCount}/10</div>
<button
onClick={(e) => {
e.stopPropagation();
goTaleQuiz();
}}
>
{props.btnText}
</button>
</S.BtnWrapper>
) : (
<button onClick={props.unLearnedFunction}>{props.btnText}</button>
<button
onClick={(e) => {
e.stopPropagation();
goTaleLearn();
}}
>
{props.btnText}
</button>
)
) : (
<S.CardImg src={imgSrc} />
Expand Down
5 changes: 4 additions & 1 deletion src/components/common/common.styled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ export const Shelf = styled.img`
@media (max-width: 710px) {
width: 520px;
}
@media (max-width: 519px) {
@media (max-width: 550px) {
width: 420px;
}
@media (max-width: 466px) {
display: none;
}
`;
8 changes: 4 additions & 4 deletions src/components/learn/TaleLearn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@ import FinishScreen from "@components/common/FinishScreen";
import NextBtn from "@components/common/NextBtn";
import ProgressBar from "@components/common/progressBar/ProgressBar";
import useLearning from "@hooks/useLearning";
import ChoiceQuiz from "./ChoiceQuiz";
import EssayQuiz from "./EssayQuiz";
import SentenceQuiz from "./SentenceQuiz";
import ChoiceQuiz from "./quiz/ChoiceQuiz";
import SentenceQuiz from "./quiz/SentenceQuiz";
import {
EssayQuestions,
MultipleChoices,
QuizData,
SentenceArrangements,
} from "@type/learning";
import { QUIZ_STAGES, QuizType } from "@utils/constants/QuizStage";
import SpeakPractice from "./SpeakPractice";
import SpeakPractice from "./quiz/SpeakPractice";
import { useEffect } from "react";
import { postAnswerCount } from "@apis/learning";
import Header from "@components/common/header/Header";
import styled from "styled-components";
import EssayQuiz from "./quiz/EssayQuiz";

interface TaleLearnProps {
quizData?: QuizData;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as S from "./learn.styled";
import * as S from "../learn.styled";
import Header from "@common/header/Header";
import { useLocation, useNavigate } from "react-router-dom";
import ProgressBar from "@components/common/progressBar/ProgressBar";
Expand All @@ -8,10 +8,10 @@ import { nationElements } from "@utils/defaultData";
import { useResult } from "@hooks/useResult";
import { getLearnedHistory, getLearningLevel } from "@apis/learning";
import { useEffect, useState } from "react";
import CreateQuiz from "./CreateQuiz";
import useSelectLevel from "@hooks/useSelectLevel";
import SelectOptionList from "@common/selectOption/SelectOptionList";
import styled from "styled-components";
import CreateQuiz from "./CreateQuiz";

const PreLearningQuestion = () => {
const location = useLocation();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import SelectOptionList from "@components/common/selectOption/SelectOptionList";
import * as S from "./learn.styled";
import * as S from "../learn.styled";
import { useEffect, useState } from "react";
import { ChoiceQuizProps } from "@type/learning";
import { shuffleArray } from "@utils/learnUtil";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect, useState } from "react";
import * as S from "./learn.styled";
import * as S from "../learn.styled";
import SelectBtn from "@components/common/selectOption/SelectBtn";
import { EssayQuizProps } from "@type/learning";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect, useState } from "react";
import * as S from "./learn.styled";
import * as S from "../learn.styled";
import { SentenceQuizProps } from "@type/learning";
import { shuffleArray } from "@utils/learnUtil";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SpeakPracticeProps } from "@type/learning";
import { speakText } from "@utils/speechUtil";
import * as S from "./speakPractice.styled";
import * as S from "../speakPractice.styled";

const SpeakPractice = ({ data }: { data: SpeakPracticeProps }) => {
return (
Expand Down
4 changes: 2 additions & 2 deletions src/components/login/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ const Login = () => {
return (
<CommonWrapper>
<S.Title>
<div>메인 소개 멘트 어쩌구</div>
<div>글로우테일로 동화를 어쩌구</div>
<div>글로우테일에서 동화를 만들고,</div>
<div>퀴즈로 학습의 재미를 더해보세요!</div>
</S.Title>
<S.Image src="/loginGraphic.png" />
<S.LoginBtn>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import TabBar from "@components/common/tabBar/TabBar";
import HomeHeader from "./homeHeader/HomeHeader";
import * as S from "./Home.styled";
import HomeStatus from "./homeStatus/HomeStatus";
import HomeRecentTales from "./homeRecentTales/HomeRecentTales";
import HomeStatus from "./homeStatus/HomeStatus";
import HomeHeader from "./homeHeader/HomeHeader";
// import Modal from "@components/common/modal/Modal";

const Home = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import {
ItemWrapper,
Shelf,
} from "@components/common/common.styled";
import Card from "./Card";
import * as S from "./HomeRecentTales.styled";
import { getRecentTale } from "@apis/createTales";
import { useEffect, useState } from "react";
import { CardProps } from "@type/card";
import { useNavigate } from "react-router-dom";
import { useMediaQuery } from "react-responsive";
import Card from "@components/common/card/Card";

const HomeRecentTales = () => {
const mediaQuery = useMediaQuery({ query: "(max-width: 710px)" });
Expand Down Expand Up @@ -56,6 +56,7 @@ const HomeRecentTales = () => {
taleId={tale.taleId}
title={tale.title}
createdAt={tale.createdAt}
languageTaleId={tale.taleId}
readFunction={() => goRead(tale)}
/>
{(index + 1) % 2 === 0 && index !== sliceTales.length - 1 && (
Expand All @@ -73,7 +74,7 @@ const HomeRecentTales = () => {
taleId={tale.taleId}
title={tale.title}
createdAt={tale.createdAt}
readFunction={() => goRead(tale)}
languageTaleId={tale.taleId}
/>
))}
</ItemWrapper>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
import Header from "@components/common/header/Header";
import { useLocation, useNavigate } from "react-router-dom";
import { useLocation } from "react-router-dom";
import * as S from "./HomeRecentTales.styled";
import Card from "./Card";
import { CardProps } from "@type/card";
import { useMediaQuery } from "react-responsive";
import { ItemWrapper, Shelf } from "@components/common/common.styled";
import Card from "@components/common/card/Card";

const MoreRecentTales = () => {
const mediaQuery = useMediaQuery({ query: "(max-width: 710px)" });

const location = useLocation();
const { allTales } = location.state || { allTales: [] };
const navigate = useNavigate();

const chunkedTales: CardProps[][] = [];
for (let i = 0; i < allTales.length; i += 3) {
chunkedTales.push(allTales.slice(i, i + 3));
}

const goRead = (response: CardProps) => {
navigate(`/readTale`, { state: { response } });
};

return (
<>
<Header text="최근 생성한 동화" />
Expand All @@ -35,7 +30,7 @@ const MoreRecentTales = () => {
taleId={tale.taleId}
title={tale.title}
createdAt={tale.createdAt}
readFunction={() => goRead(tale)}
languageTaleId={tale.languageTaleId}
/>
{(index + 1) % 2 === 0 && index !== allTales.length - 1 && (
<Shelf src="/shelf.png" key={`shelf-${index}`} />
Expand All @@ -52,7 +47,7 @@ const MoreRecentTales = () => {
taleId={tale.taleId}
title={tale.title}
createdAt={tale.createdAt}
readFunction={() => goRead(tale)}
languageTaleId={tale.languageTaleId}
/>
))}
<Shelf src="/shelf.png" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@
import { getLearnedTales } from "@apis/home";
import Card from "@components/common/card/Card";
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 { useMediaQuery } from "react-responsive";
import { useNavigate } from "react-router-dom";

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

const isMobile = useMediaQuery({ query: "(max-width: 710px)" });
const [learned, setLearned] = useState<LearnedProps[]>([]);
const sliceLearned = learned.slice(0, 3);
const sliceLearned = learned.slice(0, isMobile ? 2 : 3);

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

const handleMoreClick = () => {
navigate("/learnTale/moreLearned", { state: { learned } });
};

return (
<>
<CommonTitleWrapper>
Expand All @@ -39,11 +41,11 @@ const Learned = () => {
{sliceLearned.map((learned: LearnedProps) => (
<Card
taleId={learned.tale_id}
title={learned.languageTale.title}
title={`${learned.koreanTitle} (${learned.languageId === 1 ? "영어" : learned.languageId === 2 ? "한국어" : learned.languageId === 3 ? "일본어" : "중국어"})`}
createdAt={learned.createdAt}
point={"4/10"}
languageTaleId={learned.languageTale.id}
firstQuizCount={learned.firstQuizCount}
btnText="복습하기"
// readFunction={() => handleMoreClick()}
/>
))}
</ItemWrapper>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import Card from "@components/common/card/Card";
import {
ItemWrapper,
MainWrapper,
Shelf,
} from "@components/common/common.styled";
import Header from "@components/common/header/Header";
import Card from "@components/home/homeRecentTales/Card";
import { LearnedProps } from "@type/card";
import { useMediaQuery } from "react-responsive";
import { useLocation } from "react-router-dom";
Expand All @@ -30,11 +30,11 @@ const LearnedMore = () => {
<>
<Card
taleId={learned.tale_id}
title={learned.languageTale.title}
languageTaleId={learned.languageTale.id}
title={`${learned.koreanTitle} (${learned.languageId === 1 ? "영어" : learned.languageId === 2 ? "한국어" : learned.languageId === 3 ? "일본어" : "중국어"})`}
createdAt={learned.createdAt}
point={"4/10"}
firstQuizCount={learned.firstQuizCount}
btnText="복습하기"
// readFunction={() => goRead(tale)}
/>
{(index + 1) % 2 === 0 &&
index !== learnedSlice.length - 1 && (
Expand All @@ -50,11 +50,11 @@ const LearnedMore = () => {
{learnedGroup.map((learned: LearnedProps) => (
<Card
taleId={learned.tale_id}
title={learned.languageTale.title}
languageTaleId={learned.languageTale.id}
title={`${learned.koreanTitle} (${learned.languageId === 1 ? "영어" : learned.languageId === 2 ? "한국어" : learned.languageId === 3 ? "일본어" : "중국어"})`}
createdAt={learned.createdAt}
point={"4/10"}
firstQuizCount={learned.firstQuizCount}
btnText="복습하기"
// readFunction={() => goRead(learned)}
/>
))}
</ItemWrapper>
Expand Down
Loading