-
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
12 changed files
with
150 additions
and
77 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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from "./ui/question-detail-body"; | ||
export * from "./ui/question-detail-profile"; | ||
export * from "./ui/question-detail-title"; |
14 changes: 14 additions & 0 deletions
14
src/entities/question-detail-page/model/question-detail-key.ts
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,14 @@ | ||
import { ENV } from "~/shared/environment"; | ||
|
||
export const DETAIL_ENDPOINT = { | ||
default: `${ENV.baseUrl}/api/question/detail`, | ||
finalDetail: (id: string) => { | ||
return `${DETAIL_ENDPOINT.default}/${id}`; | ||
}, | ||
}; | ||
export const DETAIL_KEY = { | ||
default: [`detail`], | ||
finalDetail: (id: string) => { | ||
return [...DETAIL_KEY.default, id]; | ||
}, | ||
}; |
18 changes: 0 additions & 18 deletions
18
src/entities/question-detail-page/model/question-detail-type.ts
This file was deleted.
Oops, something went wrong.
25 changes: 25 additions & 0 deletions
25
src/entities/question-detail-page/model/question-detail.type.ts
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,25 @@ | ||
export interface QuestionDetailType { | ||
id: number; | ||
title: string; | ||
githubUrl: string; | ||
content: string; | ||
code: string; | ||
purpose: string; | ||
likeCount: number; | ||
viewCount: number; | ||
createdAt: string; | ||
categories: Category[]; | ||
comments: Comment[]; | ||
} | ||
export interface Category { | ||
id: number; | ||
name: string; | ||
count: number; | ||
} | ||
|
||
export interface Comment { | ||
id: number; | ||
content: string; | ||
createdAt: string; | ||
likeCount: number; | ||
} |
18 changes: 18 additions & 0 deletions
18
src/entities/question-detail-page/model/use-detail-query.ts
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,18 @@ | ||
import { UseQueryResult, useQuery } from "@tanstack/react-query"; | ||
|
||
import { DETAIL_ENDPOINT, DETAIL_KEY } from "./question-detail-key"; | ||
import { QuestionDetailType } from "./question-detail.type"; | ||
|
||
export const useDetailQuery = (id: string): UseQueryResult<QuestionDetailType> => { | ||
const Detail = useQuery<QuestionDetailType>({ | ||
queryKey: DETAIL_KEY.finalDetail(id), | ||
queryFn: async () => { | ||
const response = await fetch(DETAIL_ENDPOINT.finalDetail(id)); | ||
if (!response.ok) { | ||
throw new Error("Failed to fetch question detail"); | ||
} | ||
return await response.json(); | ||
}, | ||
}); | ||
return Detail; | ||
}; |
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
2 changes: 1 addition & 1 deletion
2
src/entities/question-detail-page/ui/question-detail-profile.tsx
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 |
---|---|---|
@@ -1,29 +1,73 @@ | ||
import { useParams } from "react-router-dom"; | ||
import styled from "styled-components"; | ||
|
||
import { CommentByQuestionAnswer } from "~/entities/comment"; | ||
import { useDetailQuery } from "~/entities/question-detail-page/model/use-detail-query"; | ||
import { QuestionDetailBody } from "~/entities/question-detail-page/ui/question-detail-body"; | ||
import { QuestionDetailPfofile } from "~/entities/question-detail-page/ui/question-detail-profile"; | ||
import { QuestionDetailTitle } from "~/entities/question-detail-page/ui/question-detail-title"; | ||
import { QuestionHeader } from "~/entities/question-header"; | ||
|
||
// 스타일 | ||
const QuestionDetailContainer = styled.div` | ||
color: #000; | ||
line-height: 1.2em; | ||
border-radius: 15px; | ||
background-color: #fff; | ||
`; | ||
const QuestionTextContainer = styled.div` | ||
padding: 25px 20px; | ||
`; | ||
const QuestionBox = styled.div` | ||
width: 768px; | ||
margin-left: auto; | ||
margin-right: auto; | ||
box-sizing: border-box; | ||
padding: 20px; | ||
background: rgb(42, 39, 49); | ||
background: linear-gradient(60deg, rgba(42, 39, 49, 1) 0%, rgba(137, 128, 155, 1) 35%, rgba(42, 39, 49, 1) 100%); | ||
border-radius: 28px; | ||
`; | ||
|
||
export const QuestionDetailPage = () => { | ||
const { id } = useParams(); | ||
|
||
const { isError, isLoading, data } = useDetailQuery(id as string); | ||
console.log(data); | ||
|
||
if (isError) { | ||
alert("Error from 하늘"); | ||
} | ||
if (isLoading) { | ||
return <div>Loading...</div>; | ||
} | ||
|
||
// Title영역 | ||
const title = data?.title || ""; | ||
const categories = data?.categories.map((category) => category.name) || []; | ||
const githubUrl = data?.githubUrl || ""; | ||
// Body 영역 | ||
const { content = "", purpose = "", code = "" } = data || {}; | ||
const questionDetailBodyProps = { | ||
content, | ||
purpose, | ||
code, | ||
}; | ||
return ( | ||
<> | ||
<QuestionDetailContainer> | ||
<QuestionDetailPfofile /> | ||
<QuestionTextContainer> | ||
<QuestionDetailTitle /> | ||
<QuestionDetailBody /> | ||
</QuestionTextContainer> | ||
</QuestionDetailContainer> | ||
<QuestionBox> | ||
<QuestionDetailContainer> | ||
<QuestionHeader | ||
viewCount={data?.viewCount as number} | ||
likeCount={data?.likeCount as number} | ||
comments={data?.comments.length as number} | ||
/> | ||
<QuestionTextContainer> | ||
<QuestionDetailTitle title={title} categories={categories} githubUrl={githubUrl} /> | ||
<QuestionDetailBody {...questionDetailBodyProps} /> | ||
</QuestionTextContainer> | ||
</QuestionDetailContainer> | ||
<CommentByQuestionAnswer /> | ||
</QuestionBox> | ||
</> | ||
); | ||
}; |
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