@@ -4,13 +4,16 @@ import { CircularProgress } from '@mui/material';
44import { PowerSyncContext } from '@powersync/react' ;
55import { PowerSyncDatabase } from '@powersync/web' ;
66import Logger from 'js-logger' ;
7- import React , { Suspense } from 'react' ;
7+ import React , { Suspense , useEffect } from 'react' ;
88import { NavigationPanelContextProvider } from '../navigation/NavigationPanelContext' ;
99import { getSyncEnabled } from '@/library/powersync/SyncMode' ;
1010
1111const SupabaseContext = React . createContext < SupabaseConnector | null > ( null ) ;
1212export const useSupabase = ( ) => React . useContext ( SupabaseContext ) ;
1313
14+ const ResetContext = React . createContext < ( ( ) => void ) | null > ( null ) ;
15+ export const useReset = ( ) => React . useContext ( ResetContext ) ;
16+
1417const dbName = 'example.db' ;
1518const syncEnabled = getSyncEnabled ( dbName ) ;
1619
@@ -23,7 +26,7 @@ const db = new PowerSyncDatabase({
2326
2427export const SystemProvider = ( { children } : { children : React . ReactNode } ) => {
2528 const [ connector ] = React . useState ( new SupabaseConnector ( ) ) ;
26- const [ powerSync ] = React . useState ( db ) ;
29+ const [ powerSync , setPowersync ] = React . useState ( db ) ;
2730
2831 React . useEffect ( ( ) => {
2932 // Linting thinks this is a hook due to it's name
@@ -53,11 +56,16 @@ export const SystemProvider = ({ children }: { children: React.ReactNode }) => {
5356
5457 return (
5558 < Suspense fallback = { < CircularProgress /> } >
56- < PowerSyncContext . Provider value = { powerSync } >
57- < SupabaseContext . Provider value = { connector } >
58- < NavigationPanelContextProvider > { children } </ NavigationPanelContextProvider >
59- </ SupabaseContext . Provider >
60- </ PowerSyncContext . Provider >
59+ < ResetContext . Provider
60+ value = { ( ) => {
61+ setPowersync ( new PowerSyncDatabase ( { schema : makeSchema ( syncEnabled ) , database : { dbFilename : dbName } } ) ) ;
62+ } } >
63+ < PowerSyncContext . Provider value = { powerSync } >
64+ < SupabaseContext . Provider value = { connector } >
65+ < NavigationPanelContextProvider > { children } </ NavigationPanelContextProvider >
66+ </ SupabaseContext . Provider >
67+ </ PowerSyncContext . Provider >
68+ </ ResetContext . Provider >
6169 </ Suspense >
6270 ) ;
6371} ;
0 commit comments