diff --git a/client/js/avatar.js b/client/js/avatar.js index 6cb8392..20de6a0 100644 --- a/client/js/avatar.js +++ b/client/js/avatar.js @@ -201,6 +201,7 @@ function wearItem(type, itemId) { updateCurrentlyWearing(type, response.avatar[type]); updateWearButton(type, itemId, true); showAlert('success', `Wore your ${type} successfully.`); + // saveAvatarSelection(type, itemId); }, error: function (xhr, status, error) { console.error(`Error wearing ${type}:`, error); @@ -235,6 +236,7 @@ function updateCurrentlyWearing(type, item) { const container = $('#currently-wearing'); container.find(`[data-type="${type}"]`).remove(); + if (item && item.ThumbnailLocation && item.Name) { const itemHtml = `
@@ -251,6 +253,7 @@ function updateCurrentlyWearing(type, item) { `; container.append(itemHtml); + } } function removeItem(type) { @@ -270,6 +273,7 @@ function removeItem(type) { $(`#currently-wearing [data-type="${type}"]`).remove(); updateWearButton(type, null, false); showAlert('info', `Unwore your ${type}.`); + // saveAvatarSelection(type, null); }, error: function (xhr, status, error) { console.error('Error unwearing item:', error); @@ -296,7 +300,7 @@ function loadUserAvatar() { Authorization: `Bearer ${token}`, }, success: function (avatar) { - if (avatar.shirtId) { + if (avatar.shirt && avatar.shirt._id) { wearItem('shirt', avatar.shirtId); } }, @@ -324,7 +328,7 @@ function saveAvatarSelection(type, itemId) { success: function (response) { console.log('Avatar updated successfully:', response); if (itemId) { - updateAvatarDisplay(type, response.avatar[`${type}Id`]); + updateAvatarDisplay(type, response.avatar[type]); updateCurrentlyWearing(type, response.avatar); updateWearButton(type, itemId, true); showAlert('success', `Wore your ${type} successfully.`); @@ -386,13 +390,4 @@ function showAlert(type, message) { $('#avatar-container').prepend(alertHtml); } -$(document).on('click', '.remove-item', function() { - const type = $(this).data('type'); - removeItem(type); -}); -function removeItem(type) { - $(`#avatar-${type}`).attr('src', ''); - $(`#currently-wearing [data-type="${type}"]`).remove(); - saveAvatarSelection(type, null); -} \ No newline at end of file diff --git a/server/functions/api/routes/avatar.js b/server/functions/api/routes/avatar.js index 7b11c98..ed13270 100644 --- a/server/functions/api/routes/avatar.js +++ b/server/functions/api/routes/avatar.js @@ -67,7 +67,7 @@ router.put('/', authenticateToken, async (req, res) => { _id: itemId, creator: user._id, AssetType: 'Shirt' - }); + }).populate('creator', 'username'); if (!inventoryItem && !createdShirt) { console.error('Shirt not in user inventory or not created by user:', itemId); @@ -75,7 +75,7 @@ router.put('/', authenticateToken, async (req, res) => { } console.log('Setting shirt:', itemId); - user.avatar.shirt = inventoryItem; + user.avatar.shirt = createdShirt || inventoryItem; } else { console.log('Unwearing shirt'); user.avatar.shirt = null;