Browse Source

feat: update note and user urls

imwald
codytseng 1 year ago
parent
commit
d1eba4eb09
  1. 2
      src/renderer/src/components/Note/index.tsx
  2. 2
      src/renderer/src/components/NoteCard/ShortTextNoteCard.tsx
  3. 4
      src/renderer/src/components/NotificationList/index.tsx
  4. 18
      src/renderer/src/lib/link.ts
  5. 2
      src/renderer/src/pages/secondary/NotePage/index.tsx

2
src/renderer/src/components/Note/index.tsx

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

2
src/renderer/src/components/NoteCard/ShortTextNoteCard.tsx

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

4
src/renderer/src/components/NotificationList/index.tsx

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

18
src/renderer/src/lib/link.ts

@ -1,5 +1,11 @@
import { Event, nip19 } from 'nostr-tools'
export const toHome = () => '/' 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 = ({ export const toNoteList = ({
hashtag, hashtag,
search, search,
@ -16,14 +22,20 @@ export const toNoteList = ({
if (relay) query.set('relay', relay) if (relay) query.set('relay', relay)
return `${path}?${query.toString()}` 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 }) => { export const toProfileList = ({ search }: { search?: string }) => {
const path = '/users' const path = '/users'
const query = new URLSearchParams() const query = new URLSearchParams()
if (search) query.set('s', search) if (search) query.set('s', search)
return `${path}?${query.toString()}` 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 toRelaySettings = () => '/relay-settings'
export const toNotifications = () => '/notifications' export const toNotifications = () => '/notifications'

2
src/renderer/src/pages/secondary/NotePage/index.tsx

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

Loading…
Cancel
Save