feat: update note and user urls

This commit is contained in:
codytseng
2024-12-17 10:19:59 +08:00
parent 2ae92abdf7
commit d1eba4eb09
5 changed files with 20 additions and 8 deletions

View File

@@ -48,7 +48,7 @@ export default function Note({
className="mt-2"
onClick={(e) => {
e.stopPropagation()
push(toNote(parentEvent.id))
push(toNote(parentEvent))
}}
/>
)}

View File

@@ -29,7 +29,7 @@ export default function ShortTextNoteCard({
className={className}
onClick={(e) => {
e.stopPropagation()
push(toNote(event.id))
push(toNote(event))
}}
>
<RepostDescription reposter={reposter} className="max-sm:hidden pl-4" />

View File

@@ -167,7 +167,7 @@ function ReplyNotification({ notification }: { notification: Event }) {
return (
<div
className="flex gap-2 items-center cursor-pointer py-2"
onClick={() => push(toNote(notification.id))}
onClick={() => push(toNote(notification))}
>
<UserAvatar userId={notification.pubkey} size="small" />
<MessageCircle size={24} className="text-blue-400" />
@@ -197,7 +197,7 @@ function RepostNotification({ notification }: { notification: Event }) {
return (
<div
className="flex gap-2 items-center cursor-pointer py-2"
onClick={() => push(toNote(event.id))}
onClick={() => push(toNote(event))}
>
<UserAvatar userId={notification.pubkey} size="small" />
<Repeat size={24} className="text-green-400" />

View File

@@ -1,5 +1,11 @@
import { Event, nip19 } from 'nostr-tools'
export const toHome = () => '/'
export const toNote = (eventId: string) => `/notes/${eventId}`
export const toNote = (eventOrId: Event | string) => {
if (typeof eventOrId === 'string') return `/notes/${eventOrId}`
const nevent = nip19.neventEncode({ id: eventOrId.id, author: eventOrId.pubkey })
return `/notes/${nevent}`
}
export const toNoteList = ({
hashtag,
search,
@@ -16,14 +22,20 @@ export const toNoteList = ({
if (relay) query.set('relay', relay)
return `${path}?${query.toString()}`
}
export const toProfile = (pubkey: string) => `/users/${pubkey}`
export const toProfile = (pubkey: string) => {
const npub = nip19.npubEncode(pubkey)
return `/users/${npub}`
}
export const toProfileList = ({ search }: { search?: string }) => {
const path = '/users'
const query = new URLSearchParams()
if (search) query.set('s', search)
return `${path}?${query.toString()}`
}
export const toFollowingList = (pubkey: string) => `/users/${pubkey}/following`
export const toFollowingList = (pubkey: string) => {
const npub = nip19.npubEncode(pubkey)
return `/users/${npub}/following`
}
export const toRelaySettings = () => '/relay-settings'
export const toNotifications = () => '/notifications'

View File

@@ -53,7 +53,7 @@ function ParentNote({ eventId }: { eventId?: string }) {
<div>
<Card
className="flex space-x-1 p-1 items-center hover:bg-muted/50 cursor-pointer text-sm text-muted-foreground hover:text-foreground"
onClick={() => push(toNote(event.id))}
onClick={() => push(toNote(event))}
>
<UserAvatar userId={event.pubkey} size="tiny" />
<Username userId={event.pubkey} className="font-semibold" skeletonClassName="h-4" />