-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
246 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,41 @@ | ||
import LocalStorage from "@utils/localStorage"; | ||
import { getAuthAxios } from "./authAxois"; | ||
import { CreateTaleData } from "@type/createTale"; | ||
// import { Server } from "./settings"; | ||
|
||
const baseURL = import.meta.env.VITE_PUBLIC_SERVER_URL; | ||
|
||
export const createWithImg = async (body: FormData): Promise<string[]> => { | ||
export const createKeyword = async (body: FormData): Promise<string[]> => { | ||
try { | ||
const access = LocalStorage.getItem('access'); | ||
const access = LocalStorage.getItem("access"); | ||
const authAxios = getAuthAxios(access); | ||
const response = await authAxios.post(`${baseURL}/tales/keyword`, body, { | ||
headers: { | ||
"Content-Type": "multipart/form-data", | ||
}, | ||
}); | ||
console.log(response.data); | ||
|
||
// response에서 keyword만 추출하여 배열에 담아 return | ||
const keywords: string[] = response.data.result.map( | ||
(item: { keyword: string }) => item.keyword | ||
); | ||
|
||
return keywords; | ||
} catch (error) { | ||
alert( | ||
"이미지 화질이 안좋거나, 추출된 키워드가 없습니다. 다시 이미지를 업로드하세요!" | ||
); | ||
throw error; | ||
} | ||
}; | ||
|
||
export const createTale = async (body: CreateTaleData) => { | ||
try { | ||
const access = LocalStorage.getItem("access"); | ||
const authAxios = getAuthAxios(access); | ||
const response = await authAxios.post(`${baseURL}/tales/`, body); | ||
return response.data; | ||
} catch (error) { | ||
alert("동화 생성 중 문제가 발생했습니다. 잠시 후 다시 시도해주세요."); | ||
throw error; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import styled from "styled-components"; | ||
|
||
export const Wrapper = styled.div` | ||
width: 95%; | ||
height: 90%; | ||
overflow-y: hidden; | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: space-between; | ||
`; | ||
|
||
export const ReadTaleHead = styled.div` | ||
width: 100%; | ||
display: flex; | ||
justify-content: space-between; | ||
padding: 2.8rem 0; | ||
`; | ||
|
||
export const TitleWrapper = styled.div` | ||
display: flex; | ||
flex-direction: column; | ||
gap: 1rem; | ||
`; | ||
|
||
export const Title = styled.div` | ||
font-size: 2.5rem; | ||
font-weight: 800; | ||
`; | ||
|
||
export const Complete = styled.div` | ||
font-size: 1.7rem; | ||
font-weight: 500; | ||
color: #f7a300; | ||
`; | ||
|
||
export const TaleWrapper = styled.div` | ||
width: 100%; | ||
height: 75%; | ||
max-height: 75%; | ||
overflow-y: scroll; | ||
font-size: 1.8rem; | ||
margin-bottom: 1rem; | ||
`; | ||
|
||
export const BtnWrapper = styled.div` | ||
width: 100%; | ||
display: flex; | ||
justify-content: space-between; | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import Header from "@components/common/header/Header"; | ||
import * as S from "./ReadTale.styled"; | ||
import Dropdown from "@components/common/dropDown/Dropdown"; | ||
import { nationElements } from "@pages/OnboardingPage"; | ||
import { useEffect, useState } from "react"; | ||
import NextBtn from "@components/common/NextBtn"; | ||
import LoadingScreen from "@components/common/spinner/LoadingScreen"; | ||
import { createTale } from "@apis/createTales"; | ||
import { useLocation } from "react-router-dom"; | ||
|
||
const ReadTale = () => { | ||
const location = useLocation(); | ||
const { requestData } = location.state || {}; | ||
|
||
const [result, setResult] = useState<string | number | null>(null); | ||
const [data, setData] = useState(null); | ||
|
||
const onClick = () => { | ||
console.log(result); | ||
}; | ||
|
||
useEffect(() => { | ||
const getTale = async () => { | ||
if (requestData) { | ||
const response = await createTale(requestData); | ||
setData(response); | ||
console.log(response); | ||
} | ||
}; | ||
getTale(); | ||
}, []); | ||
|
||
return ( | ||
<> | ||
<Header text="동화 읽기" /> | ||
<S.Wrapper> | ||
{data ? ( | ||
<> | ||
<S.ReadTaleHead> | ||
<S.TitleWrapper> | ||
<S.Complete>동화가 완성되었어요!</S.Complete> | ||
<S.Title>제목: 사과나무와 작은 동물들</S.Title> | ||
</S.TitleWrapper> | ||
<Dropdown | ||
selectList={nationElements} | ||
setter={setResult} | ||
width="30%" | ||
/> | ||
</S.ReadTaleHead> | ||
<S.TaleWrapper></S.TaleWrapper> | ||
<S.BtnWrapper> | ||
<NextBtn | ||
width="48%" | ||
isActive={true} | ||
text="음성으로 듣기" | ||
handleBtn={onClick} | ||
/> | ||
<NextBtn | ||
width="48%" | ||
isActive={true} | ||
text="학습하기" | ||
handleBtn={onClick} | ||
/> | ||
</S.BtnWrapper> | ||
</> | ||
) : ( | ||
<LoadingScreen text="동화" /> | ||
)} | ||
</S.Wrapper> | ||
</> | ||
); | ||
}; | ||
|
||
export default ReadTale; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.