aboutsummaryrefslogtreecommitdiff
path: root/extension/src/entries/popup/Components/IdentitySelection.vue
blob: d1a73339f7d796884fa3e9137bd249ecebedd835 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<template>
    <div class="px-3 text-left">
       <div class="w-full">
            <div class="">
                <select class="w-full input" 
                :disabled="waiting"
                :value="selected?.Id"
                @change.prevent="onSelected"
                >
                    <option disabled value="">Select an identity</option>
                    <option v-for="key in allKeys" :value="key.Id">{{ key.UserName }}</option>
                </select>
            </div>
       </div>
       
    </div>
</template>

<script setup lang="ts">
import { find } from 'lodash'
import { computed } from "vue";
import { useStatus, useManagment, NostrPubKey } from "~/bg-api/popup.ts";
import { useWait } from '@vnuge/vnlib.browser'
import { computedAsync } from '@vueuse/core';

const { selectedKey } = useStatus();
const { waiting } = useWait();
const { getAllKeys, selectKey } = useManagment();

const allKeys = computedAsync<NostrPubKey[]>(async () => await getAllKeys(), []);

const onSelected = async ({target}) =>{
    //Select the key of the given id
    const selected = find(allKeys.value, {Id: target.value})
    if(selected){
        await selectKey(selected)
    }
}

const selected = computed(() => selectedKey?.value || { Id:"0" })

</script>

<style lang="scss">

</style>