Skip to content

Commit decf559

Browse files
authored
Merge pull request #93 from Nexters/feat#92
Feat#92
2 parents e3afdb5 + 7a9e572 commit decf559

File tree

4 files changed

+40
-28
lines changed

4 files changed

+40
-28
lines changed

src/tarot/apis/getTarotFollowQuestion.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,13 @@ const validate = (data: serverResponse): TarotFollowQuestion => {
1616
return validatedData;
1717
};
1818

19-
export const getTarotFollowQuestion = (chatRoomId: number): Promise<TarotFollowQuestion> => {
19+
export const getTarotFollowQuestion = (
20+
chatRoomId: number,
21+
resultId: number
22+
): Promise<TarotFollowQuestion> => {
2023
return apiClient
2124
.get<serverResponse>(
22-
`${process.env.NEXT_PUBLIC_API_BASE_URL}/api/v1/tarot/question/follow?chatRoomId=${chatRoomId}`
25+
`${process.env.NEXT_PUBLIC_API_BASE_URL}/api/v1/tarot/question/follow?chatRoomId=${chatRoomId}&tarotResultId=${resultId}`
2326
)
2427
.then((res) => validate(res.data))
2528
.catch((error) => {

src/tarot/components/NextRecommendQuestion.tsx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import styled from "styled-components";
33
import { useTarotFollowQuestion } from "../hooks/useTarotFollowQuestion";
44
import { useParams } from "next/navigation";
55
interface NextRecommendQuestionProps {
6-
handleRecommendQuestionChat: (id: number, question: string) => void;
6+
handleRecommendQuestionChat: (question: string) => void;
77
}
88

9-
const NextRecommendQuestion = ({}: NextRecommendQuestionProps) => {
10-
const { chatId } = useParams<{ chatId: string }>();
9+
const NextRecommendQuestion = ({ handleRecommendQuestionChat }: NextRecommendQuestionProps) => {
10+
const { chatId, resultId } = useParams<{ chatId: string; resultId: string }>();
1111

12-
const { data: NextQuestion } = useTarotFollowQuestion(Number(chatId));
12+
const { data: NextQuestion } = useTarotFollowQuestion(Number(chatId), Number(resultId));
1313

1414
console.log(NextQuestion);
1515
return (
@@ -20,10 +20,7 @@ const NextRecommendQuestion = ({}: NextRecommendQuestionProps) => {
2020
</div>
2121
<RecommendContainer>
2222
{NextQuestion?.questions.map((item, idx) => (
23-
<RecommendQuestionBtn
24-
key={idx}
25-
// onClick={() => handleRecommendQuestionChat(item.recommendQuestionId, item.question)}
26-
>
23+
<RecommendQuestionBtn key={idx} onClick={() => handleRecommendQuestionChat(item)}>
2724
<QuestionTitle>{item} </QuestionTitle>
2825

2926
<NextQuestionAffordance>이 질문하기 &gt;</NextQuestionAffordance>

src/tarot/components/TarotResultAfterView.tsx

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import LinkIcon from "@/shared/assets/icons/link.svg";
66
import ColorStar from "@/shared/assets/icons/tarot-card-result-color-star.svg";
77
import Star from "@/shared/assets/icons/tarot-card-result-star.svg";
88
import CatWithCard from "@/shared/assets/images/cardWithCat.png";
9-
9+
import NextRecommendQuestion from "./NextRecommendQuestion";
1010
import Button from "@/shared/components/Button";
1111
import Toast from "@/shared/components/Toast";
1212
import { checkBrowserForWebShare } from "@/shared/utils/checkBrowserForWebShare";
@@ -16,7 +16,8 @@ import findCardById from "@/tarot/utils/findCardById";
1616
import { useQueryClient } from "@tanstack/react-query";
1717
import { useParams, useRouter } from "next/navigation";
1818
import { useState } from "react";
19-
// import NextRecommendQuestion from "./NextRecommendQuestion";
19+
import { SendChatMessageRequest } from "@/chat/apis/sendChatMessage";
20+
import { usePathname } from "next/navigation";
2021

2122
const TarotResultAfterView = () => {
2223
const { resultId, chatId } = useParams<{
@@ -25,7 +26,9 @@ const TarotResultAfterView = () => {
2526
}>();
2627

2728
const [toastOpen, setToastOpen] = useState(false);
28-
const shareURL = process.env.NEXT_PUBLIC_BASE_URL || "https://tarotnyang.me";
29+
const pathname = usePathname();
30+
console.log(pathname);
31+
const shareURL = process.env.NEXT_PUBLIC_BASE_URL + pathname || "https://tarotnyang.me";
2932
const { handleWebShare, handleCopyToClipboard } = shareLink(shareURL);
3033
const router = useRouter();
3134
const { data, isError } = useTarotReadingResult(Number(resultId));
@@ -43,17 +46,16 @@ const TarotResultAfterView = () => {
4346
router.push(`/chats/${chatId}`);
4447
};
4548

46-
// const handleRecommendQuestionChat = (recommendQuestionId: number, message: string) => {
47-
// const object: SendChatMessageRequest = {
48-
// roomId: Number(chatId),
49-
// referenceQuestionId: recommendQuestionId,
50-
// intent: "RECOMMEND_QUESTION",
51-
// message: message,
52-
// };
49+
const handleRecommendQuestionChat = (message: string) => {
50+
const object: SendChatMessageRequest = {
51+
roomId: Number(chatId),
52+
intent: "NORMAL",
53+
message: message,
54+
};
5355

54-
// queryClient.invalidateQueries({ queryKey: ["chatMessages"] });
55-
// router.push(`/chats/${chatId}?message=${JSON.stringify(object)}`);
56-
// };
56+
queryClient.invalidateQueries({ queryKey: ["chatMessages"] });
57+
router.push(`/chats/${chatId}?message=${JSON.stringify(object)}`);
58+
};
5759

5860
const handleNewChat = () => {
5961
router.push("/");
@@ -186,14 +188,14 @@ const TarotResultAfterView = () => {
186188
</Button>
187189
)}
188190
</NextQuestionFlow>
189-
{/* {/<Divider /> */}
191+
<Divider />
190192

191-
{/* {data?.isOwner ? (
193+
{data?.isOwner ? (
192194
<>
193195
<NextRecommendQuestion handleRecommendQuestionChat={handleRecommendQuestionChat} />
194196
<Divider />
195197
</>
196-
) : null} */}
198+
) : null}
197199

198200
<PopularQuestions />
199201
</TarotResultWrapper>
@@ -367,6 +369,16 @@ const TarotResultWrapper = styled.div`
367369
margin-inline: auto;
368370
background-color: white;
369371
`;
372+
373+
const Divider = styled.div`
374+
height: 11px;
375+
width: calc(100% + 44px * 2);
376+
377+
margin: 44px 0 44px 0;
378+
background-color: ${({ theme }) => theme.colors.grey10};
379+
380+
overflow: hidden;
381+
`;
370382
// const DownloadInfoWrapper = styled.div`
371383
// display: flex;
372384
// flex-direction: column;
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { useQuery } from "@tanstack/react-query";
22
import { getTarotFollowQuestion } from "../apis/getTarotFollowQuestion";
33

4-
export const useTarotFollowQuestion = (chatId: number) => {
4+
export const useTarotFollowQuestion = (chatId: number, resultId: number) => {
55
return useQuery({
66
queryKey: ["getTarotFollowQuestion"],
7-
queryFn: () => getTarotFollowQuestion(chatId),
7+
queryFn: () => getTarotFollowQuestion(chatId, resultId),
88
});
99
};

0 commit comments

Comments
 (0)