From 060308ec922ea28c591d9619518e80e495b1b51b Mon Sep 17 00:00:00 2001 From: Raven Scott Date: Thu, 13 Jun 2024 01:44:44 -0400 Subject: [PATCH] Remove localStorage uses --- app.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app.js b/app.js index 5c31e12..2fe4caa 100644 --- a/app.js +++ b/app.js @@ -14,7 +14,6 @@ const drive = new Hyperdrive(store); await drive.ready(); let swarm; -let registeredUsers = JSON.parse(localStorage.getItem('registeredUsers')) || {}; let peerCount = 0; let activeRooms = []; const eventEmitter = new EventEmitter(); @@ -26,7 +25,8 @@ let servePort; let config = { userName: '', userAvatar: '', - rooms: [] + rooms: [], + registeredUsers: {} }; // Store messages for each room @@ -97,8 +97,8 @@ async function initialize() { config.rooms.forEach(room => { room.alias = room.alias || truncateHash(room.topic); }); - for (let user in registeredUsers) { - registeredUsers[user] = updatePortInUrl(registeredUsers[user]); + for (let user in config.registeredUsers) { + config.registeredUsers[user] = updatePortInUrl(config.registeredUsers[user]); } renderRoomList(); // Render the room list with aliases @@ -189,7 +189,7 @@ function registerUser(e) { e.preventDefault(); const regUsername = document.querySelector('#reg-username').value; - if (registeredUsers[regUsername]) { + if (config.registeredUsers[regUsername]) { alert('Username already taken. Please choose another.'); return; } @@ -201,8 +201,8 @@ function registerUser(e) { const buffer = new Uint8Array(event.target.result); await drive.put(`/icons/${regUsername}.png`, buffer); config.userAvatar = `http://localhost:${servePort}/icons/${regUsername}.png`; // Set the correct URL - registeredUsers[regUsername] = `http://localhost:${servePort}/icons/${regUsername}.png`; // Use placeholder URL - localStorage.setItem('registeredUsers', JSON.stringify(registeredUsers)); + config.registeredUsers[regUsername] = `http://localhost:${servePort}/icons/${regUsername}.png`; // Use placeholder URL + writeConfigToFile("./config.json"); continueRegistration(regUsername); }; reader.readAsArrayBuffer(avatarFile);