diff --git a/src/components/AppBar/AppBar.tsx b/src/components/AppBar/AppBar.tsx index a4f653e..e7f5d95 100644 --- a/src/components/AppBar/AppBar.tsx +++ b/src/components/AppBar/AppBar.tsx @@ -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('/') diff --git a/src/components/Footer/Footer.tsx b/src/components/Footer/Footer.tsx index 249b8c4..c7459e3 100644 --- a/src/components/Footer/Footer.tsx +++ b/src/components/Footer/Footer.tsx @@ -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) } diff --git a/src/pages/create/index.tsx b/src/pages/create/index.tsx index 212f7bf..0ce990f 100644 --- a/src/pages/create/index.tsx +++ b/src/pages/create/index.tsx @@ -148,6 +148,17 @@ export const CreatePage = () => { [setUserInput] ) + const handleSearchUserNip05 = async ( + nip05: string + ): Promise => { + 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) => { + const handleInputKeyDown = async ( + event: React.KeyboardEvent + ) => { 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 = () => { ) : (