|
18 | 18 | <body class="bg-light"> |
19 | 19 | <div class="container py-4"> |
20 | 20 | <h1 class="mb-4">Open Pull Requests</h1> |
| 21 | + <label>User ID: <input id="userId" value="user123"></label><br> |
| 22 | + <label>Session ID: <input id="sessionId" value="session456"></label><br> |
21 | 23 |
|
22 | 24 | <!-- PR List View --> |
23 | 25 | <div id="pr-list" class="list-group"> |
@@ -51,7 +53,7 @@ <h5 class="mt-4">Review:</h5> |
51 | 53 | <!-- Chat Text Area and Submit Button --> |
52 | 54 | <div class="chat-container"> |
53 | 55 | <textarea id="chat-input" placeholder="Enter your comment..."></textarea> |
54 | | - <button class="chat-submit-btn" onclick="submitChatComment()"> |
| 56 | + <button class="chat-submit-btn" onclick="sendChatMessage()"> |
55 | 57 | ➤ |
56 | 58 | </button> |
57 | 59 | </div> |
@@ -150,6 +152,8 @@ <h6>Action:</h6> |
150 | 152 |
|
151 | 153 | // Set the Review HTML content |
152 | 154 | document.getElementById('detail-review').innerHTML = html; |
| 155 | + console.info('Connecting to chat.'); |
| 156 | + connectChat(); |
153 | 157 | } |
154 | 158 |
|
155 | 159 | function showListView() { |
@@ -212,23 +216,6 @@ <h6>Action:</h6> |
212 | 216 | alert('Failed to submit your decision.'); |
213 | 217 | } |
214 | 218 | } |
215 | | - function submitChatComment() { |
216 | | - const comment = document.getElementById("chat-input").value.trim(); |
217 | | - if (!comment) { |
218 | | - alert("Please enter a comment before submitting."); |
219 | | - return; |
220 | | - } |
221 | | - |
222 | | - // Placeholder logic for testing – replace with actual backend call if needed |
223 | | - const chatBox = document.getElementById("chat-response-box"); |
224 | | - const simulatedResponse = `🤖 Response to: "${comment}"\n`; |
225 | | - |
226 | | - chatBox.textContent += simulatedResponse; |
227 | | - chatBox.scrollTop = chatBox.scrollHeight; |
228 | | - |
229 | | - document.getElementById("chat-input").value = ''; |
230 | | - } |
231 | | - |
232 | 219 |
|
233 | 220 | function setupWebSocket() { |
234 | 221 | console.info('setupWebSocket() entered.'); |
@@ -325,6 +312,69 @@ <h6>Action:</h6> |
325 | 312 | fetchPrs(); |
326 | 313 | console.info('Setting up WebSocket'); |
327 | 314 | setupWebSocket(); |
| 315 | + chatSocket = {}; |
| 316 | + |
| 317 | + function connectChat() { |
| 318 | + if (chatSocket && (chatSocket.readyState === WebSocket.OPEN || chatSocket.readyState === WebSocket.CONNECTING)) { |
| 319 | + console.log("Chat WebSocket is already connecting or connected."); |
| 320 | + return; |
| 321 | + } |
| 322 | + const userId = document.getElementById("userId").value; |
| 323 | + const sessionId = document.getElementById("sessionId").value; |
| 324 | + //const url = `ws://localhost:8080/ws/chat/${userId}/${sessionId}`; |
| 325 | + const protocol = window.location.protocol === "https:" ? "wss:" : "ws:"; |
| 326 | + const url = `${protocol}//notifications.codeominous.com/ws/chat/${userId}/${sessionId}`; |
| 327 | + |
| 328 | + chatSocket = new WebSocket(url); |
| 329 | + |
| 330 | + chatSocket.onmessage = function (event) { |
| 331 | + const msg = event.data; |
| 332 | + document.getElementById("chat-response-box").innerHTML += `<div class='bot'><strong>Claude:</strong> ${msg}</div>`; |
| 333 | + }; |
| 334 | + |
| 335 | + chatSocket.onopen = function () { |
| 336 | + document.getElementById("chat-response-box").innerHTML += "<div><em>Connected to chat server.</em></div>"; |
| 337 | + }; |
| 338 | + |
| 339 | + chatSocket.onclose = function () { |
| 340 | + document.getElementById("chat-response-box").innerHTML += "<div><em>Disconnected.</em></div>"; |
| 341 | + }; |
| 342 | + } |
| 343 | + |
| 344 | + function sendChatMessage() { |
| 345 | + if (chatSocket && (chatSocket.readyState != WebSocket.OPEN)) { |
| 346 | + console.log("Chat WebSocket is not connected."); |
| 347 | + return; |
| 348 | + } |
| 349 | + const comment = document.getElementById("chat-input").value.trim(); |
| 350 | + if (!comment) { |
| 351 | + alert("Please enter a comment before submitting."); |
| 352 | + return; |
| 353 | + } |
| 354 | + connectChat(); |
| 355 | + const msg = comment.value; |
| 356 | + comment.value = ""; |
| 357 | + chatSocket.send(msg); |
| 358 | + } |
| 359 | + |
| 360 | + function submitChatCommentTest() { |
| 361 | + const comment = document.getElementById("chat-input").value.trim(); |
| 362 | + if (!comment) { |
| 363 | + alert("Please enter a comment before submitting."); |
| 364 | + return; |
| 365 | + } |
| 366 | + |
| 367 | + // Placeholder logic for testing – replace with actual backend call if needed |
| 368 | + const chatBox = document.getElementById("chat-response-box"); |
| 369 | + const simulatedResponse = `🤖 Response to: "${comment}"\n`; |
| 370 | + |
| 371 | + chatBox.textContent += simulatedResponse; |
| 372 | + chatBox.scrollTop = chatBox.scrollHeight; |
| 373 | + |
| 374 | + document.getElementById("chat-input").value = ''; |
| 375 | + } |
| 376 | + |
| 377 | + |
328 | 378 | </script> |
329 | 379 | </body> |
330 | 380 | </html> |
0 commit comments