added delete profile button

This commit is contained in:
Ryan Breen
2023-01-16 20:21:35 -05:00
parent 579211e6f4
commit 4fee1c9e81
4 changed files with 36 additions and 6 deletions

View File

@@ -46,6 +46,9 @@ browser.runtime.onMessage.addListener(async (message, _sender, sendResponse) =>
case 'clearData':
await browser.storage.local.clear();
break;
case 'deleteProfile':
await deleteProfile();
break;
default:
break;
}
@@ -123,3 +126,11 @@ async function saveProfile(profile) {
profiles[index] = profile;
await storage.set({profiles});
}
async function deleteProfile() {
let index = await getProfileIndex();
let profiles = await get('profiles');
profiles.splice(index, 1);
let profileIndex = Math.max(index - 1, 0);
await storage.set({profiles, profileIndex});
}

View File

@@ -19,6 +19,10 @@ input {
width: 100%;
}
.profile-buttons {
width: 100%;
}
#priv-key, #pub-key {
font-family: monospace;
}
@@ -32,6 +36,10 @@ input {
margin-bottom: 15px;
}
.profile-name {
margin-bottom: 15px;
}
.key {
margin-bottom: 15px;
}

View File

@@ -9,12 +9,16 @@
<body x-data="popup">
<div class="profiles">
<label for="profile">Profile</label>
<div class="profile-buttons">
<select x-model.number="profileIndex" name="profile" id="profile">
<template x-for="(prof, index) in profileNames" :key="index">
<option x-text="prof" :value="index"></option>
</template>
</select>
<button @click="newProfile">New</button>
<button @click="confirmDelete = true" x-show="!confirmDelete" :disabled="profileNames.length <= 1">Delete</button>
<button @click="await deleteProfile()" x-show="confirmDelete">Confirm Delete</button>
</div>
</div>
<div class="profile-name">

View File

@@ -10,6 +10,7 @@ Alpine.data('popup', () => ({
profileIndex: 0,
visibleKey: false,
confirmClear: false,
confirmDelete: false,
async init() {
console.log("Initializing backend.");
@@ -88,6 +89,12 @@ Alpine.data('popup', () => ({
this.confirmClear = false;
},
async deleteProfile() {
await browser.runtime.sendMessage({kind: 'deleteProfile'});
await this.init();
this.confirmDelete = false;
},
// Properties
get hasValidPubKey() {