Skip to content

Commit bb8fc06

Browse files
committed
Merge remote-tracking branch 'origin/dev' into feat/404#118
2 parents dccaee5 + 33fa2ed commit bb8fc06

File tree

7 files changed

+40
-24
lines changed

7 files changed

+40
-24
lines changed

src/domains/recommend/components/ChatList.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function ChatList({ messages, userCurrentStep, onSelectedOption }: ChatListProps
2020
<div
2121
ref={chatListRef}
2222
onScroll={handleCheckBottom}
23-
className="absolute top-0 left-0 bottom-18 sm:bottom-21 w-full gap-5 px-3 pt-12 pb-4 flex flex-col items-center overflow-y-auto pr-2"
23+
className="absolute top-8 left-0 bottom-18 sm:bottom-21 w-full gap-5 px-3 pt-7 pb-4 flex flex-col items-center overflow-y-auto pr-2"
2424
>
2525
<div className="max-w-1024 w-full flex flex-col gap-5">
2626
{messages.map((msg, i) => {

src/domains/recommend/components/ChatSection.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ import MessageInput from './user/MessageInput';
55
import { fetchSendStepMessage, fetchSendTextMessage } from '../api/chat';
66
import { ChatMessage, stepPayload } from '../types/recommend';
77
import ChatList from './ChatList';
8-
import { useChatInit } from '../hook/useChatInit';
98
import { useSelectedOptions } from '../hook/useSelectedOptions';
109
import { useAuthStore } from '@/domains/shared/store/auth';
10+
import { useChatInit } from '../hook/useChatInit';
11+
import { useChatWarning } from '../hook/useChatWarning';
1112

1213
function ChatSection() {
1314
const [messages, setMessages] = useState<ChatMessage[]>([]);
@@ -121,10 +122,14 @@ function ChatSection() {
121122
};
122123

123124
useChatInit(setMessages);
125+
useChatWarning(messages);
124126

125127
return (
126128
<section className="relative flex-1 flex flex-col items-center w-full">
127129
<h2 className="sr-only">대화 목록 및 입력 창</h2>
130+
<div className="p-2 text-white/80 text-sm text-center">
131+
⚠️ 페이지를 벗어나면 채팅내용이 사라집니다.
132+
</div>
128133
<ChatList
129134
messages={messages}
130135
userCurrentStep={userCurrentStep}

src/domains/recommend/components/bot/BotCocktailCard.tsx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@ import Link from 'next/link';
33
import Keep from '@/domains/shared/components/keep/Keep';
44
import { RecommendationItem } from '../../types/recommend';
55

6-
function BotCocktailCard({
7-
cocktailId,
8-
cocktailName,
9-
cocktailNameKo,
10-
cocktailImgUrl,
11-
alcoholStrength,
12-
}: RecommendationItem) {
6+
function BotCocktailCard({ cocktailId, cocktailNameKo, cocktailImgUrl }: RecommendationItem) {
137
return (
148
<div className="relative flex flex-col w-full min-w-[200px] rounded-2xl overflow-hidden bg-white shadow-[0_0_12px_rgba(255,255,255,0.4)]">
15-
<Link href="/" className="block relative">
9+
<Link
10+
href={`/recipe/${cocktailId}`}
11+
target="_blank"
12+
rel="noopener noreferrer"
13+
className="block relative"
14+
>
1615
<div className="relative w-full h-[200px]">
1716
<Image
1817
src={cocktailImgUrl}

src/domains/recommend/components/user/MessageInput.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function MessageInput({ onSubmit, disabled }: Props) {
3636
id="chatInput"
3737
name="chatInput"
3838
onInput={(e) => resizeTextarea(e.currentTarget)}
39-
placeholder={disabled ? '옵션을 선택해주세요.' : '칵테일 추천 질문을 입력해주세요.'}
39+
placeholder={disabled ? '옵션 선택' : '칵테일 추천 질문 입력'}
4040
disabled={disabled}
4141
className={`
4242
w-[calc(100%-3rem)] md:w-[calc(100%-3.75rem)] px-4 py-2 md:py-3.5

src/domains/recommend/hook/useChatInit.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,18 @@
22

33
import { useEffect } from 'react';
44
import { ChatMessage } from '../types/recommend';
5-
import { fetchChatHistory, fetchGreeting } from '../api/chat';
5+
import { fetchGreeting } from '../api/chat';
66

7-
// 채팅 기록 불러오기 없으면 greeting api 호출
87
export function useChatInit(setMessages: React.Dispatch<React.SetStateAction<ChatMessage[]>>) {
98
useEffect(() => {
10-
const loadChatHistory = async () => {
9+
const loadGreeting = async () => {
1110
try {
12-
const history = await fetchChatHistory();
13-
if (history && history.length > 0) {
14-
setMessages(history.sort((a, b) => Number(a.id) - Number(b.id)));
15-
} else {
16-
const greeting = await fetchGreeting('');
17-
if (greeting) setMessages([greeting]);
18-
}
11+
const greeting = await fetchGreeting('');
12+
if (greeting) setMessages([greeting]);
1913
} catch (err) {
2014
console.error('채팅 초기화 실패:', err);
2115
}
2216
};
23-
loadChatHistory();
17+
loadGreeting();
2418
}, [setMessages]);
2519
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'use client';
2+
3+
import { useEffect } from 'react';
4+
import { ChatMessage } from '../types/recommend';
5+
6+
export function useChatWarning(messages: ChatMessage[]) {
7+
useEffect(() => {
8+
const handleBeforeUnload = (e: BeforeUnloadEvent) => {
9+
if (messages.length > 0) {
10+
e.preventDefault();
11+
e.returnValue = '';
12+
}
13+
};
14+
15+
window.addEventListener('beforeunload', handleBeforeUnload);
16+
return () => window.removeEventListener('beforeunload', handleBeforeUnload);
17+
}, [messages]);
18+
}

src/domains/recommend/types/recommend.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ export interface StepOption {
66

77
export interface RecommendationItem {
88
cocktailId: number;
9-
cocktailName: string;
9+
cocktailName?: string;
1010
cocktailNameKo: string;
1111
cocktailImgUrl: string;
12-
alcoholStrength: string;
12+
alcoholStrength?: string;
1313
}
1414

1515
export interface StepRecommendation {

0 commit comments

Comments
 (0)