Merge pull request 'Searching counterparts glitchy when includes @ (nip05)' (#273) from issue-270 into staging
All checks were successful
Release to Staging / build_and_release (push) Successful in 1m43s

Reviewed-on: #273
Reviewed-by: enes <enes@noreply.git.nostrdev.com>
This commit is contained in:
b 2024-12-10 15:37:00 +00:00
commit c3e4f6055c
3 changed files with 36 additions and 18 deletions

View File

@ -125,7 +125,7 @@ export const AppBar = () => {
src="/logo.svg"
alt="Logo"
onClick={() => {
if (window.location.pathname === '/') {
if (['', '#/'].includes(window.location.hash)) {
location.reload()
} else {
navigate('/')

View File

@ -69,7 +69,7 @@ export const Footer = () =>
component={Link}
to={'/'}
onClick={(event) => {
if (window.location.pathname === '/') {
if (['', '#/'].includes(window.location.hash)) {
event.preventDefault()
window.scrollTo(0, 0)
}

View File

@ -148,6 +148,17 @@ export const CreatePage = () => {
[setUserInput]
)
const handleSearchUserNip05 = async (
nip05: string
): Promise<string | null> => {
const { pubkey } = await queryNip05(nip05).catch((err) => {
console.error(err)
return { pubkey: null }
})
return pubkey
}
const handleSearchUsers = async (searchValue?: string) => {
const searchString = searchValue || userSearchInput || undefined
@ -224,7 +235,9 @@ export const CreatePage = () => {
})
}, [foundUsers])
const handleInputKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {
const handleInputKeyDown = async (
event: React.KeyboardEvent<HTMLDivElement>
) => {
if (
event.code === KeyboardCode.Enter ||
event.code === KeyboardCode.NumpadEnter
@ -238,7 +251,23 @@ export const CreatePage = () => {
} else {
// Otherwize if search already provided some results, user must manually click the search button
if (!foundUsers.length) {
handleSearchUsers()
// If it's NIP05 (includes @ or is a valid domain) send request to .well-known
const domainRegex = /^[a-zA-Z0-9@.-]+\.[a-zA-Z]{2,}$/
if (domainRegex.test(userSearchInput)) {
setSearchUsersLoading(true)
const pubkey = await handleSearchUserNip05(userSearchInput)
setSearchUsersLoading(false)
if (pubkey) {
setUserInput(userSearchInput)
} else {
toast.error(`No user found with the NIP05: ${userSearchInput}`)
}
} else {
handleSearchUsers()
}
}
}
}
@ -959,19 +988,6 @@ export const CreatePage = () => {
} else {
disarmAddOnEnter()
}
} else if (value.includes('@')) {
// Seems like it's nip05 format
const { pubkey } = await queryNip05(value).catch((err) => {
console.error(err)
return { pubkey: null }
})
if (pubkey) {
// Arm the manual user npub add after enter is hit, we don't want to trigger search
setPastedUserNpubOrNip05(hexToNpub(pubkey))
} else {
disarmAddOnEnter()
}
} else {
// Disarm the add user on enter hit, and trigger search after 1 second
disarmAddOnEnter()
@ -1146,7 +1162,9 @@ export const CreatePage = () => {
</Button>
) : (
<Button
onClick={handleAddUser}
onClick={() => {
setUserInput(userSearchInput)
}}
variant="contained"
aria-label="Add"
className={styles.counterpartToggleButton}