This commit is contained in:
Raven Scott 2024-06-04 00:53:49 -04:00
parent 7a29ecc391
commit 1d7f69ccd2

28
app.js
View File

@ -49,23 +49,22 @@ async function initialize() {
messageForm.addEventListener('submit', sendMessage); messageForm.addEventListener('submit', sendMessage);
} }
const savedUser = localStorage.getItem('currentUser'); // const savedUser = localStorage.getItem('currentUser');
const avatarURL = localStorage.getItem('avatarURL');
if (savedUser) { // if (savedUser) {
const user = JSON.parse(savedUser); // const user = JSON.parse(savedUser);
userName = user.username; // userName = user.username;
userAvatar = avatarURL || ''; // userAvatar = user.avatar || '';
const setupDiv = document.querySelector('#setup'); // const setupDiv = document.querySelector('#setup');
if (setupDiv) { // if (setupDiv) {
setupDiv.classList.remove('hidden'); // setupDiv.classList.remove('hidden');
} // }
} else { // } else {
const registerDiv = document.querySelector('#register'); const registerDiv = document.querySelector('#register');
if (registerDiv) { if (registerDiv) {
registerDiv.classList.remove('hidden'); registerDiv.classList.remove('hidden');
} }
} // }
swarm.on('connection', async (connection, info) => { swarm.on('connection', async (connection, info) => {
peerCount++; peerCount++;
@ -147,8 +146,9 @@ async function registerUser(e) {
const fileBuffer = Buffer.from(reader.result); const fileBuffer = Buffer.from(reader.result);
await drive.put(`/icons/${regUsername}.png`, fileBuffer); await drive.put(`/icons/${regUsername}.png`, fileBuffer);
userAvatar = `http://localhost:1337/icons/${regUsername}.png`; userAvatar = `http://localhost:1337/icons/${regUsername}.png`;
// Save avatar URL to localStorage // Save avatar URL to currentUser.avatar
localStorage.setItem('avatarURL', userAvatar); newUser.avatar = userAvatar;
localStorage.setItem('currentUser', JSON.stringify(newUser));
// Broadcast the icon to all connected peers // Broadcast the icon to all connected peers
const iconMessage = JSON.stringify({ const iconMessage = JSON.stringify({