Skip to content

Commit

Permalink
Fixed home page message box
Browse files Browse the repository at this point in the history
  • Loading branch information
klpulliam-37 committed May 3, 2023
1 parent aa51ec6 commit 3c7a9d4
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions UserInterface/js/chatbox.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { GreenhouseProxy } from "../api/api.js";
import * as Utils from "../js/utilities.js";

const proxy = new GreenhouseProxy();

Expand Down Expand Up @@ -78,19 +79,37 @@ async function renderMessages() {
const messages = await proxy.getAllMessagesByRoom(roomID);
if (messages.length) {
messages.forEach(message => {
const user = message["user_id"];
// const user = message["user_id"];
const textContainer = document.createElement('div');
textContainer.setAttribute('class', 'd-flex align-items-baseline mb-4');
const container2 = document.createElement('div');
container2.setAttribute('class', 'pe-2');
const textCard = document.createElement('div');
textCard.setAttribute('class', 'card card-text d-inline-block p-2 px-3 m-1');
const user = document.createElement('div');
user.setAttribute('class', 'small');
user.textContent = usernames[message['user_id']];
const date = document.createElement('div');
date.setAttribute('class', 'small');
date.textContent = usernames[message['user_id']];

const dateObj = new Date(message['timestamp']);
const day = dateObj.getDate();
const month = Utils.months[dateObj.getMonth()];
const year = dateObj.getFullYear();
const hoursObj = Utils.toStandardTime(dateObj.getHours());
let minutes = dateObj.getMinutes();
if (minutes < 10) {
minutes = '0' + minutes;
}
const hours = hoursObj['hours'];
const amPm = hoursObj['amPm'];
const dateStr = `${hours}:${minutes} ${amPm} - ${day} ${month}, ${year}`;

date.textContent = dateStr;

textCard.textContent = message["body"];

container2.append(user);
container2.append(textCard);
container2.append(date);

Expand Down

0 comments on commit 3c7a9d4

Please sign in to comment.