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': case 'clearData':
await browser.storage.local.clear(); await browser.storage.local.clear();
break; break;
case 'deleteProfile':
await deleteProfile();
break;
default: default:
break; break;
} }
@@ -122,4 +125,12 @@ async function saveProfile(profile) {
let profiles = await get('profiles'); let profiles = await get('profiles');
profiles[index] = profile; profiles[index] = profile;
await storage.set({profiles}); 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%; width: 100%;
} }
.profile-buttons {
width: 100%;
}
#priv-key, #pub-key { #priv-key, #pub-key {
font-family: monospace; font-family: monospace;
} }
@@ -32,6 +36,10 @@ input {
margin-bottom: 15px; margin-bottom: 15px;
} }
.profile-name {
margin-bottom: 15px;
}
.key { .key {
margin-bottom: 15px; margin-bottom: 15px;
} }

View File

@@ -9,12 +9,16 @@
<body x-data="popup"> <body x-data="popup">
<div class="profiles"> <div class="profiles">
<label for="profile">Profile</label> <label for="profile">Profile</label>
<select x-model.number="profileIndex" name="profile" id="profile"> <div class="profile-buttons">
<template x-for="(prof, index) in profileNames" :key="index"> <select x-model.number="profileIndex" name="profile" id="profile">
<option x-text="prof" :value="index"></option> <template x-for="(prof, index) in profileNames" :key="index">
</template> <option x-text="prof" :value="index"></option>
</select> </template>
<button @click="newProfile">New</button> </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>
<div class="profile-name"> <div class="profile-name">

View File

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