Skip to content

Commit

Permalink
Implemented notes on roompage
Browse files Browse the repository at this point in the history
  • Loading branch information
klpulliam-37 committed May 1, 2023
1 parent 87b8c6e commit aeafc31
Show file tree
Hide file tree
Showing 6 changed files with 292 additions and 277 deletions.
2 changes: 1 addition & 1 deletion UserInterface/js/chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ function updateChart(dates, data, key) {
},
options: {
animation: false,
aspectRatio: 1,
aspectRatio: 1.5,
scales: {
y: {
beginAtZero: false,
Expand Down
4 changes: 4 additions & 0 deletions UserInterface/js/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ async function validateUser() {
const jwt = await proxy.login(user);
if (jwt) {
invalidLoginText.style.visibility = 'hidden';

const jwtStr = JSON.stringify(jwt);
sessionStorage.setItem('jwt', jwtStr);

sessionStorage.setItem('access_token', jwt['access_token']);
sessionStorage.setItem('refresh_token', jwt['refresh_token']);
window.location.assign('/home');
Expand Down
12 changes: 8 additions & 4 deletions UserInterface/js/roomMessages.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ function createUserList() {
}

createUserList();
// console.log(usernames);

function resetChatbox() {
while(chatbox_body.firstChild) {
Expand All @@ -27,7 +26,7 @@ function resetChatbox() {
}

async function renderMessages() {
const messages = proxy.getAllMessagesByRoom(roomID);
const messages = await proxy.getAllMessagesByRoom(roomID);
console.log(messages);
resetChatbox();

Expand Down Expand Up @@ -66,8 +65,13 @@ renderMessages();
async function sendMessage() {
const messageBox = document.getElementById('message-input-box');
const message = messageBox.value;
console.log(message);

// Get user ID from access_token
Utils.
const jwt = Utils.getJwt();
const userID = jwt['user_id'];

await proxy.createRoomMessage(roomID, userID, message);
renderMessages();

messageBox.value = '';
}
10 changes: 6 additions & 4 deletions UserInterface/js/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function getUserObj() {
return user;
}

export function parseJwt (token) {
export function parseJwt(token) {
var base64Url = token.split('.')[1];
var base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');
var jsonPayload = decodeURIComponent(window.atob(base64).split('').map(function(c) {
Expand All @@ -21,6 +21,8 @@ export function parseJwt (token) {
return JSON.parse(jsonPayload);
}

// export function getJwt(obj) {
// return JSON.parse(obj)["access_token"];
// }
export function getJwt() {
const jwtStr = sessionStorage.getItem('jwt');
const jwt = JSON.parse(jwtStr);
return jwt;
}
Loading

0 comments on commit aeafc31

Please sign in to comment.