Accept hex pubkeys/npubs/nprofiles in ProfileMultiSelect
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
<script lang="ts">
|
||||
import * as nip19 from "nostr-tools/nip19"
|
||||
import {writable} from "svelte/store"
|
||||
import type {Writable} from "svelte/store"
|
||||
import {type Instance} from "tippy.js"
|
||||
@@ -35,6 +36,26 @@
|
||||
value = remove(pubkey, value)
|
||||
}
|
||||
|
||||
const onInput = (e: any) => {
|
||||
if (e.target.value.match(/^[a-f0-9]{64}$/)) {
|
||||
selectPubkey(e.target.value)
|
||||
}
|
||||
|
||||
try {
|
||||
const {type, data} = nip19.decode(e.target.value) as any
|
||||
|
||||
if (type === "npub") {
|
||||
selectPubkey(data)
|
||||
}
|
||||
|
||||
if (type === "nprofile") {
|
||||
selectPubkey(data.pubkey)
|
||||
}
|
||||
} catch (e) {
|
||||
// pass
|
||||
}
|
||||
}
|
||||
|
||||
const onKeyDown = (e: Event) => {
|
||||
if (instance.onKeyDown(e)) {
|
||||
e.preventDefault()
|
||||
@@ -80,6 +101,7 @@
|
||||
type="text"
|
||||
placeholder="Search for profiles..."
|
||||
bind:value={$term}
|
||||
oninput={onInput}
|
||||
onkeydown={onKeyDown} />
|
||||
</label>
|
||||
<Tippy
|
||||
|
||||
@@ -76,9 +76,8 @@
|
||||
onclick={stopPropagation(preventDefault(() => select(value)))}>
|
||||
<Component {value}></Component>
|
||||
</button>
|
||||
{:else}
|
||||
<div class="tiptap-suggestions__item">No results</div>
|
||||
{/each}
|
||||
</div>
|
||||
{#if items.length === 0}
|
||||
<div class="tiptap-suggestions__empty">No results</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user