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