feat: improve chat room UI and scrolling behavior
- Added automatic scrolling to bottom of messages in chat room - Updated CSS to handle app and chat container height more precisely - Implemented scrollToBottom function for messages container - Ensured messages scroll automatically on new message or send - Removed unnecessary port mapping in docker-compose.yml
This commit is contained in:
parent
1e5a035d33
commit
1e3b188d90
3 changed files with 22 additions and 5 deletions
|
@ -65,7 +65,8 @@ body {
|
||||||
.app {
|
.app {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
min-height: 100vh;
|
height: calc(100vh - 4rem);
|
||||||
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
.app-header {
|
.app-header {
|
||||||
|
@ -81,6 +82,8 @@ body {
|
||||||
.app-main {
|
.app-main {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
padding: 1rem;
|
padding: 1rem;
|
||||||
|
height: 100%;
|
||||||
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Auth styles */
|
/* Auth styles */
|
||||||
|
@ -185,7 +188,8 @@ button:disabled {
|
||||||
/* Chat styles */
|
/* Chat styles */
|
||||||
.chat-container {
|
.chat-container {
|
||||||
display: flex;
|
display: flex;
|
||||||
height: calc(100vh - 120px);
|
height: 100%;
|
||||||
|
max-height: calc(100vh - 120px);
|
||||||
background-color: var(--card-background);
|
background-color: var(--card-background);
|
||||||
border-radius: 0.5rem;
|
border-radius: 0.5rem;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
|
|
@ -80,6 +80,13 @@ export function ChatRoom(props: ChatRoomProps) {
|
||||||
const [messages, setMessages] = createSignal<Message[]>([]);
|
const [messages, setMessages] = createSignal<Message[]>([]);
|
||||||
const [confirmLeave, setConfirmLeave] = createSignal(false);
|
const [confirmLeave, setConfirmLeave] = createSignal(false);
|
||||||
const [leaveError, setLeaveError] = createSignal<string | null>(null);
|
const [leaveError, setLeaveError] = createSignal<string | null>(null);
|
||||||
|
let messagesContainer: HTMLDivElement | undefined;
|
||||||
|
|
||||||
|
const scrollToBottom = () => {
|
||||||
|
if (messagesContainer) {
|
||||||
|
messagesContainer.scrollTop = messagesContainer.scrollHeight;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Query room details
|
// Query room details
|
||||||
const [roomQuery] = createQuery({
|
const [roomQuery] = createQuery({
|
||||||
|
@ -121,12 +128,19 @@ export function ChatRoom(props: ChatRoomProps) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
createEffect(() => {
|
||||||
|
if (messages().length > 0) {
|
||||||
|
scrollToBottom();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Handle new messages from subscription
|
// Handle new messages from subscription
|
||||||
createEffect(() => {
|
createEffect(() => {
|
||||||
const result = messageSubscription;
|
const result = messageSubscription;
|
||||||
if (result.data?.messageAdded) {
|
if (result.data?.messageAdded) {
|
||||||
const newMessage = result.data.messageAdded;
|
const newMessage = result.data.messageAdded;
|
||||||
setMessages((prev) => [...prev, newMessage]);
|
setMessages((prev) => [...prev, newMessage]);
|
||||||
|
scrollToBottom();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -149,6 +163,7 @@ export function ChatRoom(props: ChatRoomProps) {
|
||||||
roomId: props.roomId,
|
roomId: props.roomId,
|
||||||
});
|
});
|
||||||
setMessage('');
|
setMessage('');
|
||||||
|
scrollToBottom();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to send message:', error);
|
console.error('Failed to send message:', error);
|
||||||
}
|
}
|
||||||
|
@ -209,7 +224,7 @@ export function ChatRoom(props: ChatRoomProps) {
|
||||||
</div>
|
</div>
|
||||||
</Show>
|
</Show>
|
||||||
|
|
||||||
<div class='chat-messages'>
|
<div class='chat-messages' ref={messagesContainer}>
|
||||||
<Show
|
<Show
|
||||||
when={!roomQuery.fetching}
|
when={!roomQuery.fetching}
|
||||||
fallback={<div>Loading messages...</div>}
|
fallback={<div>Loading messages...</div>}
|
||||||
|
|
|
@ -28,8 +28,6 @@ services:
|
||||||
- NODE_ENV=production
|
- NODE_ENV=production
|
||||||
- VITE_API_URL=https://chat-api.jusemon.com/graphql
|
- VITE_API_URL=https://chat-api.jusemon.com/graphql
|
||||||
- VITE_WS_URL=wss://chat-api.jusemon.com/graphql
|
- VITE_WS_URL=wss://chat-api.jusemon.com/graphql
|
||||||
ports:
|
|
||||||
- "5173:5173"
|
|
||||||
networks:
|
networks:
|
||||||
- default-network
|
- default-network
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue