Remove localStorage uses

This commit is contained in:
Raven Scott 2024-06-13 01:44:44 -04:00
parent 7461dadf88
commit 060308ec92

14
app.js
View File

@ -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);