Skip to content

Commit 1a79ed0

Browse files
committed
Refactor chat.html for improved functionality and user experience
- Replaced auto-scroll logic with dedicated functions for scrolling and focusing input. - Updated form submission to use a JavaScript function for better control and added a loading state for the send button. - Enhanced textarea placeholder to clarify message input instructions.
1 parent cd37bdb commit 1a79ed0

1 file changed

Lines changed: 21 additions & 8 deletions

File tree

src/deepseek_wrapper/templates/chat.html

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,40 @@
55
<title>DeepSeek Chat</title>
66
<link rel="stylesheet" href="/static/style.css">
77
<script>
8-
// Auto-scroll chat to bottom
9-
window.onload = function() {
8+
function scrollChat() {
109
var chat = document.getElementById('chat-history');
1110
if (chat) chat.scrollTop = chat.scrollHeight;
12-
document.getElementById('user_message').focus();
11+
}
12+
function focusInput() {
13+
var input = document.getElementById('user_message');
14+
if (input) input.focus();
15+
}
16+
window.onload = function() {
17+
scrollChat();
18+
focusInput();
1319
};
14-
// Enter to send, Shift+Enter for newline
1520
function handleKey(e) {
1621
if (e.key === 'Enter' && !e.shiftKey) {
1722
e.preventDefault();
18-
document.getElementById('chat-form').submit();
23+
sendChat();
1924
}
2025
}
26+
function sendChat() {
27+
var btn = document.getElementById('send-btn');
28+
var form = document.getElementById('chat-form');
29+
var input = document.getElementById('user_message');
30+
if (btn) btn.disabled = true;
31+
form.submit();
32+
setTimeout(function() { if (input) input.value = ''; }, 100);
33+
}
2134
</script>
2235
</head>
2336
<body>
2437
<div class="container">
2538
<h1>DeepSeek Chat</h1>
26-
<form id="chat-form" method="post" action="/chat" autocomplete="off">
27-
<textarea id="user_message" name="user_message" placeholder="Type your message..." required rows="2" onkeydown="handleKey(event)"></textarea>
28-
<button type="submit">Send</button>
39+
<form id="chat-form" method="post" action="/chat" autocomplete="off" onsubmit="sendChat(); return false;">
40+
<textarea id="user_message" name="user_message" placeholder="Type your message... (Enter to send, Shift+Enter for newline)" required rows="2" onkeydown="handleKey(event)"></textarea>
41+
<button id="send-btn" type="submit" {% if loading %}disabled{% endif %}>Send</button>
2942
<button type="button" onclick="document.getElementById('reset-form').submit();" class="reset-btn">Reset</button>
3043
</form>
3144
<form id="reset-form" method="post" action="/reset" style="display:none;"></form>

0 commit comments

Comments
 (0)