-
Notifications
You must be signed in to change notification settings - Fork 3
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
1 parent
52d29aa
commit 0ad31ba
Showing
9 changed files
with
237 additions
and
35 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
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 @@ | ||
export { DetailPage } from './ui/DetailPage'; |
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,58 @@ | ||
import styled from 'styled-components'; | ||
|
||
export const Container = styled.div` | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
`; | ||
|
||
export const ContentContainer = styled.div` | ||
background-color: rgb(0, 0, 0, 0.3); | ||
height: 400px; | ||
width: 100% | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
`; | ||
|
||
export const Wrap = styled.div` | ||
width: 100%; | ||
max-width: 960px; | ||
display: flex; | ||
// flex-direction: column; // 모바일 버전일 때 | ||
align-items: stretch; | ||
gap: 10px; | ||
`; | ||
|
||
export const MusicContainer = styled.div` | ||
flex: 1; | ||
`; | ||
|
||
export const EmotionMoodWrap = styled.div` | ||
flex: 1; | ||
display: flex; | ||
flex-direction: column; | ||
gap: 10px; | ||
`; | ||
|
||
export const MoodContainer = styled.div` | ||
flex: 1; | ||
width: 100%; | ||
`; | ||
|
||
export const EmotionWrap = styled.div` | ||
flex: 1; | ||
width: 100%; | ||
display: flex; | ||
gap: 10px; | ||
`; | ||
|
||
export const MainEmotionContainer = styled.div` | ||
flex: 1.2; | ||
`; | ||
export const SubEmotionContainer = styled.div` | ||
flex: 2; | ||
`; |
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,126 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import { useParams } from 'react-router-dom'; | ||
import { | ||
Container, | ||
ContentContainer, | ||
Wrap, | ||
EmotionMoodWrap, | ||
EmotionWrap, | ||
MusicContainer, | ||
MoodContainer, | ||
MainEmotionContainer, | ||
SubEmotionContainer | ||
} from './DetailPage.styled'; | ||
import { ShowMusicContainer } from '@/widgets/show-music'; | ||
import { ShowMoodContainer } from '@/widgets/show-mood'; | ||
import { ShowMainEmotionContainer } from '@/widgets/show-main-emotion'; | ||
import { ShowSubEmotionContainer } from '@/widgets/show-sub-emotion'; | ||
|
||
import { emotionMapping, Emotions } from '@/shared/model/EmotionEnum'; | ||
import { ConditionType } from '@/shared/model/conditionTypes'; | ||
|
||
interface DiaryData { | ||
title: string; | ||
content: string; | ||
is_public: boolean; | ||
title_date: Date; | ||
updated_date: Date; | ||
author_email: string; | ||
// author_username: string; | ||
|
||
mood: ConditionType; | ||
emotion: string; | ||
sub_emotion: string; | ||
music_url: string; | ||
music_imgurl: string; | ||
music_title: string; | ||
artist: string; | ||
|
||
reactions: string; | ||
} | ||
|
||
export const DetailPage = () => { | ||
const { id } = useParams(); | ||
const [data, setData] = useState<DiaryData | null>(null); | ||
|
||
useEffect(() => { | ||
const fetchData = async () => { | ||
try { | ||
const response = await fetch( | ||
`https://td3axvf8x7.execute-api.ap-northeast-2.amazonaws.com/moodi/diary/${id}` | ||
); | ||
const result: DiaryData = await response.json(); | ||
setData(result); | ||
} catch (error) { | ||
console.error('Error:', error); | ||
} | ||
}; | ||
|
||
fetchData(); | ||
}, [id]); | ||
|
||
if (!data) { | ||
return <div>Loading...</div>; // 데이터 로딩 중 표시 | ||
} | ||
|
||
// 구조 분해로 변수 할당 | ||
const { | ||
title, | ||
content, | ||
is_public: isPublic, | ||
|
||
mood, | ||
emotion, | ||
sub_emotion: subEmotion, | ||
title_date: titleDate, | ||
updated_date: updatedDate, | ||
|
||
music_url: youtubeId, | ||
music_imgurl: albumCover, | ||
music_title: songTitle, | ||
artist: artistName | ||
} = data; | ||
|
||
// 서브 감정을 매핑 | ||
const transSubEmotion = JSON.parse(subEmotion).map( | ||
(emo: string) => emotionMapping[emo] ?? emo | ||
); | ||
|
||
return ( | ||
<Container> | ||
<ContentContainer>{content}</ContentContainer> | ||
|
||
<Wrap> | ||
<EmotionMoodWrap> | ||
<MoodContainer> | ||
<ShowMoodContainer mood={mood} /> | ||
</MoodContainer> | ||
<EmotionWrap> | ||
<MainEmotionContainer> | ||
<ShowMainEmotionContainer | ||
emotion={emotionMapping[emotion]} | ||
/> | ||
</MainEmotionContainer> | ||
<SubEmotionContainer> | ||
<ShowSubEmotionContainer | ||
subEmotions={transSubEmotion} | ||
/> | ||
</SubEmotionContainer> | ||
</EmotionWrap> | ||
</EmotionMoodWrap> | ||
<MusicContainer> | ||
<ShowMusicContainer | ||
youtubeId={youtubeId} | ||
thumbnailUrl={albumCover} | ||
title={songTitle} | ||
artist={artistName} | ||
/> | ||
</MusicContainer> | ||
</Wrap> | ||
|
||
{/* <ReactionContainer></ReactionContainer> */} | ||
|
||
{/* <ButtonContainer></ButtonContainer> */} | ||
</Container> | ||
); | ||
}; |
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