-
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.
Merge pull request #54 from Soongmile/feat/#35_questionRead
[#35] 게시물 조회 기능 API 연결
- Loading branch information
Showing
20 changed files
with
344 additions
and
101 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { GetQuestionResponse } from '@/types/question.type'; | ||
import client from './client'; | ||
|
||
const getQuestion = async (id: number): Promise<GetQuestionResponse> => { | ||
const response = await client.get(`/user/question/${id}`); | ||
return response.data; | ||
}; | ||
|
||
export default getQuestion; |
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,26 @@ | ||
import { AnswerWriteRequest, PostAnswerWriteResponse } from '@/types/answer.type'; | ||
import client from './client'; | ||
|
||
const postAnswer = async ({ | ||
questionId, | ||
fileIds, | ||
content, | ||
}: AnswerWriteRequest): Promise<PostAnswerWriteResponse> => { | ||
const response = await client.post( | ||
'/user/answer', | ||
{ | ||
questionId, | ||
fileIds, | ||
content, | ||
}, | ||
{ | ||
headers: { | ||
Authorization: | ||
'eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJha211QGdtYWlsLmNvbSIsInJvbGVzIjpbXSwiaWF0IjoxNjk1OTgyNTI1LCJleHAiOjE2OTYwNjg5MjV9.N5UWZD4xvULjHk7EaKblTM7kJwEdZrQ3cfII1jZMuAE', | ||
}, | ||
}, | ||
); | ||
return response.data; | ||
}; | ||
|
||
export default postAnswer; |
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,8 +1,12 @@ | ||
import '@toast-ui/editor/dist/toastui-editor.css'; | ||
import { Viewer } from '@toast-ui/react-editor'; | ||
|
||
const MarkdownViewer = () => { | ||
return <Viewer initialValue="#hello react editor world!" el="dkdkd" />; | ||
interface MarkdownViewerProps { | ||
content?: string; | ||
} | ||
|
||
const MarkdownViewer = ({ content }: MarkdownViewerProps) => { | ||
return <Viewer initialValue={content} />; | ||
}; | ||
|
||
export default MarkdownViewer; |
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,9 @@ | ||
import getQuestion from '@/apis/getQuestion'; | ||
import { GetQuestionResponse } from '@/types/question.type'; | ||
import { useQuery } from 'react-query'; | ||
|
||
const useGetQuestionRead = (id: number) => { | ||
return useQuery<GetQuestionResponse>(['getQuestion', id], () => getQuestion(id)); | ||
}; | ||
|
||
export default useGetQuestionRead; |
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,22 @@ | ||
import postAnswer from '@/apis/postAnswer'; | ||
import { queryClient } from '@/pages/_app'; | ||
import { AxiosError } from 'axios'; | ||
import { useRouter } from 'next/router'; | ||
import { useMutation } from 'react-query'; | ||
|
||
const usePostAnswer = (pId: number) => { | ||
const router = useRouter(); | ||
return useMutation(postAnswer, { | ||
onSuccess: () => { | ||
queryClient.invalidateQueries(['getQuestion']); | ||
router.push(`/questionRead/${pId}`); | ||
}, | ||
onError: (error) => { | ||
const Error = error as AxiosError; | ||
|
||
console.log(Error); | ||
}, | ||
}); | ||
}; | ||
|
||
export default usePostAnswer; |
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
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
Oops, something went wrong.