create-usebecky 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +80 -2
- package/dist/create.js +842 -0
- package/dist/extension-skill/usebecky-extension/SKILL.md +181 -0
- package/dist/extension-skill/usebecky-extension/references/accounts.md +125 -0
- package/dist/extension-skill/usebecky-extension/references/dev-server.md +102 -0
- package/dist/extension-skill/usebecky-extension/references/manifest.md +104 -0
- package/dist/extension-skill/usebecky-extension/references/oauth-and-tokens.md +179 -0
- package/dist/extension-skill/usebecky-extension/references/partner-api.md +87 -0
- package/dist/extension-skill/usebecky-extension/references/submit-and-pricing.md +31 -0
- package/dist/extension-skill/usebecky-extension/references/ui.md +172 -0
- package/dist/extension-skill/usebecky-extension/references/webhooks.md +97 -0
- package/dist/index.js +10 -0
- package/dist/keys.js +72 -0
- package/dist/platform.js +104 -0
- package/dist/pm.js +69 -0
- package/dist/prompts.js +242 -0
- package/dist/scaffold.js +108 -0
- package/dist/setup.js +130 -0
- package/dist/shared/ai.js +203 -0
- package/dist/shared/extension-skill.js +107 -0
- package/dist/shared/framework.js +460 -0
- package/dist/shared/hosted.js +8 -0
- package/dist/shared/ui.js +141 -0
- package/dist/skill/usebecky/SKILL.md +339 -0
- package/dist/skill/usebecky/references/access-rules.md +307 -0
- package/dist/skill/usebecky/references/addons.md +68 -0
- package/dist/skill/usebecky/references/analytics.md +166 -0
- package/dist/skill/usebecky/references/android.md +434 -0
- package/dist/skill/usebecky/references/auth.md +379 -0
- package/dist/skill/usebecky/references/cache.md +51 -0
- package/dist/skill/usebecky/references/components.md +127 -0
- package/dist/skill/usebecky/references/emails.md +105 -0
- package/dist/skill/usebecky/references/expo.md +147 -0
- package/dist/skill/usebecky/references/functions.md +99 -0
- package/dist/skill/usebecky/references/hosting.md +119 -0
- package/dist/skill/usebecky/references/http-api.md +233 -0
- package/dist/skill/usebecky/references/ios.md +355 -0
- package/dist/skill/usebecky/references/payments.md +493 -0
- package/dist/skill/usebecky/references/realtime.md +143 -0
- package/dist/skill/usebecky/references/scheduled-jobs.md +82 -0
- package/dist/skill/usebecky/references/sdk.md +838 -0
- package/dist/skill/usebecky/references/storage.md +210 -0
- package/dist/skill/usebecky/references/templates.md +191 -0
- package/dist/skill/usebecky/references/wordpress.md +87 -0
- package/dist/templates.js +74 -0
- package/package.json +37 -4
- package/templates/expo/App.tsx +48 -0
- package/templates/expo/README.md +59 -0
- package/templates/expo/_env.example +4 -0
- package/templates/expo/_gitignore +12 -0
- package/templates/expo/app.json +25 -0
- package/templates/expo/assets/icon.png +0 -0
- package/templates/expo/brand.ts +7 -0
- package/templates/expo/components/Avatar.tsx +75 -0
- package/templates/expo/components/ui.tsx +57 -0
- package/templates/expo/index.ts +4 -0
- package/templates/expo/lib/theme.ts +43 -0
- package/templates/expo/lib/usebecky.ts +15 -0
- package/templates/expo/package.json +29 -0
- package/templates/expo/screens/Home.tsx +187 -0
- package/templates/expo/screens/SignIn.tsx +112 -0
- package/templates/expo/tsconfig.json +6 -0
- package/templates/expo/usebecky.template.json +36 -0
- package/templates/extension/README.md +128 -0
- package/templates/extension/_env.example +21 -0
- package/templates/extension/_gitignore +11 -0
- package/templates/extension/logo.svg +1 -0
- package/templates/extension/package.json +25 -0
- package/templates/extension/src/accounts.ts +90 -0
- package/templates/extension/src/app.ts +178 -0
- package/templates/extension/src/pages.ts +108 -0
- package/templates/extension/src/replay-guard.ts +17 -0
- package/templates/extension/src/server.ts +57 -0
- package/templates/extension/src/settings.ts +69 -0
- package/templates/extension/src/ui.ts +70 -0
- package/templates/extension/test/app.test.ts +222 -0
- package/templates/extension/tsconfig.json +16 -0
- package/templates/extension/usebecky-extension.json +36 -0
- package/templates/extension/usebecky.template.json +22 -0
- package/templates/landing/README.md +43 -0
- package/templates/landing/_env.example +4 -0
- package/templates/landing/_gitignore +9 -0
- package/templates/landing/index.html +16 -0
- package/templates/landing/package.json +28 -0
- package/templates/landing/public/icon.svg +1 -0
- package/templates/landing/src/App.tsx +97 -0
- package/templates/landing/src/components/Contact.tsx +43 -0
- package/templates/landing/src/components/Counter.tsx +34 -0
- package/templates/landing/src/components/Feedback.tsx +36 -0
- package/templates/landing/src/components/Logo.tsx +11 -0
- package/templates/landing/src/components/Receipt.tsx +128 -0
- package/templates/landing/src/components/Setup.tsx +20 -0
- package/templates/landing/src/components/fields.tsx +63 -0
- package/templates/landing/src/content.ts +22 -0
- package/templates/landing/src/index.css +119 -0
- package/templates/landing/src/lib/usebecky.ts +11 -0
- package/templates/landing/src/lib/waitlist.ts +46 -0
- package/templates/landing/src/main.tsx +12 -0
- package/templates/landing/src/vite-env.d.ts +6 -0
- package/templates/landing/tsconfig.json +19 -0
- package/templates/landing/usebecky.template.json +20 -0
- package/templates/landing/vite.config.ts +10 -0
- package/templates/notes/README.md +68 -0
- package/templates/notes/_env.example +4 -0
- package/templates/notes/_gitignore +9 -0
- package/templates/notes/index.html +15 -0
- package/templates/notes/package.json +28 -0
- package/templates/notes/public/icon.svg +1 -0
- package/templates/notes/src/App.tsx +35 -0
- package/templates/notes/src/brand.ts +7 -0
- package/templates/notes/src/components/Composer.tsx +113 -0
- package/templates/notes/src/components/NoteEntry.tsx +151 -0
- package/templates/notes/src/components/Notes.tsx +163 -0
- package/templates/notes/src/components/Setup.tsx +44 -0
- package/templates/notes/src/components/SignIn.tsx +112 -0
- package/templates/notes/src/components/icons.tsx +54 -0
- package/templates/notes/src/index.css +105 -0
- package/templates/notes/src/lib/notes.ts +68 -0
- package/templates/notes/src/lib/usebecky.ts +9 -0
- package/templates/notes/src/main.tsx +22 -0
- package/templates/notes/src/vite-env.d.ts +6 -0
- package/templates/notes/tsconfig.json +19 -0
- package/templates/notes/usebecky.template.json +34 -0
- package/templates/notes/vite.config.ts +10 -0
- package/templates/saas/README.md +69 -0
- package/templates/saas/_env.example +10 -0
- package/templates/saas/_gitignore +11 -0
- package/templates/saas/app/(app)/account/ManageBilling.tsx +26 -0
- package/templates/saas/app/(app)/account/page.tsx +71 -0
- package/templates/saas/app/(app)/dashboard/Projects.tsx +227 -0
- package/templates/saas/app/(app)/dashboard/page.tsx +21 -0
- package/templates/saas/app/(app)/layout.tsx +29 -0
- package/templates/saas/app/(app)/premium/page.tsx +62 -0
- package/templates/saas/app/auth/callback/page.tsx +33 -0
- package/templates/saas/app/globals.css +143 -0
- package/templates/saas/app/icon.svg +1 -0
- package/templates/saas/app/layout.tsx +20 -0
- package/templates/saas/app/page.tsx +87 -0
- package/templates/saas/app/pricing/Plans.tsx +133 -0
- package/templates/saas/app/pricing/TestCardHint.tsx +18 -0
- package/templates/saas/app/pricing/page.tsx +21 -0
- package/templates/saas/app/setup/page.tsx +34 -0
- package/templates/saas/app/sign-in/SignInForm.tsx +195 -0
- package/templates/saas/app/sign-in/page.tsx +21 -0
- package/templates/saas/brand.ts +10 -0
- package/templates/saas/components/AppNav.tsx +45 -0
- package/templates/saas/components/Logo.tsx +22 -0
- package/templates/saas/components/SiteHeader.tsx +50 -0
- package/templates/saas/components/Status.tsx +15 -0
- package/templates/saas/lib/session.ts +26 -0
- package/templates/saas/lib/usebecky.ts +11 -0
- package/templates/saas/next-env.d.ts +5 -0
- package/templates/saas/next.config.ts +5 -0
- package/templates/saas/package.json +26 -0
- package/templates/saas/postcss.config.mjs +3 -0
- package/templates/saas/tsconfig.json +21 -0
- package/templates/saas/usebecky.template.json +31 -0
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
@import 'tailwindcss';
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
Your brand colour. Change this one value and the whole page follows, in light and dark mode.
|
|
5
|
+
The top of the page is filled with it, so pick a colour dark enough for white text.
|
|
6
|
+
*/
|
|
7
|
+
:root {
|
|
8
|
+
--brand: #2340d8;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/* Light theme */
|
|
12
|
+
:root {
|
|
13
|
+
color-scheme: light;
|
|
14
|
+
--page: #f6f7fb;
|
|
15
|
+
--surface: #ffffff;
|
|
16
|
+
--ink: #12152b;
|
|
17
|
+
--muted: #565c78;
|
|
18
|
+
--line: #dfe2ee;
|
|
19
|
+
--accent: var(--brand);
|
|
20
|
+
--accent-soft: color-mix(in oklab, var(--brand) 9%, var(--surface));
|
|
21
|
+
--on-brand: #ffffff;
|
|
22
|
+
--on-brand-muted: color-mix(in oklab, white 78%, var(--brand));
|
|
23
|
+
--paper: #fffdf8;
|
|
24
|
+
--paper-ink: #1d1b16;
|
|
25
|
+
--danger: #c0262d;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/* Dark theme (follows your computer's setting) */
|
|
29
|
+
@media (prefers-color-scheme: dark) {
|
|
30
|
+
:root {
|
|
31
|
+
color-scheme: dark;
|
|
32
|
+
--page: #0c0f1f;
|
|
33
|
+
--surface: #141933;
|
|
34
|
+
--ink: #eef0fa;
|
|
35
|
+
--muted: #a0a6c3;
|
|
36
|
+
--line: #262c4d;
|
|
37
|
+
--accent: color-mix(in oklab, var(--brand) 55%, white);
|
|
38
|
+
--accent-soft: color-mix(in oklab, var(--brand) 22%, var(--surface));
|
|
39
|
+
--danger: #ff8b8b;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
@theme inline {
|
|
44
|
+
--color-page: var(--page);
|
|
45
|
+
--color-surface: var(--surface);
|
|
46
|
+
--color-ink: var(--ink);
|
|
47
|
+
--color-muted: var(--muted);
|
|
48
|
+
--color-line: var(--line);
|
|
49
|
+
--color-brand: var(--brand);
|
|
50
|
+
--color-accent: var(--accent);
|
|
51
|
+
--color-accent-soft: var(--accent-soft);
|
|
52
|
+
--color-on-brand: var(--on-brand);
|
|
53
|
+
--color-on-brand-muted: var(--on-brand-muted);
|
|
54
|
+
--color-paper: var(--paper);
|
|
55
|
+
--color-paper-ink: var(--paper-ink);
|
|
56
|
+
--color-danger: var(--danger);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
@theme {
|
|
60
|
+
--font-sans: 'Figtree Variable', ui-sans-serif, system-ui, sans-serif;
|
|
61
|
+
--font-display: 'Anybody Variable', 'Figtree Variable', ui-sans-serif, system-ui, sans-serif;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
@layer base {
|
|
65
|
+
html {
|
|
66
|
+
background: var(--page);
|
|
67
|
+
color: var(--ink);
|
|
68
|
+
-webkit-font-smoothing: antialiased;
|
|
69
|
+
scroll-behavior: smooth;
|
|
70
|
+
}
|
|
71
|
+
@media (prefers-reduced-motion: reduce) {
|
|
72
|
+
html {
|
|
73
|
+
scroll-behavior: auto;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
body {
|
|
77
|
+
@apply font-sans;
|
|
78
|
+
}
|
|
79
|
+
:focus-visible {
|
|
80
|
+
outline: 2px solid var(--accent);
|
|
81
|
+
outline-offset: 3px;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/* The wide, heavy display type used for headlines. */
|
|
86
|
+
@utility display {
|
|
87
|
+
font-family: var(--font-display);
|
|
88
|
+
font-stretch: 125%;
|
|
89
|
+
font-weight: 800;
|
|
90
|
+
letter-spacing: -0.035em;
|
|
91
|
+
line-height: 0.92;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/* The torn bottom edge of the receipt. */
|
|
95
|
+
@utility torn {
|
|
96
|
+
--tooth: 14px;
|
|
97
|
+
mask:
|
|
98
|
+
conic-gradient(from -45deg at bottom, #0000, #000 1deg 89deg, #0000 90deg) 50% / var(--tooth) 100%;
|
|
99
|
+
padding-bottom: calc(var(--tooth) / 2 + 1.5rem);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/* A rolling digit for the live counter. */
|
|
103
|
+
.digit {
|
|
104
|
+
display: inline-block;
|
|
105
|
+
height: 1em;
|
|
106
|
+
overflow: hidden;
|
|
107
|
+
line-height: 1;
|
|
108
|
+
vertical-align: -0.12em;
|
|
109
|
+
}
|
|
110
|
+
.digit > span {
|
|
111
|
+
display: flex;
|
|
112
|
+
flex-direction: column;
|
|
113
|
+
transition: transform 900ms cubic-bezier(0.2, 0.8, 0.1, 1);
|
|
114
|
+
}
|
|
115
|
+
@media (prefers-reduced-motion: reduce) {
|
|
116
|
+
.digit > span {
|
|
117
|
+
transition: none;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Your usebecky client. Vite reads the two values from .env.local (without a URL it uses the hosted API).
|
|
2
|
+
// analytics.autoPageviews counts a page view on every page load and route change
|
|
3
|
+
// (see Dashboard → Analytics). No cookies, no IP addresses.
|
|
4
|
+
import { createClient } from 'usebecky'
|
|
5
|
+
|
|
6
|
+
export const baas = createClient(
|
|
7
|
+
// The key fallback only matters before .env.local exists: the page then shows how to connect instead of crashing.
|
|
8
|
+
import.meta.env.VITE_USEBECKY_URL,
|
|
9
|
+
import.meta.env.VITE_USEBECKY_PUBLISHABLE_KEY || 'ub_pk_notconfigured_0',
|
|
10
|
+
{ analytics: { autoPageviews: true } },
|
|
11
|
+
)
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// The waitlist, the counter and the feedback form, using the Waitlist template's tables.
|
|
2
|
+
// Visitors can add rows but never read them: you see them in Dashboard → Database.
|
|
3
|
+
import { baas } from './usebecky'
|
|
4
|
+
|
|
5
|
+
/** How many people joined. waitlist_count() returns only the number, never the emails. */
|
|
6
|
+
export async function waitlistCount(): Promise<number | null> {
|
|
7
|
+
const { data, error } = await baas.rpc('waitlist_count')
|
|
8
|
+
return error ? null : Number(data)
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export type JoinResult = { status: 'joined' | 'already' } | { status: 'error'; message: string }
|
|
12
|
+
|
|
13
|
+
/** Add an email. We make the referral code ourselves, because visitors can't read their row back. */
|
|
14
|
+
export async function joinWaitlist(email: string, referralCode: string, referredBy: string | null): Promise<JoinResult> {
|
|
15
|
+
const { error } = await baas.from('waitlist').insert({ email, referral_code: referralCode, referred_by: referredBy })
|
|
16
|
+
if (!error) return { status: 'joined' }
|
|
17
|
+
if (error.code === 'already_exists') return { status: 'already' }
|
|
18
|
+
if (error.code === 'table_not_found') return { status: 'error', message: 'This project has no waitlist table yet. Create the project from the Waitlist template (see the README).' }
|
|
19
|
+
if (error.code === 'check_violation' || error.status === 400) return { status: 'error', message: 'That doesn’t look like an email address. Check it and try again.' }
|
|
20
|
+
return { status: 'error', message: error.message }
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export async function sendFeedback(message: string, email: string) {
|
|
24
|
+
return baas.from('feedback').insert({ message, email: email || null, page: location.pathname })
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** A short code for the share link, e.g. "k3x9q2m7". */
|
|
28
|
+
export function newReferralCode(): string {
|
|
29
|
+
const alphabet = 'abcdefghijkmnpqrstuvwxyz23456789'
|
|
30
|
+
const bytes = crypto.getRandomValues(new Uint8Array(8))
|
|
31
|
+
return Array.from(bytes, (b) => alphabet[b % alphabet.length]).join('')
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Remember on this device that you joined, so the page greets you on your next visit. */
|
|
35
|
+
const KEY = 'waitlist-spot'
|
|
36
|
+
export type Spot = { number: number | null; code: string; email: string }
|
|
37
|
+
export function savedSpot(): Spot | null {
|
|
38
|
+
try {
|
|
39
|
+
return JSON.parse(localStorage.getItem(KEY) ?? 'null')
|
|
40
|
+
} catch {
|
|
41
|
+
return null
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
export function saveSpot(spot: Spot) {
|
|
45
|
+
localStorage.setItem(KEY, JSON.stringify(spot))
|
|
46
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import '@fontsource-variable/anybody/standard.css'
|
|
2
|
+
import '@fontsource-variable/figtree'
|
|
3
|
+
import './index.css'
|
|
4
|
+
import { StrictMode } from 'react'
|
|
5
|
+
import { createRoot } from 'react-dom/client'
|
|
6
|
+
import { App } from './App'
|
|
7
|
+
|
|
8
|
+
createRoot(document.getElementById('root')!).render(
|
|
9
|
+
<StrictMode>
|
|
10
|
+
<App />
|
|
11
|
+
</StrictMode>,
|
|
12
|
+
)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"lib": ["ES2023", "DOM", "DOM.Iterable"],
|
|
5
|
+
"module": "ESNext",
|
|
6
|
+
"moduleResolution": "bundler",
|
|
7
|
+
"jsx": "react-jsx",
|
|
8
|
+
"strict": true,
|
|
9
|
+
"noEmit": true,
|
|
10
|
+
"skipLibCheck": true,
|
|
11
|
+
"isolatedModules": true,
|
|
12
|
+
"allowImportingTsExtensions": true,
|
|
13
|
+
"verbatimModuleSyntax": true,
|
|
14
|
+
"noUnusedLocals": true,
|
|
15
|
+
"noUnusedParameters": true,
|
|
16
|
+
"types": ["vite/client"]
|
|
17
|
+
},
|
|
18
|
+
"include": ["src", "vite.config.ts"]
|
|
19
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "landing",
|
|
3
|
+
"name": "Landing page",
|
|
4
|
+
"description": "Waitlist, live counter, feedback and contact",
|
|
5
|
+
"stack": "React + Vite",
|
|
6
|
+
"kind": "node",
|
|
7
|
+
"framework": "vite",
|
|
8
|
+
"serverTemplate": "waitlist",
|
|
9
|
+
"order": 3,
|
|
10
|
+
"brandName": "Tidy",
|
|
11
|
+
"brandSlug": "tidy",
|
|
12
|
+
"brandFiles": ["src/content.ts", "index.html"],
|
|
13
|
+
"customize": { "name": "src/content.ts", "colour": "src/index.css (--brand)" },
|
|
14
|
+
"requires": { "tables": ["waitlist", "feedback"] },
|
|
15
|
+
"setup": {
|
|
16
|
+
"forms": [{ "key": "contact", "name": "Contact form", "preset": "contact" }]
|
|
17
|
+
},
|
|
18
|
+
"run": { "script": "dev", "url": "http://localhost:3002", "port": 3002 },
|
|
19
|
+
"docs": [{ "title": "Waitlist template", "path": "reference/templates" }]
|
|
20
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import tailwindcss from '@tailwindcss/vite'
|
|
2
|
+
import react from '@vitejs/plugin-react'
|
|
3
|
+
import { defineConfig } from 'vite'
|
|
4
|
+
|
|
5
|
+
// Port 3002, so it doesn't clash with the usebecky dashboard (5173) or a Next.js app (3000) or the Notes starter (3001).
|
|
6
|
+
export default defineConfig({
|
|
7
|
+
plugins: [react(), tailwindcss()],
|
|
8
|
+
server: { port: 3002 },
|
|
9
|
+
preview: { port: 3002 },
|
|
10
|
+
})
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# Margin: a private notes app
|
|
2
|
+
|
|
3
|
+
A notes app built with React, Vite and usebecky. People create an account, write notes, attach a picture, and see changes appear live in every open tab. It is the finished app from the usebecky tutorial.
|
|
4
|
+
|
|
5
|
+
## What's inside
|
|
6
|
+
|
|
7
|
+
- **Sign in and sign up** with an email and a password (`src/components/SignIn.tsx`).
|
|
8
|
+
- **Notes**: write, edit, delete and search (`src/components/Composer.tsx`, `src/components/NoteEntry.tsx`).
|
|
9
|
+
- **Private by design**: each person sees only their own notes. The database enforces this with access rules, not just the app.
|
|
10
|
+
- **Live updates**: add a note in one tab and it appears in the other (`src/components/Notes.tsx`).
|
|
11
|
+
- **Image attachments** in a private bucket, shown with links that expire after an hour (`src/lib/notes.ts`).
|
|
12
|
+
|
|
13
|
+
All the code that talks to usebecky is in `src/lib/notes.ts`, and the client is set up in `src/lib/usebecky.ts`.
|
|
14
|
+
|
|
15
|
+
## Run it
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm run dev
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Open http://localhost:3001 and create an account. Open a second tab next to it to see live updates.
|
|
22
|
+
|
|
23
|
+
Your project's address and key are in `.env.local`. If you change that file, stop `npm run dev` with Ctrl+C and start it again.
|
|
24
|
+
|
|
25
|
+
## Make it yours
|
|
26
|
+
|
|
27
|
+
- **Name and words**: `src/brand.ts`. The browser tab title is in `index.html`.
|
|
28
|
+
- **Colour**: change `--brand` at the top of `src/index.css`. Light and dark mode both follow it.
|
|
29
|
+
- **Fonts**: Newsreader for notes and Instrument Sans for everything else, imported in `src/main.tsx`.
|
|
30
|
+
|
|
31
|
+
## Connect it later
|
|
32
|
+
|
|
33
|
+
If you made the app without connecting it (`--skip-connect`), the page explains what to do. In short:
|
|
34
|
+
|
|
35
|
+
1. In this folder, run `npx usebecky init`. It signs you in, lets you pick a project and writes `.env.local`.
|
|
36
|
+
2. Create the table and the bucket. In the dashboard, open **Database**, then **SQL editor**, paste this and click **Run**:
|
|
37
|
+
|
|
38
|
+
```sql
|
|
39
|
+
create table public.notes (
|
|
40
|
+
id uuid primary key default gen_random_uuid(),
|
|
41
|
+
user_id uuid not null default auth.uid() references auth.users (id) on delete cascade,
|
|
42
|
+
title text not null,
|
|
43
|
+
body text,
|
|
44
|
+
image_path text,
|
|
45
|
+
created_at timestamptz not null default now()
|
|
46
|
+
);
|
|
47
|
+
create index on public.notes (user_id);
|
|
48
|
+
alter table public.notes enable row level security;
|
|
49
|
+
create policy "Users can view their own rows" on public.notes for select to authenticated using (user_id = auth.uid());
|
|
50
|
+
create policy "Users can add their own rows" on public.notes for insert to authenticated with check (user_id = auth.uid());
|
|
51
|
+
create policy "Users can update their own rows" on public.notes for update to authenticated using (user_id = auth.uid()) with check (user_id = auth.uid());
|
|
52
|
+
create policy "Users can delete their own rows" on public.notes for delete to authenticated using (user_id = auth.uid());
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
3. Turn on **Realtime** for `notes` (dashboard: **Realtime**, then switch on `notes`).
|
|
56
|
+
4. Create a private bucket called `attachments` (dashboard: **Storage**, **New bucket**) and add the rule **Users manage their own folder** (**Who can access**).
|
|
57
|
+
5. Restart `npm run dev`.
|
|
58
|
+
|
|
59
|
+
## Learn more
|
|
60
|
+
|
|
61
|
+
The docs are in your dashboard under **Docs**.
|
|
62
|
+
|
|
63
|
+
- **Tutorial part 1**: how this app is built, step by step (`tutorial/1-notes-app`).
|
|
64
|
+
- **Tutorial part 2**: the image attachments (`tutorial/2-file-uploads`).
|
|
65
|
+
- **Starter apps**: all starters and how to change them (`getting-started/starters`).
|
|
66
|
+
- **React + Vite guide**: more patterns for auth, data and realtime (`frameworks/react-vite`).
|
|
67
|
+
|
|
68
|
+
Ask your AI assistant for help, too: this folder contains the usebecky skill (`.claude/skills/usebecky`) and an `AGENTS.md`, so Claude Code, Cursor and others know how usebecky works.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<meta name="theme-color" content="#f2f3ee" media="(prefers-color-scheme: light)" />
|
|
7
|
+
<meta name="theme-color" content="#111513" media="(prefers-color-scheme: dark)" />
|
|
8
|
+
<link rel="icon" href="/icon.svg" type="image/svg+xml" />
|
|
9
|
+
<title>Margin</title>
|
|
10
|
+
</head>
|
|
11
|
+
<body>
|
|
12
|
+
<div id="root"></div>
|
|
13
|
+
<script type="module" src="/src/main.tsx"></script>
|
|
14
|
+
</body>
|
|
15
|
+
</html>
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "margin",
|
|
3
|
+
"private": true,
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "vite",
|
|
8
|
+
"build": "tsc --noEmit && vite build",
|
|
9
|
+
"preview": "vite preview",
|
|
10
|
+
"typecheck": "tsc --noEmit"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@fontsource-variable/instrument-sans": "5.3.0",
|
|
14
|
+
"@fontsource-variable/newsreader": "5.3.0",
|
|
15
|
+
"react": "19.3.1",
|
|
16
|
+
"react-dom": "19.3.1",
|
|
17
|
+
"usebecky": "^0.2.0"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@tailwindcss/vite": "4.3.3",
|
|
21
|
+
"@types/react": "19.3.0",
|
|
22
|
+
"@types/react-dom": "19.3.0",
|
|
23
|
+
"@vitejs/plugin-react": "6.1.2",
|
|
24
|
+
"tailwindcss": "4.3.3",
|
|
25
|
+
"typescript": "5.9.3",
|
|
26
|
+
"vite": "8.3.5"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"><rect x="4" y="3" width="24" height="26" rx="5" fill="#2f6b4f"/><rect x="10" y="3" width="2" height="26" fill="#f2f3ee" opacity=".85"/><path d="M15 11h8M15 16h8M15 21h5" stroke="#f2f3ee" stroke-width="2" stroke-linecap="round"/></svg>
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react'
|
|
2
|
+
import type { User } from 'usebecky'
|
|
3
|
+
import { brand } from './brand'
|
|
4
|
+
import { Logo } from './components/icons'
|
|
5
|
+
import { Notes } from './components/Notes'
|
|
6
|
+
import { SignIn } from './components/SignIn'
|
|
7
|
+
import { baas } from './lib/usebecky'
|
|
8
|
+
|
|
9
|
+
export function App() {
|
|
10
|
+
// undefined = still loading the saved session, null = signed out.
|
|
11
|
+
const [user, setUser] = useState<User | null | undefined>(undefined)
|
|
12
|
+
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
// Runs once right away (with the saved session), then on every sign-in and sign-out.
|
|
15
|
+
return baas.auth.onAuthStateChange((_event, session) => setUser(session?.user ?? null))
|
|
16
|
+
}, [])
|
|
17
|
+
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
document.title = user ? `Your notes · ${brand.name}` : brand.name
|
|
20
|
+
}, [user])
|
|
21
|
+
|
|
22
|
+
if (user === undefined) return <Loading />
|
|
23
|
+
if (!user) return <SignIn />
|
|
24
|
+
return <Notes user={user} />
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function Loading() {
|
|
28
|
+
return (
|
|
29
|
+
<div className="grid min-h-dvh place-items-center" aria-busy="true" aria-label="Loading">
|
|
30
|
+
<div className="animate-pulse">
|
|
31
|
+
<Logo size={36} />
|
|
32
|
+
</div>
|
|
33
|
+
</div>
|
|
34
|
+
)
|
|
35
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Your app's name and the words around it. Change them here and they change everywhere.
|
|
2
|
+
// The colour lives in src/index.css (--brand).
|
|
3
|
+
export const brand = {
|
|
4
|
+
name: 'Margin',
|
|
5
|
+
tagline: 'Notes that stay yours.',
|
|
6
|
+
description: 'Write it down, add a picture, find it again. Private to you, and live on every device you sign in on.',
|
|
7
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// Write a new note, optionally with an image.
|
|
2
|
+
import { useEffect, useRef, useState, type FormEvent } from 'react'
|
|
3
|
+
import type { User } from 'usebecky'
|
|
4
|
+
import { addNote, removeImage, uploadImage, type Note } from '../lib/notes'
|
|
5
|
+
import { ImageIcon, XIcon } from './icons'
|
|
6
|
+
|
|
7
|
+
export function Composer({ user, onCreated, onError }: { user: User; onCreated: (note: Note) => void; onError: (message: string) => void }) {
|
|
8
|
+
const [title, setTitle] = useState('')
|
|
9
|
+
const [body, setBody] = useState('')
|
|
10
|
+
const [file, setFile] = useState<File | null>(null)
|
|
11
|
+
const [preview, setPreview] = useState<string | null>(null)
|
|
12
|
+
const [busy, setBusy] = useState(false)
|
|
13
|
+
const fileInput = useRef<HTMLInputElement>(null)
|
|
14
|
+
const titleInput = useRef<HTMLInputElement>(null)
|
|
15
|
+
|
|
16
|
+
// Show the picked image before it is uploaded.
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
if (!file) return setPreview(null)
|
|
19
|
+
const url = URL.createObjectURL(file)
|
|
20
|
+
setPreview(url)
|
|
21
|
+
return () => URL.revokeObjectURL(url)
|
|
22
|
+
}, [file])
|
|
23
|
+
|
|
24
|
+
function pick(picked: File | undefined) {
|
|
25
|
+
if (!picked) return
|
|
26
|
+
if (!picked.type.startsWith('image/')) return onError('Pick an image file (JPG, PNG, GIF or WebP).')
|
|
27
|
+
if (picked.size > 5 * 1024 * 1024) return onError('That image is larger than 5 MB. Pick a smaller one.')
|
|
28
|
+
onError('')
|
|
29
|
+
setFile(picked)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async function save(event: FormEvent<HTMLFormElement>) {
|
|
33
|
+
event.preventDefault()
|
|
34
|
+
if (!title.trim()) return titleInput.current?.focus()
|
|
35
|
+
setBusy(true)
|
|
36
|
+
onError('')
|
|
37
|
+
let image_path: string | null = null
|
|
38
|
+
if (file) {
|
|
39
|
+
const uploaded = await uploadImage(user.id, file)
|
|
40
|
+
if (uploaded.error) {
|
|
41
|
+
setBusy(false)
|
|
42
|
+
return onError(`The image could not be uploaded: ${uploaded.error.message}`)
|
|
43
|
+
}
|
|
44
|
+
image_path = uploaded.path
|
|
45
|
+
}
|
|
46
|
+
const { data, error } = await addNote({ title: title.trim(), body: body.trim(), image_path })
|
|
47
|
+
setBusy(false)
|
|
48
|
+
if (error) {
|
|
49
|
+
if (image_path) await removeImage(image_path) // don't leave an orphaned file behind
|
|
50
|
+
return onError(error.message)
|
|
51
|
+
}
|
|
52
|
+
onCreated(data)
|
|
53
|
+
setTitle('')
|
|
54
|
+
setBody('')
|
|
55
|
+
setFile(null)
|
|
56
|
+
titleInput.current?.focus()
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return (
|
|
60
|
+
<form onSubmit={save} className="relative py-6 pr-5 pl-9 sm:py-8 sm:pr-8 sm:pl-36" aria-label="New note">
|
|
61
|
+
<span className="absolute top-9 left-0 hidden w-[7.5rem] pr-5 text-right text-sm text-muted sm:block" aria-hidden="true">
|
|
62
|
+
New note
|
|
63
|
+
</span>
|
|
64
|
+
<label htmlFor="new-title" className="sr-only">
|
|
65
|
+
Title
|
|
66
|
+
</label>
|
|
67
|
+
<input
|
|
68
|
+
id="new-title"
|
|
69
|
+
ref={titleInput}
|
|
70
|
+
value={title}
|
|
71
|
+
onChange={(e) => setTitle(e.target.value)}
|
|
72
|
+
placeholder="Title"
|
|
73
|
+
maxLength={200}
|
|
74
|
+
autoComplete="off"
|
|
75
|
+
className="w-full bg-transparent font-serif text-[1.75rem] leading-tight font-medium outline-none placeholder:text-muted/60 focus-visible:outline-none"
|
|
76
|
+
/>
|
|
77
|
+
<label htmlFor="new-body" className="sr-only">
|
|
78
|
+
Note
|
|
79
|
+
</label>
|
|
80
|
+
<textarea
|
|
81
|
+
id="new-body"
|
|
82
|
+
value={body}
|
|
83
|
+
onChange={(e) => setBody(e.target.value)}
|
|
84
|
+
onKeyDown={(e) => {
|
|
85
|
+
if (e.key === 'Enter' && (e.metaKey || e.ctrlKey)) e.currentTarget.form?.requestSubmit()
|
|
86
|
+
}}
|
|
87
|
+
placeholder="Write something…"
|
|
88
|
+
rows={2}
|
|
89
|
+
className="mt-1 field-sizing-content min-h-14 w-full resize-none bg-transparent font-serif text-[1.075rem] leading-[1.7] outline-none placeholder:text-muted/70 focus-visible:outline-none"
|
|
90
|
+
/>
|
|
91
|
+
|
|
92
|
+
{preview && (
|
|
93
|
+
<div className="relative mt-3 inline-block">
|
|
94
|
+
<img src={preview} alt="The image you picked" className="max-h-48 rounded-xl border border-line object-cover" />
|
|
95
|
+
<button type="button" onClick={() => setFile(null)} className="absolute top-2 right-2 grid size-8 place-items-center rounded-full bg-ink/75 text-paper backdrop-blur transition-colors hover:bg-ink" aria-label="Remove the image">
|
|
96
|
+
<XIcon width={16} height={16} />
|
|
97
|
+
</button>
|
|
98
|
+
</div>
|
|
99
|
+
)}
|
|
100
|
+
|
|
101
|
+
<div className="mt-3 -ml-3 flex items-center justify-between gap-3">
|
|
102
|
+
<input ref={fileInput} type="file" accept="image/*" className="sr-only" id="new-image" onChange={(e) => (pick(e.target.files?.[0]), (e.target.value = ''))} />
|
|
103
|
+
<label htmlFor="new-image" className="inline-flex h-10 cursor-pointer items-center gap-2 rounded-xl px-3 text-sm font-medium text-muted transition-colors hover:bg-paper hover:text-ink">
|
|
104
|
+
<ImageIcon />
|
|
105
|
+
{file ? 'Change image' : 'Add image'}
|
|
106
|
+
</label>
|
|
107
|
+
<button type="submit" disabled={busy || !title.trim()} className="h-10 rounded-xl bg-accent px-5 text-sm font-semibold text-accent-ink transition-[filter,opacity] hover:brightness-110 disabled:opacity-40">
|
|
108
|
+
{busy ? (file ? 'Uploading…' : 'Saving…') : 'Save note'}
|
|
109
|
+
</button>
|
|
110
|
+
</div>
|
|
111
|
+
</form>
|
|
112
|
+
)
|
|
113
|
+
}
|