mirror of
https://github.com/dergigi/boris.git
synced 2025-12-19 07:34:28 +01:00
refactor: use applesauce EventStore for offline event management
Major improvements: - Store highlights in EventStore immediately when created - Query EventStore instead of local relays for offline sync - Pass eventStore to highlight creation service and hooks - Simplified offline sync: no more relay queries, just EventStore lookups - More efficient and reliable offline event tracking - Better integration with applesauce architecture Benefits: - Faster sync (no relay queries needed) - More reliable (events always in EventStore) - Cleaner code (leveraging applesauce patterns) - Better separation of concerns
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { useEffect, useRef } from 'react'
|
||||
import { RelayPool } from 'applesauce-relay'
|
||||
import { IAccount } from 'applesauce-core/helpers'
|
||||
import { IAccount, IEventStore } from 'applesauce-core'
|
||||
import { syncLocalEventsToRemote } from '../services/offlineSyncService'
|
||||
import { isLocalRelay } from '../utils/helpers'
|
||||
import { RelayStatus } from '../services/relayStatusService'
|
||||
@@ -8,6 +8,7 @@ import { RelayStatus } from '../services/relayStatusService'
|
||||
interface UseOfflineSyncParams {
|
||||
relayPool: RelayPool | null
|
||||
account: IAccount | null
|
||||
eventStore: IEventStore | null
|
||||
relayStatuses: RelayStatus[]
|
||||
enabled?: boolean
|
||||
}
|
||||
@@ -15,6 +16,7 @@ interface UseOfflineSyncParams {
|
||||
export function useOfflineSync({
|
||||
relayPool,
|
||||
account,
|
||||
eventStore,
|
||||
relayStatuses,
|
||||
enabled = true
|
||||
}: UseOfflineSyncParams) {
|
||||
@@ -27,7 +29,7 @@ export function useOfflineSync({
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
if (!enabled || !relayPool || !account) return
|
||||
if (!enabled || !relayPool || !account || !eventStore) return
|
||||
|
||||
const connectedRelays = relayStatuses.filter(r => r.isInPool)
|
||||
const hasRemoteRelays = connectedRelays.some(r => !isLocalRelay(r.url))
|
||||
@@ -57,11 +59,11 @@ export function useOfflineSync({
|
||||
// Wait a moment for relays to fully establish connections
|
||||
setTimeout(() => {
|
||||
console.log('🚀 Starting sync after delay...')
|
||||
syncLocalEventsToRemote(relayPool, account)
|
||||
syncLocalEventsToRemote(relayPool, account, eventStore)
|
||||
}, 2000)
|
||||
}
|
||||
|
||||
previousStateRef.current.hasRemoteRelays = hasRemoteRelays
|
||||
}, [relayPool, account, relayStatuses, enabled])
|
||||
}, [relayPool, account, eventStore, relayStatuses, enabled])
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user