Browse Source

fixed discussions fetch

imwald
Silberengel 5 months ago
parent
commit
a9f8e7e39b
  1. 73
      src/components/ErrorBoundary.tsx
  2. 7
      src/pages/primary/DiscussionsPage/index.tsx
  3. 2
      src/providers/DeletedEventProvider.tsx
  4. 36
      src/providers/NostrProvider/index.tsx

73
src/components/ErrorBoundary.tsx

@ -1,6 +1,9 @@ @@ -1,6 +1,9 @@
import { Button } from '@/components/ui/button'
import { RotateCw } from 'lucide-react'
import PostContent from '@/components/PostEditor/PostContent'
import { SILBERENGEL_PUBKEY } from '@/constants'
import { MessageCircle, RotateCw } from 'lucide-react'
import React, { Component, ReactNode } from 'react'
import { toast } from 'sonner'
interface ErrorBoundaryProps {
children: ReactNode
@ -9,16 +12,17 @@ interface ErrorBoundaryProps { @@ -9,16 +12,17 @@ interface ErrorBoundaryProps {
interface ErrorBoundaryState {
hasError: boolean
error?: Error
showErrorReportDialog: boolean
}
export class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {
constructor(props: ErrorBoundaryProps) {
super(props)
this.state = { hasError: false }
this.state = { hasError: false, showErrorReportDialog: false }
}
static getDerivedStateFromError(error: Error) {
return { hasError: true, error }
return { hasError: true, error, showErrorReportDialog: false }
}
componentDidCatch(error: Error, errorInfo: React.ErrorInfo) {
@ -31,45 +35,52 @@ export class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundarySt @@ -31,45 +35,52 @@ export class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundarySt
<div className="w-screen h-screen flex flex-col items-center justify-center p-4 gap-4">
<h1 className="text-2xl font-bold">Oops, something went wrong.</h1>
<p className="text-lg text-center max-w-md">
Sorry for the inconvenience. If you don't mind helping, you can{' '}
<a
href="https://github.com/CodyTseng/jumble/issues/new"
target="_blank"
rel="noopener noreferrer"
className="text-primary underline"
>
submit an issue on GitHub
</a>{' '}
with the error details, or{' '}
<a
href="https://jumble.social/npub1syjmjy0dp62dhccq3g97fr87tngvpvzey08llyt6ul58m2zqpzps9wf6wl"
target="_blank"
rel="noopener noreferrer"
className="text-primary underline"
>
mention me
</a>
. Thank you for your support!
Sorry for the inconvenience. You can help by sending me a public message with the error details.
</p>
{this.state.error?.message && (
<>
<Button
onClick={() => {
navigator.clipboard.writeText(this.state.error!.message)
}}
variant="secondary"
>
Copy Error Message
</Button>
<div className="flex gap-2">
<Button
onClick={() => {
this.setState({ showErrorReportDialog: true })
}}
className="bg-primary text-primary-foreground"
>
<MessageCircle className="w-4 h-4 mr-2" />
Send Error Report
</Button>
<Button
onClick={() => {
navigator.clipboard.writeText(this.state.error!.message)
toast.success('Error message copied to clipboard')
}}
variant="secondary"
>
Copy Error Message
</Button>
</div>
<pre className="bg-destructive/10 text-destructive p-2 rounded text-wrap break-words whitespace-pre-wrap">
Error: {this.state.error.message}
</pre>
</>
)}
<Button onClick={() => window.location.reload()} className="mt-2">
<RotateCw />
<RotateCw className="w-4 h-4 mr-2" />
Reload Page
</Button>
{this.state.showErrorReportDialog && (
<PostContent
defaultContent={`@${SILBERENGEL_PUBKEY} Jumble Error Report:
${this.state.error?.message || 'Unknown error'}
Please help investigate this issue. Thank you!`}
close={() => {
this.setState({ showErrorReportDialog: false })
}}
/>
)}
</div>
)
}

7
src/pages/primary/DiscussionsPage/index.tsx

@ -181,7 +181,7 @@ const DiscussionsPage = forwardRef((_, ref) => { @@ -181,7 +181,7 @@ const DiscussionsPage = forwardRef((_, ref) => {
}
updateRelayUrls()
}, [selectedRelay, availableRelays, relaySets, pubkey, favoriteRelays])
}, [selectedRelay, availableRelays, relaySets, pubkey])
// Available topic IDs for matching
const availableTopicIds = useMemo(() =>
@ -246,7 +246,10 @@ const DiscussionsPage = forwardRef((_, ref) => { @@ -246,7 +246,10 @@ const DiscussionsPage = forwardRef((_, ref) => {
const validThreads = events
.filter(event => {
// Filter out deleted events
if (isEventDeleted(event)) return false
if (isEventDeleted(event)) {
console.log(`Filtering out deleted event: ${event.id}`)
return false
}
// Ensure it has a title tag
const titleTag = event.tags.find(tag => tag[0] === 'title' && tag[1])

2
src/providers/DeletedEventProvider.tsx

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
import { getReplaceableCoordinateFromEvent, isReplaceableEvent } from '@/lib/event'
import { NostrEvent } from 'nostr-tools'
import { NostrEvent, kinds } from 'nostr-tools'
import { createContext, useCallback, useContext, useState } from 'react'
type TDeletedEventContext = {

36
src/providers/NostrProvider/index.tsx

@ -278,6 +278,42 @@ export function NostrProvider({ children }: { children: React.ReactNode }) { @@ -278,6 +278,42 @@ export function NostrProvider({ children }: { children: React.ReactNode }) {
}
setRelayList(relayList)
// Fetch deletion events to populate the deleted event keys
try {
const relays = relayList.read?.slice(0, 5) || []
if (relays.length > 0) {
// Fetch kind 5 (deletion) events from the last 30 days
const thirtyDaysAgo = Math.floor((Date.now() - (30 * 24 * 60 * 60 * 1000)) / 1000)
const deletionEvents = await client.fetchEvents(relays, {
kinds: [kinds.EventDeletion],
since: thirtyDaysAgo,
limit: 1000
})
// Process deletion events to extract deleted event IDs
const newDeletedKeys = new Set<string>()
for (const deletionEvent of deletionEvents) {
// Kind 5 events contain 'e' tags with the IDs of deleted events
const deletedEventTags = deletionEvent.tags.filter(tag => tag[0] === 'e' && tag[1])
for (const tag of deletedEventTags) {
const deletedEventId = tag[1]
if (deletedEventId) {
newDeletedKeys.add(deletedEventId)
// Also add to the DeletedEventProvider
addDeletedEvent({ id: deletedEventId } as Event)
}
}
}
console.log(`Fetched ${deletionEvents.length} deletion events, found ${newDeletedKeys.size} deleted event IDs`)
}
} catch (error) {
console.warn('Failed to fetch deletion events:', error)
}
const normalizedRelays = [
...relayList.write.map(url => normalizeUrl(url) || url),
...BIG_RELAY_URLS.map(url => normalizeUrl(url) || url)

Loading…
Cancel
Save