@@ -2,10 +2,12 @@ import React from 'react';
22import { CircularProgress , Grid , styled } from '@mui/material' ;
33import { useSupabase } from '@/components/providers/SystemProvider' ;
44import { useNavigate } from 'react-router-dom' ;
5+ import { usePowerSync } from '@powersync/react' ;
56
67export default function EntryPage ( ) {
78 const navigate = useNavigate ( ) ;
89 const connector = useSupabase ( ) ;
10+ const powerSync = usePowerSync ( ) ;
911
1012 React . useEffect ( ( ) => {
1113 if ( ! connector ) {
@@ -21,17 +23,14 @@ export default function EntryPage() {
2123 return ;
2224 }
2325 // otherwise, create a new document
24- const { data } = await connector . client
25- . from ( 'documents' )
26- . insert ( {
27- title : 'Test Document ' + ( 1000 + Math . floor ( Math . random ( ) * 8999 ) )
28- } )
29- . select ( )
30- . single ( ) ;
26+ const results = await powerSync . execute ( 'INSERT INTO documents(id, title) VALUES(uuid(), ?) RETURNING id' , [
27+ 'Test Document ' + ( 1000 + Math . floor ( Math . random ( ) * 8999 ) )
28+ ] ) ;
29+ const documentId = results . rows ! . item ( 0 ) . id ;
3130
3231 // redirect user to the document
33- lastDocumentId = data . id ;
34- window . localStorage . setItem ( 'lastDocumentId' , lastDocumentId || '' ) ;
32+ lastDocumentId = documentId ;
33+ window . localStorage . setItem ( 'lastDocumentId' , documentId ) ;
3534 navigate ( '/editor/' + lastDocumentId ) ;
3635 } ;
3736
0 commit comments