Skip to content

Commit d5c824b

Browse files
committed
feat: add close button to ChatPage for navigation
1 parent bb9f134 commit d5c824b

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

frontend/src/common/components/Chat/ChatContainer.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React, { useEffect, useRef } from 'react';
2-
import { useTranslation } from 'react-i18next';
32
import { IconDefinition } from '@fortawesome/fontawesome-svg-core';
43
import ChatMessage, { ChatMessageData } from './ChatMessage';
54
import './ChatContainer.scss';
@@ -23,7 +22,6 @@ const ChatContainer: React.FC<ChatContainerProps> = ({
2322
testid = 'chat-container',
2423
className = '',
2524
}) => {
26-
const { t } = useTranslation();
2725
const chatContainerRef = useRef<HTMLDivElement>(null);
2826

2927
// Auto-scroll to bottom when new messages arrive
@@ -41,11 +39,7 @@ const ChatContainer: React.FC<ChatContainerProps> = ({
4139
aria-label="Chat messages"
4240
data-testid={testid}
4341
>
44-
{messages.length === 0 ? (
45-
<div className="chat-empty-state" data-testid={`${testid}-empty`}>
46-
<p>{t('aiAssistant.emptyState', 'How can I help you today?')}</p>
47-
</div>
48-
) : (
42+
{messages.length > 0 &&
4943
messages.map((message) => (
5044
<ChatMessage
5145
key={message.id}
@@ -54,8 +48,7 @@ const ChatContainer: React.FC<ChatContainerProps> = ({
5448
robotIcon={robotIcon}
5549
testid={`${testid}-message`}
5650
/>
57-
))
58-
)}
51+
))}
5952
</div>
6053
);
6154
};

frontend/src/pages/Chat/ChatPage.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { IonContent, IonHeader, IonPage, IonTitle, IonToolbar } from '@ionic/rea
22
import { useTranslation } from 'react-i18next';
33
import { useState, useEffect, useRef } from 'react';
44
import { useLocation } from 'react-router-dom';
5+
import { useHistory } from 'react-router';
6+
import closeIcon from 'assets/icons/close.svg';
57
import ChatContainer from '../../common/components/Chat/ChatContainer';
68
import ChatInput from '../../common/components/Chat/ChatInput';
79
import { chatService } from '../../common/services/ChatService';
@@ -19,11 +21,17 @@ const ChatPage = (): JSX.Element => {
1921
const [messages, setMessages] = useState<ChatMessageData[]>([]);
2022
const location = useLocation();
2123
const prevPathRef = useRef(location.pathname);
24+
const history = useHistory();
2225

2326
const resetChatState = () => {
2427
setMessages([]);
2528
};
2629

30+
// Handle close button
31+
const handleClose = () => {
32+
history.push('/tabs/home');
33+
};
34+
2735
// Handle initial setup and cleanup
2836
useEffect(() => {
2937
// Create a new session when the component mounts using an IIFE
@@ -92,6 +100,14 @@ const ChatPage = (): JSX.Element => {
92100
<span>{t('pages.chat.title', 'AI Assistant')}</span>
93101
</div>
94102
</IonTitle>
103+
<div slot="end">
104+
<button
105+
onClick={handleClose}
106+
style={{ backgroundColor: 'transparent', marginRight: '2em' }}
107+
>
108+
<img src={closeIcon} alt="Close" />
109+
</button>
110+
</div>
95111
</IonToolbar>
96112
</IonHeader>
97113
<IonContent className="chat-page-content">

0 commit comments

Comments
 (0)