Fix scan, chat scrolling

This commit is contained in:
Jonathan Staab 2023-10-17 10:26:43 -07:00
parent ca3a7b073e
commit 320e8abd59
4 changed files with 36 additions and 26 deletions

View File

@ -2,6 +2,7 @@
import cx from "classnames"
import {identity, map} from "ramda"
import {tryFunc} from "hurdak"
import {throttle} from "throttle-debounce"
import {nip05, nip19} from "nostr-tools"
import {onMount} from "svelte"
import {fuzzy} from "src/util/misc"
@ -50,6 +51,7 @@
const hideSearch = () => {
term = ""
searchIsOpen = false
scanner?.stop()
}
const showScan = () => {
@ -67,31 +69,39 @@
router.at("people").of(pubkey).open()
}
const tryParseEntity = async entity => {
entity = fromNostrURI(entity)
const tryParseEntity = throttle(
500,
async entity => {
entity = fromNostrURI(entity)
if (entity.length < 5) {
return
}
if (isHex(entity)) {
router.at("people").of(entity).open()
hideSearch()
} else if (entity.includes("@")) {
let profile = await nip05.queryProfile(entity)
if (profile) {
router.at("people").of(nip19.nprofileEncode(profile)).open()
hideSearch()
if (entity.length < 5) {
return
}
} else {
tryFunc(() => {
nip19.decode(entity)
router.at(entity).open()
if (isHex(entity)) {
router.at("people").of(entity).open()
hideSearch()
})
} else if (entity.includes("@")) {
let profile = await nip05.queryProfile(entity)
if (profile) {
const {pubkey, relays} = profile
router.at("people").of(pubkey, {relays}).open()
hideSearch()
}
} else {
tryFunc(() => {
nip19.decode(entity)
router.at(entity).open()
hideSearch()
})
}
},
{
noTrailing: true,
}
}
)
const topicOptions = topics.derived(
map((topic: Topic) => ({type: "topic", id: topic.name, topic, text: "#" + topic.name}))

View File

@ -126,6 +126,8 @@ router.extend("media", encodeURIComponent)
router.extend("notes", (id, {relays = []} = {}) =>
relays ? nip19.neventEncode({id, relays}) : nip19.noteEncode(id)
)
router.extend("people", pubkey => nip19.nprofileEncode({pubkey, relays: getPubkeyHints(pubkey)}))
router.extend("people", (pubkey, {relays = []} = {}) =>
nip19.nprofileEncode({pubkey, relays: relays.concat(getPubkeyHints(pubkey))})
)
router.extend("relays", nip19.nrelayEncode)
router.extend("channels", getNip24ChannelId)

View File

@ -41,7 +41,7 @@
export const isStartOrEnd = i => isNewline(i - 1) || isNewline(i + 1)
</script>
<div class="flex flex-col gap-2 overflow-hidden text-ellipsis">
<div class="flex max-w-full flex-col gap-2 overflow-hidden text-ellipsis">
<p>
{#each shortContent as { type, value }, i}
{#if type === NEWLINE}

View File

@ -32,9 +32,7 @@
scroller.stop()
})
const scrollToBottom = () => {
container.scrollIntoView({behavior: "smooth", block: "end"})
}
const scrollToBottom = () => container.childNodes[0].scrollIntoView({behavior: "smooth"})
const stickToBottom = async () => {
const lastMessage = pluck("created_at", groupedMessages).reduce(max, 0)