Skip to content

Commit

Permalink
haaaaaaaaaaaaa
Browse files Browse the repository at this point in the history
  • Loading branch information
TotoB12 committed Feb 18, 2024
1 parent f5050f1 commit c999c87
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 27 deletions.
57 changes: 36 additions & 21 deletions public/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,8 @@ function updateMenuWithConversations() {

categories.forEach(category => {
if (category.conversations.length > 0) {
const header = document.createElement("h4");
const header = document.createElement("p");
header.className = "conversation-header";
header.textContent = category.label;
menu.appendChild(header);

Expand Down Expand Up @@ -747,7 +748,7 @@ function startWebSocket() {
) {
// console.log("UUID:", data.uuid);
processAIResponse(data.text);
wrapCodeElements();
// wrapCodeElements();
}

if (data.type === "pong") {
Expand Down Expand Up @@ -859,6 +860,7 @@ function processAIResponse(message, isError = false) {
generateAndDisplayImage(imageCommandMatch[1]);
} else if (displayedMessage.trim() !== "") {
latestAIMessageElement.innerHTML = marked.parse(displayedMessage.trim());
wrapCodeElements();
}

if (latestAIMessageElement.fullMessage.trim() !== "") {
Expand All @@ -877,12 +879,33 @@ function processAIResponse(message, isError = false) {
}

function addLoadingIndicator() {
const bubbleContainer = document.createElement("div");
bubbleContainer.className = "loading-bubble";

const loadingIndicator = document.createElement("div");
loadingIndicator.className = "image-loading";
loadingIndicator.textContent = "Generating image...";
// const loadingIndicatorIcon = document.createElement("div");
// loadingIndicatorIcon.className = "image-loading-icon";
// chatBox.appendChild(loadingIndicatorIcon);
loadingIndicator.textContent = "Generating image";
bubbleContainer.appendChild(loadingIndicator);
chatBox.appendChild(bubbleContainer);

let dots = 0;
const maxDots = 3;
const updateText = () => {
dots = (dots + 1) % (maxDots + 1);
loadingIndicator.textContent = "Generating image" + ".".repeat(dots);
};
const intervalId = setInterval(updateText, 500);

bubbleContainer.dataset.intervalId = intervalId.toString();
}

function removeLoadingIndicator() {
const bubbleContainer = document.querySelector(".loading-bubble");
if (bubbleContainer) {
const intervalId = parseInt(bubbleContainer.dataset.intervalId, 10);
clearInterval(intervalId);
bubbleContainer.remove();
}
}

function generateAndDisplayImage(prompt, image = null) {
Expand All @@ -899,16 +922,7 @@ function generateAndDisplayImage(prompt, image = null) {
.then((response) => response.json())
.then((data) => {
if (data && data.imageData) {
const loadingIndicator = document.querySelector(".image-loading");
const loadingIndicatorIcon = document.querySelector(
".image-loading-icon",
);
if (loadingIndicator) {
loadingIndicator.remove();
}
if (loadingIndicatorIcon) {
loadingIndicatorIcon.remove();
}
removeLoadingIndicator();

const imageBlob = base64ToBlob(data.imageData);
const tempImageUrl = URL.createObjectURL(imageBlob);
Expand Down Expand Up @@ -1074,6 +1088,10 @@ function sendMessage() {
isNewConversation = false;
}

if (ws && ws.readyState === WebSocket.OPEN) {
ws.send(JSON.stringify(message));
}

inputField.value = "";
resetTextarea();
resetUploadButton();
Expand All @@ -1083,10 +1101,7 @@ function sendMessage() {
isAIResponding = true;
updateSendButtonState();
wrapCodeElements();

if (ws && ws.readyState === WebSocket.OPEN) {
ws.send(JSON.stringify(message));
}
updateMenuWithConversations();
}

function displayImage(imageUrl, blobUrl = false) {
Expand Down Expand Up @@ -1791,7 +1806,7 @@ function update_anim(t) {
// }

function wrapCodeElements() {
console.log('haaaaaaaaa');
// console.log('haaaaaaaaa');
hljs.highlightAll();
const codeElements = document.querySelectorAll("code");
codeElements.forEach((codeElement) => {
Expand Down
37 changes: 31 additions & 6 deletions public/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,23 @@
}

@font-face {
font-family: 'PolySans';
font-family: 'PolySans Neutral';
src: url('/assets/fonts/PolySans-neutral.ttf') format('truetype');
}

@font-face {
font-family: 'PolySans Bulky';
src: url('/assets/fonts/PolySans-bulky.ttf') format('truetype');
}

@font-face {
font-family: 'PolySans Slim';
src: url('/assets/fonts/PolySans-slim.ttf') format('truetype');
}

::-webkit-scrollbar {
width: 7px;
height: 7px;
/* 10px */
}

Expand All @@ -34,7 +43,7 @@
}

body {
font-family: 'PolySans', Arial, sans-serif;
font-family: 'PolySans Slim', Arial, sans-serif;
margin: 0;
background-color: var(--background-color);
color: var(--main-color);
Expand Down Expand Up @@ -104,7 +113,7 @@ body {
}

#chat-input {
font-family: 'PolySans', Arial, sans-serif;
font-family: 'PolySans Slim', Arial, sans-serif;
resize: none;
font-size: large;
flex-grow: 1;
Expand Down Expand Up @@ -760,7 +769,7 @@ code.hljs {
}

.copy-button {
font-family: 'PolySans', Arial, sans-serif;
font-family: 'PolySans Neutral', Arial, sans-serif;
cursor: pointer;
background: none;
border: none;
Expand Down Expand Up @@ -937,16 +946,32 @@ input:checked + .slider:before {
-moz-animation: loading-animation 1s infinite linear;
}

.loading-bubble {
/* display: inline-block; */
width: 20vw;
padding: 10px 20px;
margin: 20px 0px;
background-color: var(--main-color);
border-radius: 20px;
box-shadow: 0 2px 4px rgba(0,0,0,0.2);
color: #333;
}

.image-loading {
color: var(--main-color);
font-size: 1.2em;
color: inherit;
font-size: 1em;
}


@keyframes loading-animation {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}

.conversation-header {
font-family: 'PolySans Neutral', Arial, sans-serif;
}

0 comments on commit c999c87

Please sign in to comment.