From 1155fc37d132d910147605a321b27c4500b4646c Mon Sep 17 00:00:00 2001 From: yashdesu Date: Mon, 28 Oct 2024 09:05:15 +0530 Subject: [PATCH] fix: add id to 0 skin by default --- .../components/UserProfileEdit.svelte | 34 ++++++++----------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/src/pages/passport/components/UserProfileEdit.svelte b/src/pages/passport/components/UserProfileEdit.svelte index 37cdc9124..205232f96 100644 --- a/src/pages/passport/components/UserProfileEdit.svelte +++ b/src/pages/passport/components/UserProfileEdit.svelte @@ -403,26 +403,6 @@ } hasSpotlightLimitReadched = false - console.log('Skin index', skinIndex) - console.log('Before skin index', profile?.skins?.slice(0, skinIndex) ?? []) - console.log('After skin index', profile?.skins?.slice(skinIndex + 1) ?? []) - console.log('At skin index', { - ...(profile?.skins?.at(skinIndex) ?? ({} as Skin)), // Retain other skin properties irrespective of whether the skin is modified or not. - spotlight: profile?.skins - ?.at(skinIndex) - ?.spotlight?.find((clip) => clip.payload === item.payload) - ? [ - ...(profile.skins - ?.at(skinIndex) - ?.spotlight?.filter((clip) => clip.payload !== item.payload) ?? - []), - ] - : [ - ...(profile.skins?.at(skinIndex)?.spotlight ?? []), - { payload: item.payload, description: '', frameColorHex: '' }, - ], - }) - profile = { ...profile, // Retain other modified fields. skins: [ @@ -732,6 +712,20 @@ } $: { + // generate id only once (i.e when profile or skins or skins(0) or skins(0).id is not present) + if (!profile?.skins?.at(0)?.id) { + profile = { + ...profile, + skins: [ + { + ...(profile?.skins?.at(0) ?? ({} as Skin)), // Retain other skin properties irrespective of whether the skin is modified or not. + id: nanoid(), + }, + ...(profile?.skins?.slice(1) ?? []), // Retain all the other skins. + ], + } + } + const index = profile?.skins?.findIndex((skin) => skin.id === skinId) ?? 0 skinIndex = index === -1 ? 0 : index }