feat(create): add React PowerSync scaffolding add-on #407
Mergeddevagrawal09(GitHub profile, opens in a new tab)merged 3 commits into
main fromrefs/pull/407/headmerged by tannerlinsley - @@ -0,0 +30,21 @@30+ for (const op of transaction.crud) {31+ const record = { ...op.opData, id: op.id }32+33+ switch (op.op) {34+ case UpdateType.PUT:35+ console.info('TODO: create record remotely', record)36+ break37+ case UpdateType.PATCH:38+ console.info('TODO: patch record remotely', record)39+ break40+ case UpdateType.DELETE:41+ console.info('TODO: delete record remotely', record)42+ break43+ }44+ }45+46+ await transaction.complete()47+ } catch (error) {48+ console.error('PowerSync uploadData failed', error)49+ await transaction.complete()50+ }@@ -0,0 +19,21 @@19+ const { data } = useQuery(20+ 'SELECT id, created_at, description, completed FROM todos ORDER BY created_at DESC',21+ )22+ const todos = (data ?? []) as Array<TodoRow>23+ const [description, setDescription] = useState('')24+25+ async function addTodo(event: React.FormEvent<HTMLFormElement>) {26+ event.preventDefault()27+28+ const nextDescription = description.trim()29+ if (!nextDescription) {30+ return31+ }32+33+ await powerSync.execute(34+ 'INSERT INTO todos (id, created_at, description, completed) VALUES (?, ?, ?, ?)',35+ [crypto.randomUUID(), new Date().toISOString(), nextDescription, 0],36+ )37+38+ setDescription('')39+ }@@ -0,0 +54,21 @@54+55+ <section className="rounded-3xl border border-[var(--line)] bg-white/70 p-5 shadow-sm">56+ <h2 className="text-sm font-semibold uppercase tracking-[0.16em] text-[var(--sea-ink-soft)]">57+ Connection State58+ </h2>59+ <pre className="mt-3 overflow-auto rounded-2xl bg-[var(--chip-bg)] p-4 text-xs leading-6 text-[var(--sea-ink)]">60+ {JSON.stringify(status, null, 2)}61+ </pre>62+ </section>63+64+ <section className="rounded-3xl border border-[var(--line)] bg-white/70 p-5 shadow-sm">65+ <h2 className="text-sm font-semibold uppercase tracking-[0.16em] text-[var(--sea-ink-soft)]">66+ Local Todos67+ </h2>68+ <form className="mt-4 flex flex-col gap-3 sm:flex-row" onSubmit={addTodo}>69+ <input70+ className="min-w-0 flex-1 rounded-2xl border border-[var(--line)] bg-white px-4 py-3 text-sm text-[var(--sea-ink)] outline-none"71+ onChange={(event) => setDescription(event.target.value)}72+ placeholder="Write to the local PowerSync database"73+ value={description}74+ />@@ -0,0 +3,21 @@3+ "description": "Add PowerSync offline sync to your application.",4+ "phase": "add-on",5+ "type": "add-on",6+ "category": "database",7+ "color": "#2563EB",8+ "priority": 55,9+ "link": "https://docs.powersync.com/client-sdk-references/js-web",10+ "modes": ["file-router"],11+ "envVars": [12+ {13+ "name": "VITE_POWERSYNC_URL",14+ "description": "PowerSync instance URL",15+ "required": true,16+ "file": ".env.local"17+ },18+ {19+ "name": "VITE_POWERSYNC_TOKEN",20+ "description": "Development token for local testing",21+ "required": false,22+ "secret": true,23+ "file": ".env.local"
tannerlinsley merged this8f24af5
tannerlinsley closed this
Sign in to join this conversation.
⚠️ No Changeset found#
Latest commit: 69afd2983c46ee56f75be1c645dd7b7b16672b7f
Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.
This PR includes no changesets
When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types
Click here to learn what changesets are, and how to add one.
Click here if you're a maintainer who wants to add a changeset to this PR