ADD: Deleting profiles

This commit is contained in:
Robert Kossessa
2024-03-13 22:10:33 +01:00
parent f91312c824
commit 9b21f206a8
2 changed files with 18 additions and 1 deletions

View File

@@ -126,7 +126,7 @@
deviceStore.duplicateProfile(originalName, profile) deviceStore.duplicateProfile(originalName, profile)
} }
" "
@delete="console.log('Delete profile not implemented!')" @delete="(profileName) => deviceStore.deleteProfile(profileName)"
/> />
</div> </div>
</template> </template>

View File

@@ -135,6 +135,23 @@ export const useDeviceStore = defineStore('device', {
} }
} }
}, },
deleteProfile(profileName: string, updateDevice: boolean = true) {
const index = this.profileNames.indexOf(profileName)
if (index !== -1) {
this.profileNames.splice(index, 1)
}
const profile = this.profiles.find((p) => p.name === profileName)
if (profile) {
const profileIndex = this.profiles.indexOf(profile)
this.profiles.splice(profileIndex, 1)
}
if (this.currentProfileName === profileName && this.profileNames.length > 0) {
this.selectProfile(this.profileNames[0], updateDevice)
}
if (updateDevice) {
nanoIpc.send(this.currentDeviceId!, JSON.stringify({ profiles: this.profileNames }))
}
},
duplicateProfile(profileName: string, updateDevice: boolean = true) { duplicateProfile(profileName: string, updateDevice: boolean = true) {
const profile = this.profiles.find((p) => p.name === profileName) const profile = this.profiles.find((p) => p.name === profileName)
if (profile) { if (profile) {