this repo has no description
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

revert: broken build

+19 -77
+19 -77
mast-react-vite/src/main.tsx
··· 1 - import { StrictMode } from 'react' 2 1 import { createRoot } from 'react-dom/client' 3 2 import './index.css' 4 3 import App from "./App.tsx"; 5 - import Root from "./Root.tsx"; 6 - import { start } from "@vlcn.io/ws-client/worker.js"; 7 - import { createDbProvider } from "@vlcn.io/ws-browserdb"; 8 4 9 5 import initWasm from '@vlcn.io/crsqlite-wasm'; 10 6 import wasmUrl from '@vlcn.io/crsqlite-wasm/crsqlite.wasm?url'; 11 7 import tblrx from '@vlcn.io/rx-tbl'; 12 8 13 - async function initializeDatabase() { 14 - const sqlite = await initWasm(() => wasmUrl); 15 - const db = await sqlite.open("todo.db"); 16 - await db.exec(` 17 - CREATE TABLE IF NOT EXISTS todos ( 18 - id BLOB PRIMARY KEY NOT NULL, 19 - description TEXT, 20 - project text, 21 - tags text, 22 - due text, 23 - wait text, 24 - priority text, 25 - urgency real, 26 - completed INTEGER NOT NULL DEFAULT 0 27 - ); 28 - SELECT crsql_as_crr('todos'); 29 - `); 30 - db.onUpdate(async () => { 31 - const changes = await db.execA(`SELECT * FROM crsql_changes WHERE db_version > 0 AND site_id = crsql_site_id()`); 32 - 33 - sendChangesToServer(changes); 34 - }); 35 - return db; 36 - } 37 - 38 - const config = { 39 - dbProvider: createDbProvider(), 40 - transportProvider: (dbName) => new WebSocket(`ws://localhost:8080/sync/${dbName}`), 41 - }; 42 - 43 - start(config); 44 - const ws = new WebSocket('ws://localhost:8080/sync'); 45 - 46 - ws.onmessage = async function(event) { 47 - const { type, data } = JSON.parse(event.data); 48 - if (type === 'changes') { 49 - await applyChanges(data); 50 - } 51 - }; 52 - 53 - function sendChangesToServer(changes) { 54 - const formattedChanges = changes.map(change => ({ 55 - TableName: change[0], 56 - PK: Array.isArray(change[1]) ? btoa(String.fromCharCode.apply(null, change[1])) : btoa(change[1]), 57 - ColumnName: change[2], 58 - Value: Array.isArray(change[3]) ? btoa(String.fromCharCode.apply(null, change[3])) : change[3], 59 - ColVersion: Number(change[4]), 60 - DBVersion: Number(change[5]), 61 - SiteID: Array.isArray(change[6]) ? btoa(new TextDecoder('utf8').decode(change[6])) : btoa(change[6]), 62 - CL: Number(change[7]), 63 - Seq: Number(change[8]) 64 - })); 65 - console.log(formattedChanges) 66 - 67 - const message = { 68 - type: "changes", 69 - data: formattedChanges 70 - }; 9 + const sqlite = await initWasm(() => wasmUrl); 71 10 72 - ws.send(JSON.stringify(message)); 73 - } 11 + const db = await sqlite.open("todo.db"); 12 + await db.exec(` 13 + CREATE TABLE IF NOT EXISTS todos ( 14 + id BLOB PRIMARY KEY NOT NULL, 15 + description TEXT, 16 + project text, 17 + tags text, 18 + due text, 19 + wait text, 20 + priority text, 21 + urgency real, 22 + completed INTEGER NOT NULL DEFAULT 0 23 + ); 24 + SELECT crsql_as_crr('todos'); 25 + `); 74 26 75 - async function applyChanges(changes) { 76 - const db = initializeDatabase(); 77 - const rx = tblrx(db); 78 - const ctx = { db, rx }; 79 - await db.tx(async (tx) => { 80 - for (const change of changes) { 81 - await tx.exec( 82 - `INSERT INTO crsql_changes VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`, 83 - change 84 - ); 85 - } 86 - }); 87 - } 27 + const rx = tblrx(db); 28 + const ctx = { db, rx }; 88 29 89 30 document.getElementById("root")!.classList.add("dark"); 90 31 ··· 93 34 <App ctx={ctx} /> 94 35 </main> 95 36 ); 37 +