Skip to content

Commit 31fbe42

Browse files
authored
Merge pull request #93 from Azure-Samples/howie/css-and-refresh
Howie/css and refresh
2 parents b8fa2e3 + 5774923 commit 31fbe42

File tree

6 files changed

+52
-31
lines changed

6 files changed

+52
-31
lines changed

docs/webapp_screenshot.png

-96.7 KB
Loading

src/api/routes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ async def history(
180180
raise HTTPException(status_code=400, detail=f"Error handling thread: {e}")
181181

182182
thread_id = thread.id
183-
messages = OpenAIPageableListOfThreadMessage()
183+
agent_id = agent.id
184184

185185
# Create a new message from the user's input.
186186
try:

src/api/static/ChatUI.js

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,33 @@ class ChatUI {
3333
return content;
3434
}
3535

36-
removePlaceholder() {
37-
// Remove placeholder message if it exists
36+
showPlaceholder(show) {
37+
// show/hide placeholder message if it exists
3838
const placeholderWrapper = document.getElementById("placeholder-wrapper");
3939
if (placeholderWrapper) {
40-
placeholderWrapper.remove();
40+
placeholderWrapper.style.display = show? "flex": "none";
4141
}
4242
}
4343

44+
clearChat() {
45+
const placeholderWrapper = document.getElementById("placeholder-wrapper");
46+
const targetContainer = document.getElementById("messages");
47+
while (targetContainer.lastChild && targetContainer.lastChild != placeholderWrapper) {
48+
targetContainer.removeChild(targetContainer.lastChild);
49+
}
50+
this.showPlaceholder(true)
51+
52+
this.deleteAllCookies();
53+
}
54+
55+
deleteAllCookies() {
56+
document.cookie.split(';').forEach(cookie => {
57+
const eqPos = cookie.indexOf('=');
58+
const name = eqPos > -1 ? cookie.substring(0, eqPos) : cookie;
59+
document.cookie = name + '=;expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/';
60+
});
61+
}
62+
4463
addCitationClickListener() {
4564
document.addEventListener('click', (event) => {
4665
if (event.target.classList.contains('file-citation')) {
@@ -127,7 +146,7 @@ class ChatUI {
127146

128147
appendUserMessage(message) {
129148
// Remove the placeholder message
130-
this.removePlaceholder();
149+
this.showPlaceholder(false);
131150

132151
const userTemplateClone = this.userTemplate.content.cloneNode(true);
133152
userTemplateClone.querySelector(".message-content").textContent = message;
@@ -148,13 +167,12 @@ class ChatUI {
148167
const preprocessedContent = this.preprocessContent(accumulatedContent, annotations);
149168
// Convert the accumulated content to HTML using markdown-it
150169
let htmlContent = md.render(preprocessedContent);
151-
const messageTextDiv = messageDiv.querySelector(".message-text");
152-
if (!messageTextDiv) {
170+
if (!messageDiv) {
153171
throw new Error("Message content div not found in the template.");
154172
}
155173

156174
// Set the innerHTML of the message text div to the HTML content
157-
messageTextDiv.innerHTML = htmlContent;
175+
messageDiv.innerHTML = htmlContent;
158176

159177
// Use requestAnimationFrame to ensure the DOM has updated before scrolling
160178
// Only scroll if not streaming
@@ -169,9 +187,8 @@ class ChatUI {
169187
}
170188

171189
clearAssistantMessage(messageDiv) {
172-
const messageTextDiv = messageDiv.querySelector(".message-text");
173-
if (messageTextDiv) {
174-
messageTextDiv.innerHTML = '';
190+
if (messageDiv) {
191+
messageDiv.innerHTML = '';
175192
}
176193
}
177194

@@ -183,7 +200,7 @@ class ChatUI {
183200
}
184201

185202
// Remove the placeholder message
186-
this.removePlaceholder();
203+
this.showPlaceholder(false);
187204

188205
// Append the clone to the target container
189206
this.targetContainer.appendChild(assistantTemplateClone);

src/api/static/main.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,7 @@ function initChat() {
2727

2828
document.addEventListener("DOMContentLoaded", initChat);
2929

30+
window.chatUI = chatUI;
31+
window.chatClient = chatClient;
32+
3033
await chatUI.loadChatHistory();

src/api/static/styles.css

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ html, body {
4242
margin-bottom: 5px;
4343
}
4444

45+
#messages .message-content p {
46+
margin: 0;
47+
}
48+
49+
.user .message-content {
50+
background-color: #EBEFFF;
51+
}
52+
4553
/* Ensure consistent font size and styling for message text */
4654
.message-text {
4755
font-size: 16px;
@@ -151,14 +159,9 @@ html, body {
151159

152160
/* Background colors for user and assistant messages */
153161
.background-user {
154-
background-color: #2372cc;
155162
color: white; /* Ensure text is readable on the background */
156163
}
157164

158-
.background-assistant {
159-
background-color: #2c8310;
160-
color: white; /* Ensure text is readable on the background */
161-
}
162165

163166
/* Styling for messages */
164167
.toast {
@@ -177,4 +180,8 @@ html, body {
177180

178181
.toast-body {
179182
padding: 0.75rem;
183+
}
184+
185+
.dark-border {
186+
border-color: #373A3C;
180187
}

src/api/templates/index.html

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,12 @@
5656
<div id="chat-area" class="text-light px-4 py-2 rounded-top text-dark d-flex flex-column justify-content-center background-user">
5757
<form id="chat-form" onsubmit="event.preventDefault();">
5858
<div class="input-group">
59-
<i class="bi bi-body-text input-group-text" aria-hidden="true"></i>
60-
<input id="message" name="message" class="form-control form-control-sm" type="text" placeholder="Your Message" aria-label="Ask ChatGPT"></input>
61-
<button type="submit" class="btn btn-outline-light">
59+
<button class="btn btn-outline-dark" onclick="chatUI.clearChat()" aria-label="Start a new chat">
60+
<i class="bi bi-arrow-repeat" aria-hidden="true"></i>
61+
</button>
62+
<i class="bi bi-body-text input-group-text dark-border" aria-hidden="true"></i>
63+
<input id="message" name="message" class="form-control form-control-sm dark-border" type="text" placeholder="Your Message" aria-label="Ask ChatGPT"></input>
64+
<button type="submit" class="btn btn-outline-dark" style="border-left-width: 0" aria-label="Submit">
6265
Send <i class="bi bi-send-fill" aria-hidden="true"></i>
6366
</button>
6467
</div>
@@ -70,20 +73,16 @@
7073
<div class="col-6 d-flex flex-column h-100 p-3 bg-light border-left" id="document-viewer-section" style="display: none !important;"> <!-- Hidden and no space initially -->
7174
<div class="d-flex justify-content-between align-items-center mb-2">
7275
<h5 class="mb-0">Document Viewer</h5>
73-
<button id="close-button" class="btn btn-danger">Close</button>
76+
<button id="close-button" class="btn bi-x"></button>
7477
</div>
7578
<iframe id="document-viewer" class="flex-grow-1 border-0 rounded" style="background-color: white;"></iframe>
7679
</div>
7780
</div>
7881
</div>
7982

8083
<template id="message-template-user">
81-
<div class="toast-container position-static w-100 d-flex flex-column align-items-stretch">
84+
<div class="toast-container position-static w-100 d-flex flex-column align-items-stretch user">
8285
<div class="toast fade show w-75 rounded-3 align-self-end">
83-
<div class="toast-header text-light background-user">
84-
<i class="bi bi-person me-1" aria-hidden="true"></i>
85-
<strong class="me-auto text-capitalize">You</strong>
86-
</div>
8786
<div class="toast-body message-content"></div>
8887
</div>
8988
</div>
@@ -92,12 +91,7 @@ <h5 class="mb-0">Document Viewer</h5>
9291
<template id="message-template-assistant">
9392
<div class="toast-container position-static w-100 d-flex flex-column align-items-stretch">
9493
<div class="toast fade show w-75 rounded-3 align-self-start">
95-
<div class="toast-header text-light background-assistant">
96-
<i class="bi bi-robot me-1" aria-hidden="true"></i>
97-
<strong class="me-auto text-capitalize">Assistant</strong>
98-
</div>
9994
<div class="toast-body message-content">
100-
<div class="message-text"></div>
10195
</div>
10296
</div>
10397
</div>

0 commit comments

Comments
 (0)