From 35c108a3cfe554ad264b3dde63c98d7de604cf08 Mon Sep 17 00:00:00 2001 From: Robert Kossessa Date: Sat, 27 Jan 2024 16:09:16 +0100 Subject: [PATCH] UPD: Copies of profiles will have related ids --- src/components/ProfileManager.vue | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/components/ProfileManager.vue b/src/components/ProfileManager.vue index 2215bf8..341ebc7 100644 --- a/src/components/ProfileManager.vue +++ b/src/components/ProfileManager.vue @@ -94,11 +94,17 @@ const filteredProfiles = computed(() => { }) }) -function newProfileId() { - let id = '' - do { - id = Math.floor(Math.random() * 9999).toString().padStart(4, '0') - } while (store.profileIds.includes(id)) +function newProfileId(originalId = '') { + let id = originalId + if (originalId) { + do { + id = Math.floor((parseInt(id) + 1) % 9999).toString().padStart(4, '0') + } while (store.profileIds.includes(id)) + } else { + do { + id = Math.floor(Math.random() * 9999).toString().padStart(4, '0') + } while (store.profileIds.includes(id)) + } return id } @@ -115,7 +121,7 @@ const duplicateProfile = (id) => { const profile = profiles.value.find(p => p.id === id) const profileIndex = profiles.value.indexOf(profile) const newProfile = JSON.parse(JSON.stringify(profile)) - newProfile.id = newProfileId() + newProfile.id = newProfileId(id) newProfile.name = newProfileName(profile.name) profiles.value.splice(profileIndex + 1, 0, newProfile) }