mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-06-08 20:25:19 +02:00
feat: Enhance Electric SQL integration and update notification handling
- Added initialization script for Electric SQL user in Docker setup. - Updated Electric SQL client to support new PGlite architecture and sync functionality. - Improved notification fetching and syncing logic in useNotifications hook. - Refactored ElectricProvider to handle initialization state and errors more gracefully. - Removed deprecated electric.config.ts file and adjusted package dependencies accordingly.
This commit is contained in:
parent
82c6dd0221
commit
f441c7b0ce
10 changed files with 376 additions and 1046 deletions
|
|
@ -1,31 +1,53 @@
|
|||
"use client"
|
||||
|
||||
import { useEffect, useState } from 'react'
|
||||
import { initElectric } from '@/lib/electric/client'
|
||||
import { initElectric, isElectricInitialized } from '@/lib/electric/client'
|
||||
|
||||
interface ElectricProviderProps {
|
||||
children: React.ReactNode
|
||||
}
|
||||
|
||||
/**
|
||||
* ElectricProvider initializes the Electric SQL client with PGlite
|
||||
*
|
||||
* This provider ensures Electric is initialized before rendering children,
|
||||
* but doesn't block if initialization fails (app can still work without real-time sync)
|
||||
*/
|
||||
export function ElectricProvider({ children }: ElectricProviderProps) {
|
||||
const [initialized, setInitialized] = useState(false)
|
||||
const [error, setError] = useState<Error | null>(null)
|
||||
|
||||
useEffect(() => {
|
||||
// Skip if already initialized
|
||||
if (isElectricInitialized()) {
|
||||
setInitialized(true)
|
||||
return
|
||||
}
|
||||
|
||||
let mounted = true
|
||||
|
||||
async function init() {
|
||||
try {
|
||||
await initElectric()
|
||||
setInitialized(true)
|
||||
setError(null)
|
||||
if (mounted) {
|
||||
setInitialized(true)
|
||||
setError(null)
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Failed to initialize Electric SQL:', err)
|
||||
setError(err instanceof Error ? err : new Error('Failed to initialize Electric SQL'))
|
||||
// Don't block rendering if Electric SQL fails - app can still work
|
||||
setInitialized(true)
|
||||
if (mounted) {
|
||||
setError(err instanceof Error ? err : new Error('Failed to initialize Electric SQL'))
|
||||
// Don't block rendering if Electric SQL fails - app can still work
|
||||
setInitialized(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
init()
|
||||
|
||||
return () => {
|
||||
mounted = false
|
||||
}
|
||||
}, [])
|
||||
|
||||
// Show loading state only briefly, then render children
|
||||
|
|
@ -38,6 +60,10 @@ export function ElectricProvider({ children }: ElectricProviderProps) {
|
|||
)
|
||||
}
|
||||
|
||||
// If there's an error, still render children but log the error
|
||||
if (error) {
|
||||
console.warn('Electric SQL initialization failed, notifications may not sync:', error.message)
|
||||
}
|
||||
|
||||
return <>{children}</>
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue