11import { configureFts } from '@/app/utils/fts_setup' ;
2- import { AppSchema , ListRecord , LISTS_TABLE , TODOS_TABLE } from '@/library/powersync/AppSchema' ;
2+ import {
3+ AppSchema ,
4+ drizzleSchema ,
5+ drizzleTodos ,
6+ ListRecord ,
7+ LISTS_TABLE ,
8+ TODOS_TABLE
9+ } from '@/library/powersync/AppSchema' ;
310import { SupabaseConnector } from '@/library/powersync/SupabaseConnector' ;
411import { CircularProgress } from '@mui/material' ;
512import { PowerSyncContext } from '@powersync/react' ;
6- import { createBaseLogger , DifferentialWatchedQuery , LogLevel , PowerSyncDatabase } from '@powersync/web' ;
13+ import {
14+ createBaseLogger ,
15+ DifferentialWatchedQuery ,
16+ LogLevel ,
17+ PowerSyncDatabase ,
18+ SyncClientImplementation
19+ } from '@powersync/web' ;
720import React , { Suspense } from 'react' ;
821import { NavigationPanelContextProvider } from '../navigation/NavigationPanelContext' ;
22+ import { wrapPowerSyncWithDrizzle } from '@powersync/drizzle-driver' ;
23+ import { inArray , sql } from 'drizzle-orm' ;
924
1025const SupabaseContext = React . createContext < SupabaseConnector | null > ( null ) ;
1126export const useSupabase = ( ) => React . useContext ( SupabaseContext ) ;
@@ -17,6 +32,8 @@ export const db = new PowerSyncDatabase({
1732 }
1833} ) ;
1934
35+ export const drizzleDb = wrapPowerSyncWithDrizzle ( db , { schema : drizzleSchema } ) ;
36+
2037export type EnhancedListRecord = ListRecord & { total_tasks : number ; completed_tasks : number } ;
2138
2239export type QueryStore = {
@@ -26,6 +43,13 @@ export type QueryStore = {
2643const QueryStore = React . createContext < QueryStore | null > ( null ) ;
2744export const useQueryStore = ( ) => React . useContext ( QueryStore ) ;
2845
46+ export async function markItemsAsCompleted ( ids : string [ ] ) {
47+ await drizzleDb
48+ . update ( drizzleTodos )
49+ . set ( { completed : 1 , completed_at : sql `datetime ('now')` } )
50+ . where ( inArray ( drizzleTodos . id , ids ) ) ;
51+ }
52+
2953export const SystemProvider = ( { children } : { children : React . ReactNode } ) => {
3054 const [ connector ] = React . useState ( ( ) => new SupabaseConnector ( ) ) ;
3155 const [ powerSync ] = React . useState ( db ) ;
@@ -68,7 +92,7 @@ export const SystemProvider = ({ children }: { children: React.ReactNode }) => {
6892 const l = connector . registerListener ( {
6993 initialized : ( ) => { } ,
7094 sessionStarted : ( ) => {
71- powerSync . connect ( connector ) ;
95+ powerSync . connect ( connector , { clientImplementation : SyncClientImplementation . RUST } ) ;
7296 }
7397 } ) ;
7498
@@ -94,4 +118,6 @@ export const SystemProvider = ({ children }: { children: React.ReactNode }) => {
94118 ) ;
95119} ;
96120
121+ ( window as any ) . markItemsAsCompleted = markItemsAsCompleted ;
122+
97123export default SystemProvider ;
0 commit comments