chore: make some minor adjustments
This commit is contained in:
parent
dd33a62095
commit
ab285b0e97
13 changed files with 49 additions and 32 deletions
|
|
@ -1,10 +1,10 @@
|
|||
import { useFetchEventById } from '@renderer/hooks'
|
||||
import { useFetchEvent } from '@renderer/hooks'
|
||||
import { toNoStrudelArticle, toNoStrudelNote } from '@renderer/lib/link'
|
||||
import { kinds } from 'nostr-tools'
|
||||
import ShortTextNoteCard from '../NoteCard/ShortTextNoteCard'
|
||||
|
||||
export function EmbeddedNote({ noteId }: { noteId: string }) {
|
||||
const { event } = useFetchEventById(noteId)
|
||||
const { event } = useFetchEvent(noteId)
|
||||
|
||||
return event && event.kind === kinds.ShortTextNote ? (
|
||||
<ShortTextNoteCard size="small" className="mt-2 w-full" event={event} hideStats />
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ export default function LoginDialog({
|
|||
<Dialog open={open} onOpenChange={setOpen}>
|
||||
<DialogContent className="w-80">
|
||||
<DialogHeader>
|
||||
<DialogTitle />
|
||||
<DialogTitle className="hidden" />
|
||||
<DialogDescription className="text-destructive">
|
||||
{!canLogin && 'Encryption is not available in your device.'}
|
||||
</DialogDescription>
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
import { Event } from 'nostr-tools'
|
||||
import { Card } from '@renderer/components/ui/card'
|
||||
import { useFetchEvent } from '@renderer/hooks'
|
||||
import { getParentEventId, getRootEventId } from '@renderer/lib/event'
|
||||
import { toNote } from '@renderer/lib/link'
|
||||
import { useSecondaryPage } from '@renderer/PageManager'
|
||||
import { Event } from 'nostr-tools'
|
||||
import Note from '../Note'
|
||||
import { useFetchEventById } from '@renderer/hooks'
|
||||
import { getParentEventId, getRootEventId } from '@renderer/lib/event'
|
||||
|
||||
export default function ShortTextNoteCard({
|
||||
event,
|
||||
|
|
@ -18,8 +18,8 @@ export default function ShortTextNoteCard({
|
|||
hideStats?: boolean
|
||||
}) {
|
||||
const { push } = useSecondaryPage()
|
||||
const { event: rootEvent } = useFetchEventById(getRootEventId(event))
|
||||
const { event: parentEvent } = useFetchEventById(getParentEventId(event))
|
||||
const { event: rootEvent } = useFetchEvent(getRootEventId(event))
|
||||
const { event: parentEvent } = useFetchEvent(getParentEventId(event))
|
||||
|
||||
return (
|
||||
<div
|
||||
|
|
|
|||
|
|
@ -1,4 +1,10 @@
|
|||
import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@renderer/components/ui/dialog'
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogHeader,
|
||||
DialogTitle
|
||||
} from '@renderer/components/ui/dialog'
|
||||
import { ScrollArea, ScrollBar } from '@renderer/components/ui/scroll-area'
|
||||
import { Event } from 'nostr-tools'
|
||||
|
||||
|
|
@ -16,6 +22,7 @@ export default function RawEventDialog({
|
|||
<DialogContent className="h-[60vh]">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Raw Event</DialogTitle>
|
||||
<DialogDescription className="hidden" />
|
||||
</DialogHeader>
|
||||
<ScrollArea className="h-full">
|
||||
<pre className="text-sm overflow-x-auto text-muted-foreground">
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ export default function PostDialog({
|
|||
t('New post')
|
||||
)}
|
||||
</DialogTitle>
|
||||
<DialogDescription />
|
||||
<DialogDescription className="hidden" />
|
||||
</DialogHeader>
|
||||
<Textarea
|
||||
className="h-32"
|
||||
|
|
|
|||
|
|
@ -3,7 +3,13 @@ import { Command as CommandPrimitive } from 'cmdk'
|
|||
import { Search } from 'lucide-react'
|
||||
import * as React from 'react'
|
||||
|
||||
import { Dialog, DialogContent } from '@renderer/components/ui/dialog'
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogHeader,
|
||||
DialogTitle
|
||||
} from '@renderer/components/ui/dialog'
|
||||
import { ScrollArea } from '@renderer/components/ui/scroll-area'
|
||||
import { cn } from '@renderer/lib/utils'
|
||||
|
||||
|
|
@ -25,6 +31,10 @@ Command.displayName = CommandPrimitive.displayName
|
|||
const CommandDialog = ({ children, ...props }: DialogProps) => {
|
||||
return (
|
||||
<Dialog {...props}>
|
||||
<DialogHeader className="hidden">
|
||||
<DialogTitle />
|
||||
<DialogDescription />
|
||||
</DialogHeader>
|
||||
<DialogContent className="overflow-hidden p-0 shadow-lg top-4 translate-y-0 data-[state=closed]:slide-out-to-top-0 data-[state=open]:slide-in-from-top-0">
|
||||
<Command
|
||||
shouldFilter={false}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
export * from './use-toast'
|
||||
export * from './useFetchEventById'
|
||||
export * from './useFetchEvent'
|
||||
export * from './useFetchFollowings'
|
||||
export * from './useFetchNip05'
|
||||
export * from './useFetchProfile'
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import client from '@renderer/services/client.service'
|
|||
import { Event } from 'nostr-tools'
|
||||
import { useEffect, useState } from 'react'
|
||||
|
||||
export function useFetchEventById(id?: string) {
|
||||
export function useFetchEvent(id?: string) {
|
||||
const [isFetching, setIsFetching] = useState(true)
|
||||
const [error, setError] = useState<Error | null>(null)
|
||||
const [event, setEvent] = useState<Event | undefined>(undefined)
|
||||
|
|
@ -17,7 +17,7 @@ export function useFetchEventById(id?: string) {
|
|||
}
|
||||
|
||||
try {
|
||||
const event = await client.fetchEventByBench32Id(id)
|
||||
const event = await client.fetchEvent(id)
|
||||
if (event) {
|
||||
setEvent(event)
|
||||
}
|
||||
|
|
@ -17,7 +17,7 @@ export function useFetchProfile(id?: string) {
|
|||
return
|
||||
}
|
||||
|
||||
const profile = await client.fetchProfileByBench32Id(id)
|
||||
const profile = await client.fetchProfile(id)
|
||||
if (profile) {
|
||||
setProfile(profile)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ export async function extractMentions(content: string, parentEvent?: Event) {
|
|||
} else if (type === 'npub') {
|
||||
pubkeySet.add(data)
|
||||
} else if (['nevent', 'note', 'naddr'].includes(type)) {
|
||||
const event = await client.fetchEventByBench32Id(id)
|
||||
const event = await client.fetchEvent(id)
|
||||
if (event) {
|
||||
pubkeySet.add(event.pubkey)
|
||||
quoteEventIdSet.add(event.id)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import Username from '@renderer/components/Username'
|
|||
import { Card } from '@renderer/components/ui/card'
|
||||
import { Separator } from '@renderer/components/ui/separator'
|
||||
import { Skeleton } from '@renderer/components/ui/skeleton'
|
||||
import { useFetchEventById } from '@renderer/hooks'
|
||||
import { useFetchEvent } from '@renderer/hooks'
|
||||
import SecondaryPageLayout from '@renderer/layouts/SecondaryPageLayout'
|
||||
import { getParentEventId, getRootEventId } from '@renderer/lib/event'
|
||||
import { toNote } from '@renderer/lib/link'
|
||||
|
|
@ -16,7 +16,7 @@ import { useTranslation } from 'react-i18next'
|
|||
|
||||
export default function NotePage({ id }: { id?: string }) {
|
||||
const { t } = useTranslation()
|
||||
const { event, isFetching } = useFetchEventById(id)
|
||||
const { event, isFetching } = useFetchEvent(id)
|
||||
const parentEventId = useMemo(() => getParentEventId(event), [event])
|
||||
const rootEventId = useMemo(() => getRootEventId(event), [event])
|
||||
|
||||
|
|
@ -42,7 +42,7 @@ export default function NotePage({ id }: { id?: string }) {
|
|||
|
||||
function ParentNote({ eventId }: { eventId?: string }) {
|
||||
const { push } = useSecondaryPage()
|
||||
const { event } = useFetchEventById(eventId)
|
||||
const { event } = useFetchEvent(eventId)
|
||||
if (!event) return null
|
||||
|
||||
return (
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ class ClientService {
|
|||
|
||||
private eventCache = new LRUCache<string, Promise<NEvent | undefined>>({ max: 10000 })
|
||||
private eventDataLoader = new DataLoader<string, NEvent | undefined>(
|
||||
(ids) => Promise.all(ids.map((id) => this._fetchEventByBench32Id(id))),
|
||||
(ids) => Promise.all(ids.map((id) => this._fetchEvent(id))),
|
||||
{ cacheMap: this.eventCache }
|
||||
)
|
||||
private fetchEventFromBigRelaysDataloader = new DataLoader<string, NEvent | undefined>(
|
||||
|
|
@ -42,7 +42,7 @@ class ClientService {
|
|||
})
|
||||
private profileCache = new LRUCache<string, Promise<TProfile>>({ max: 10000 })
|
||||
private profileDataloader = new DataLoader<string, TProfile>(
|
||||
(ids) => Promise.all(ids.map((id) => this._fetchProfileByBench32Id(id))),
|
||||
(ids) => Promise.all(ids.map((id) => this._fetchProfile(id))),
|
||||
{ cacheMap: this.profileCache }
|
||||
)
|
||||
private fetchProfileFromBigRelaysDataloader = new DataLoader<string, TProfile | undefined>(
|
||||
|
|
@ -58,13 +58,14 @@ class ClientService {
|
|||
private relayInfoDataLoader = new DataLoader<string, TRelayInfo | undefined>(async (urls) => {
|
||||
return await Promise.all(
|
||||
urls.map(async (url) => {
|
||||
return (await (
|
||||
await fetch(url.replace('ws://', 'http://').replace('wss://', 'https://'), {
|
||||
try {
|
||||
const res = await fetch(url.replace('ws://', 'http://').replace('wss://', 'https://'), {
|
||||
headers: { Accept: 'application/nostr+json' }
|
||||
})
|
||||
)
|
||||
.json()
|
||||
.catch(() => undefined)) as TRelayInfo | undefined
|
||||
return res.json() as TRelayInfo
|
||||
} catch {
|
||||
return undefined
|
||||
}
|
||||
})
|
||||
)
|
||||
})
|
||||
|
|
@ -290,7 +291,7 @@ class ClientService {
|
|||
return events
|
||||
}
|
||||
|
||||
async fetchEventByBench32Id(id: string): Promise<NEvent | undefined> {
|
||||
async fetchEvent(id: string): Promise<NEvent | undefined> {
|
||||
if (!/^[0-9a-f]{64}$/.test(id)) {
|
||||
let eventId: string | undefined
|
||||
const { type, data } = nip19.decode(id)
|
||||
|
|
@ -316,7 +317,7 @@ class ClientService {
|
|||
this.eventDataLoader.prime(event.id, Promise.resolve(event))
|
||||
}
|
||||
|
||||
async fetchProfileByBench32Id(id: string): Promise<TProfile | undefined> {
|
||||
async fetchProfile(id: string): Promise<TProfile | undefined> {
|
||||
if (!/^[0-9a-f]{64}$/.test(id)) {
|
||||
let pubkey: string | undefined
|
||||
const { data, type } = nip19.decode(id)
|
||||
|
|
@ -381,7 +382,7 @@ class ClientService {
|
|||
return this.tryHarderToFetchEvent(relayUrls, { ids: [id], limit: 1 }, true)
|
||||
}
|
||||
|
||||
private async _fetchEventByBench32Id(id: string): Promise<NEvent | undefined> {
|
||||
private async _fetchEvent(id: string): Promise<NEvent | undefined> {
|
||||
let filter: Filter | undefined
|
||||
let relays: string[] = []
|
||||
if (/^[0-9a-f]{64}$/.test(id)) {
|
||||
|
|
@ -426,7 +427,7 @@ class ClientService {
|
|||
return event
|
||||
}
|
||||
|
||||
private async _fetchProfileByBench32Id(id: string): Promise<TProfile> {
|
||||
private async _fetchProfile(id: string): Promise<TProfile> {
|
||||
let pubkey: string | undefined
|
||||
let relays: string[] = []
|
||||
if (/^[0-9a-f]{64}$/.test(id)) {
|
||||
|
|
|
|||
|
|
@ -23,8 +23,7 @@ class WebService {
|
|||
?.content
|
||||
|
||||
return { title, description, image }
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
} catch {
|
||||
return {}
|
||||
}
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue