parent
efad0f44f5
commit
0ee3dba906
@ -116,14 +116,20 @@ export const Profile = ({ pubkey }: ProfileProps) => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Try to encode
|
||||||
let profileRoute = appRoutes.home
|
let profileRoute = appRoutes.home
|
||||||
|
let nprofile: string | undefined
|
||||||
|
try {
|
||||||
const hexPubkey = npubToHex(pubkey)
|
const hexPubkey = npubToHex(pubkey)
|
||||||
if (hexPubkey) {
|
nprofile = hexPubkey
|
||||||
profileRoute = getProfilePageRoute(
|
? nip19.nprofileEncode({
|
||||||
nip19.nprofileEncode({
|
|
||||||
pubkey: hexPubkey
|
pubkey: hexPubkey
|
||||||
})
|
})
|
||||||
)
|
: undefined
|
||||||
|
profileRoute = nprofile ? getProfilePageRoute(nprofile) : appRoutes.home
|
||||||
|
} catch (error) {
|
||||||
|
// Silently ignore and redirect to home
|
||||||
|
log(true, LogType.Error, 'Failed to encode profile.', error)
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -148,7 +154,8 @@ export const Profile = ({ pubkey }: ProfileProps) => {
|
|||||||
<div className='IBMSMSMSSS_Author_Top_Left_InsideDetails'>
|
<div className='IBMSMSMSSS_Author_Top_Left_InsideDetails'>
|
||||||
<div className='IBMSMSMSSS_Author_TopWrapper'>
|
<div className='IBMSMSMSSS_Author_TopWrapper'>
|
||||||
<p className='IBMSMSMSSS_Author_Top_Name'>{displayName}</p>
|
<p className='IBMSMSMSSS_Author_Top_Name'>{displayName}</p>
|
||||||
{nip05 && (
|
{/* Nip05 can sometimes be an empty object '{}' which causes the error */}
|
||||||
|
{typeof nip05 === 'string' && (
|
||||||
<p className='IBMSMSMSSS_Author_Top_Handle'>{nip05}</p>
|
<p className='IBMSMSMSSS_Author_Top_Handle'>{nip05}</p>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
@ -181,8 +188,12 @@ export const Profile = ({ pubkey }: ProfileProps) => {
|
|||||||
<path d='M384 96L384 0h-112c-26.51 0-48 21.49-48 48v288c0 26.51 21.49 48 48 48H464c26.51 0 48-21.49 48-48V128h-95.1C398.4 128 384 113.6 384 96zM416 0v96h96L416 0zM192 352V128h-144c-26.51 0-48 21.49-48 48v288c0 26.51 21.49 48 48 48h192c26.51 0 48-21.49 48-48L288 416h-32C220.7 416 192 387.3 192 352z'></path>
|
<path d='M384 96L384 0h-112c-26.51 0-48 21.49-48 48v288c0 26.51 21.49 48 48 48H464c26.51 0 48-21.49 48-48V128h-95.1C398.4 128 384 113.6 384 96zM416 0v96h96L416 0zM192 352V128h-144c-26.51 0-48 21.49-48 48v288c0 26.51 21.49 48 48 48h192c26.51 0 48-21.49 48-48L288 416h-32C220.7 416 192 387.3 192 352z'></path>
|
||||||
</svg>
|
</svg>
|
||||||
</div>
|
</div>
|
||||||
<ProfileQRButtonWithPopUp pubkey={pubkey} />
|
{typeof nprofile !== 'undefined' && (
|
||||||
{lud16 && <ZapButtonWithPopUp pubkey={pubkey} />}
|
<ProfileQRButtonWithPopUp nprofile={nprofile} />
|
||||||
|
)}
|
||||||
|
{typeof lud16 !== 'undefined' && (
|
||||||
|
<ZapButtonWithPopUp pubkey={pubkey} />
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -227,20 +238,16 @@ const posts: Post[] = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
type QRButtonWithPopUpProps = {
|
type QRButtonWithPopUpProps = {
|
||||||
pubkey: string
|
nprofile: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export const ProfileQRButtonWithPopUp = ({
|
export const ProfileQRButtonWithPopUp = ({
|
||||||
pubkey
|
nprofile
|
||||||
}: QRButtonWithPopUpProps) => {
|
}: QRButtonWithPopUpProps) => {
|
||||||
const [isOpen, setIsOpen] = useState(false)
|
const [isOpen, setIsOpen] = useState(false)
|
||||||
|
|
||||||
useBodyScrollDisable(isOpen)
|
useBodyScrollDisable(isOpen)
|
||||||
|
|
||||||
const nprofile = nip19.nprofileEncode({
|
|
||||||
pubkey
|
|
||||||
})
|
|
||||||
|
|
||||||
const onQrCodeClicked = async () => {
|
const onQrCodeClicked = async () => {
|
||||||
const href = `https://njump.me/${nprofile}`
|
const href = `https://njump.me/${nprofile}`
|
||||||
const a = document.createElement('a')
|
const a = document.createElement('a')
|
||||||
|
@ -23,6 +23,8 @@ import { FilterOptions, ModDetails, UserRelaysType } from 'types'
|
|||||||
import {
|
import {
|
||||||
copyTextToClipboard,
|
copyTextToClipboard,
|
||||||
DEFAULT_FILTER_OPTIONS,
|
DEFAULT_FILTER_OPTIONS,
|
||||||
|
log,
|
||||||
|
LogType,
|
||||||
now,
|
now,
|
||||||
npubToHex,
|
npubToHex,
|
||||||
scrollIntoView,
|
scrollIntoView,
|
||||||
@ -42,8 +44,8 @@ export const ProfilePage = () => {
|
|||||||
: undefined
|
: undefined
|
||||||
profilePubkey = value?.data.pubkey
|
profilePubkey = value?.data.pubkey
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// Failed to decode the nprofile
|
|
||||||
// Silently ignore and redirect to home or logged in user
|
// Silently ignore and redirect to home or logged in user
|
||||||
|
log(true, LogType.Error, 'Failed to decode nprofile.', error)
|
||||||
}
|
}
|
||||||
|
|
||||||
const scrollTargetRef = useRef<HTMLDivElement>(null)
|
const scrollTargetRef = useRef<HTMLDivElement>(null)
|
||||||
|
@ -37,7 +37,8 @@ import {
|
|||||||
isModDataComplete,
|
isModDataComplete,
|
||||||
log,
|
log,
|
||||||
LogType,
|
LogType,
|
||||||
scrollIntoView
|
scrollIntoView,
|
||||||
|
timeout
|
||||||
} from 'utils'
|
} from 'utils'
|
||||||
|
|
||||||
enum SearchKindEnum {
|
enum SearchKindEnum {
|
||||||
@ -373,29 +374,38 @@ const UsersResult = ({
|
|||||||
if (searchTerm === '') {
|
if (searchTerm === '') {
|
||||||
setProfiles([])
|
setProfiles([])
|
||||||
} else {
|
} else {
|
||||||
|
const fetchProfiles = async () => {
|
||||||
|
setIsFetching(true)
|
||||||
|
|
||||||
const filter: NDKFilter = {
|
const filter: NDKFilter = {
|
||||||
kinds: [NDKKind.Metadata],
|
kinds: [NDKKind.Metadata],
|
||||||
search: searchTerm
|
search: searchTerm
|
||||||
}
|
}
|
||||||
|
|
||||||
setIsFetching(true)
|
const profiles = await Promise.race([
|
||||||
fetchEvents(filter)
|
fetchEvents(filter),
|
||||||
|
timeout(10 * 1000)
|
||||||
|
])
|
||||||
.then((events) => {
|
.then((events) => {
|
||||||
const results = events.map((event) => {
|
const results = events.map((event) => {
|
||||||
const ndkEvent = new NDKEvent(undefined, event)
|
const ndkEvent = new NDKEvent(undefined, event)
|
||||||
const profile = profileFromEvent(ndkEvent)
|
const profile = profileFromEvent(ndkEvent)
|
||||||
return profile
|
return profile
|
||||||
})
|
})
|
||||||
setProfiles(results)
|
return results
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
log(true, LogType.Error, 'An error occurred in fetching users', err)
|
log(true, LogType.Error, 'An error occurred in fetching users', err)
|
||||||
|
return []
|
||||||
})
|
})
|
||||||
.finally(() => {
|
|
||||||
|
setProfiles(profiles)
|
||||||
setIsFetching(false)
|
setIsFetching(false)
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}, [searchTerm, fetchEvents])
|
|
||||||
|
fetchProfiles()
|
||||||
|
}
|
||||||
|
}, [fetchEvents, searchTerm])
|
||||||
|
|
||||||
const filteredProfiles = useMemo(() => {
|
const filteredProfiles = useMemo(() => {
|
||||||
let filtered = [...profiles]
|
let filtered = [...profiles]
|
||||||
|
@ -98,15 +98,15 @@ export const ProfileSettings = () => {
|
|||||||
|
|
||||||
// In case user is not logged in clicking on profile link will navigate to homepage
|
// In case user is not logged in clicking on profile link will navigate to homepage
|
||||||
let profileRoute = appRoutes.home
|
let profileRoute = appRoutes.home
|
||||||
|
let nprofile: string | undefined
|
||||||
if (userState.auth && userState.user) {
|
if (userState.auth && userState.user) {
|
||||||
const hexPubkey = npubToHex(userState.user.npub as string)
|
const hexPubkey = npubToHex(userState.user.npub as string)
|
||||||
|
|
||||||
if (hexPubkey) {
|
if (hexPubkey) {
|
||||||
profileRoute = getProfilePageRoute(
|
nprofile = nip19.nprofileEncode({
|
||||||
nip19.nprofileEncode({
|
|
||||||
pubkey: hexPubkey
|
pubkey: hexPubkey
|
||||||
})
|
})
|
||||||
)
|
profileRoute = getProfilePageRoute(nprofile)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -247,10 +247,8 @@ export const ProfileSettings = () => {
|
|||||||
<path d='M384 96L384 0h-112c-26.51 0-48 21.49-48 48v288c0 26.51 21.49 48 48 48H464c26.51 0 48-21.49 48-48V128h-95.1C398.4 128 384 113.6 384 96zM416 0v96h96L416 0zM192 352V128h-144c-26.51 0-48 21.49-48 48v288c0 26.51 21.49 48 48 48h192c26.51 0 48-21.49 48-48L288 416h-32C220.7 416 192 387.3 192 352z'></path>
|
<path d='M384 96L384 0h-112c-26.51 0-48 21.49-48 48v288c0 26.51 21.49 48 48 48H464c26.51 0 48-21.49 48-48V128h-95.1C398.4 128 384 113.6 384 96zM416 0v96h96L416 0zM192 352V128h-144c-26.51 0-48 21.49-48 48v288c0 26.51 21.49 48 48 48h192c26.51 0 48-21.49 48-48L288 416h-32C220.7 416 192 387.3 192 352z'></path>
|
||||||
</svg>
|
</svg>
|
||||||
</div>
|
</div>
|
||||||
{typeof userState.user?.pubkey === 'string' && (
|
{typeof nprofile !== 'undefined' && (
|
||||||
<ProfileQRButtonWithPopUp
|
<ProfileQRButtonWithPopUp nprofile={nprofile} />
|
||||||
pubkey={userState.user.pubkey}
|
|
||||||
/>
|
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user