Skip to content

Commit 526806b

Browse files
committed
Use local db to create new documents.
1 parent c51fa5c commit 526806b

File tree

1 file changed

+8
-9
lines changed
  • demos/yjs-react-supabase-text-collab/src/app

1 file changed

+8
-9
lines changed

demos/yjs-react-supabase-text-collab/src/app/page.tsx

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ import React from 'react';
22
import { CircularProgress, Grid, styled } from '@mui/material';
33
import { useSupabase } from '@/components/providers/SystemProvider';
44
import { useNavigate } from 'react-router-dom';
5+
import { usePowerSync } from '@powersync/react';
56

67
export 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

Comments
 (0)