Skip to content

Commit

Permalink
fixed wearing created shirt
Browse files Browse the repository at this point in the history
  • Loading branch information
singharaj-usai committed Oct 18, 2024
1 parent b56f2a0 commit 357370e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
17 changes: 6 additions & 11 deletions client/js/avatar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 = `
<div class="col-xs-12 col-sm-6 col-md-4" data-type="${type}">
<div class="panel panel-default">
Expand All @@ -251,6 +253,7 @@ function updateCurrentlyWearing(type, item) {
`;

container.append(itemHtml);
}
}

function removeItem(type) {
Expand All @@ -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);
Expand All @@ -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);
}
},
Expand Down Expand Up @@ -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.`);
Expand Down Expand Up @@ -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);
}
4 changes: 2 additions & 2 deletions server/functions/api/routes/avatar.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ 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);
return res.status(400).json({ error: 'Shirt not in user inventory or not created by u' });
}

console.log('Setting shirt:', itemId);
user.avatar.shirt = inventoryItem;
user.avatar.shirt = createdShirt || inventoryItem;
} else {
console.log('Unwearing shirt');
user.avatar.shirt = null;
Expand Down

0 comments on commit 357370e

Please sign in to comment.