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,151 @@
|
|
|
1
|
+
// One note: read it, edit it, delete it, and see its image.
|
|
2
|
+
import { useEffect, useState, type ReactNode } from 'react'
|
|
3
|
+
import type { User } from 'usebecky'
|
|
4
|
+
import { deleteNote, imageUrl, removeImage, timeAgo, updateNote, type Note } from '../lib/notes'
|
|
5
|
+
import { PencilIcon, TrashIcon } from './icons'
|
|
6
|
+
|
|
7
|
+
type Props = { note: Note; user: User; onChanged: (n: Note) => void; onDeleted: (id: string) => void; onError: (m: string) => void }
|
|
8
|
+
|
|
9
|
+
export function NoteEntry({ note, onChanged, onDeleted, onError }: Props) {
|
|
10
|
+
const [editing, setEditing] = useState(false)
|
|
11
|
+
const [confirming, setConfirming] = useState(false)
|
|
12
|
+
const [title, setTitle] = useState(note.title)
|
|
13
|
+
const [body, setBody] = useState(note.body ?? '')
|
|
14
|
+
const [busy, setBusy] = useState(false)
|
|
15
|
+
const created = new Date(note.created_at)
|
|
16
|
+
|
|
17
|
+
function startEditing() {
|
|
18
|
+
setTitle(note.title)
|
|
19
|
+
setBody(note.body ?? '')
|
|
20
|
+
setEditing(true)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async function save() {
|
|
24
|
+
if (!title.trim()) return
|
|
25
|
+
setBusy(true)
|
|
26
|
+
const { data, error } = await updateNote(note.id, { title: title.trim(), body: body.trim() })
|
|
27
|
+
setBusy(false)
|
|
28
|
+
if (error) return onError(error.message)
|
|
29
|
+
onChanged(data)
|
|
30
|
+
setEditing(false)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async function detachImage() {
|
|
34
|
+
if (!note.image_path) return
|
|
35
|
+
setBusy(true)
|
|
36
|
+
const { data, error } = await updateNote(note.id, { image_path: null })
|
|
37
|
+
if (!error) await removeImage(note.image_path)
|
|
38
|
+
setBusy(false)
|
|
39
|
+
if (error) return onError(error.message)
|
|
40
|
+
onChanged(data)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async function remove() {
|
|
44
|
+
setBusy(true)
|
|
45
|
+
const { error } = await deleteNote(note.id)
|
|
46
|
+
if (error) {
|
|
47
|
+
setBusy(false)
|
|
48
|
+
return onError(error.message)
|
|
49
|
+
}
|
|
50
|
+
if (note.image_path) await removeImage(note.image_path) // the note's image goes too
|
|
51
|
+
onDeleted(note.id)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
<article className="note-enter group relative py-6 pr-5 pl-9 sm:py-7 sm:pr-8 sm:pl-36" aria-labelledby={`note-${note.id}`}>
|
|
56
|
+
{/* The date sits in the margin on wide screens */}
|
|
57
|
+
<time dateTime={note.created_at} className="absolute top-8 left-0 hidden w-[7.5rem] pr-5 text-right text-sm leading-tight text-muted tabular-nums sm:block" title={created.toLocaleString()}>
|
|
58
|
+
{created.toLocaleDateString(undefined, { day: 'numeric', month: 'short' })}
|
|
59
|
+
<span className="block text-xs opacity-75">{created.toLocaleTimeString(undefined, { hour: 'numeric', minute: '2-digit' })}</span>
|
|
60
|
+
</time>
|
|
61
|
+
|
|
62
|
+
{editing ? (
|
|
63
|
+
<div className="space-y-2">
|
|
64
|
+
<label className="sr-only" htmlFor={`edit-title-${note.id}`}>
|
|
65
|
+
Title
|
|
66
|
+
</label>
|
|
67
|
+
<input id={`edit-title-${note.id}`} autoFocus value={title} onChange={(e) => setTitle(e.target.value)} className="w-full rounded-lg bg-paper px-3 py-2 font-serif text-[1.35rem] font-medium outline-none focus:ring-2 focus:ring-accent" />
|
|
68
|
+
<label className="sr-only" htmlFor={`edit-body-${note.id}`}>
|
|
69
|
+
Note
|
|
70
|
+
</label>
|
|
71
|
+
<textarea id={`edit-body-${note.id}`} value={body} onChange={(e) => setBody(e.target.value)} rows={4} className="field-sizing-content min-h-24 w-full resize-none rounded-lg bg-paper px-3 py-2 font-serif text-[1.05rem] leading-[1.7] outline-none focus:ring-2 focus:ring-accent" />
|
|
72
|
+
<div className="flex flex-wrap items-center gap-2 pt-1">
|
|
73
|
+
<button onClick={save} disabled={busy || !title.trim()} className="h-9 rounded-lg bg-accent px-4 text-sm font-semibold text-accent-ink disabled:opacity-50">
|
|
74
|
+
{busy ? 'Saving…' : 'Save changes'}
|
|
75
|
+
</button>
|
|
76
|
+
<button onClick={() => setEditing(false)} className="h-9 rounded-lg px-3 text-sm font-medium text-muted hover:bg-paper hover:text-ink">
|
|
77
|
+
Cancel
|
|
78
|
+
</button>
|
|
79
|
+
{note.image_path && (
|
|
80
|
+
<button onClick={detachImage} disabled={busy} className="ml-auto h-9 rounded-lg px-3 text-sm font-medium text-muted hover:bg-paper hover:text-danger">
|
|
81
|
+
Remove image
|
|
82
|
+
</button>
|
|
83
|
+
)}
|
|
84
|
+
</div>
|
|
85
|
+
</div>
|
|
86
|
+
) : (
|
|
87
|
+
<>
|
|
88
|
+
<div className="flex items-start gap-3">
|
|
89
|
+
<h3 id={`note-${note.id}`} className="min-w-0 flex-1 font-serif text-[1.4rem] leading-snug font-medium break-words text-balance">
|
|
90
|
+
{note.title}
|
|
91
|
+
</h3>
|
|
92
|
+
<div className="-mt-0.5 -mr-2 flex shrink-0 gap-0.5 transition-opacity sm:opacity-0 sm:group-focus-within:opacity-100 sm:group-hover:opacity-100">
|
|
93
|
+
<IconButton label={`Edit “${note.title}”`} onClick={startEditing}>
|
|
94
|
+
<PencilIcon />
|
|
95
|
+
</IconButton>
|
|
96
|
+
<IconButton label={`Delete “${note.title}”`} onClick={() => setConfirming(true)} danger>
|
|
97
|
+
<TrashIcon />
|
|
98
|
+
</IconButton>
|
|
99
|
+
</div>
|
|
100
|
+
</div>
|
|
101
|
+
<p className="mt-0.5 text-xs text-muted sm:hidden">{timeAgo(note.created_at)}</p>
|
|
102
|
+
{note.body && <p className="mt-2 max-w-[62ch] font-serif text-[1.05rem] leading-[1.7] break-words whitespace-pre-wrap text-ink/85">{note.body}</p>}
|
|
103
|
+
{note.image_path && <NoteImage path={note.image_path} />}
|
|
104
|
+
</>
|
|
105
|
+
)}
|
|
106
|
+
|
|
107
|
+
{confirming && !editing && (
|
|
108
|
+
<div role="alertdialog" aria-label="Delete this note?" className="mt-4 flex flex-wrap items-center gap-3 rounded-xl bg-[color-mix(in_oklab,var(--danger)_8%,transparent)] px-4 py-3 text-sm">
|
|
109
|
+
<span className="mr-auto">Delete this note{note.image_path ? ' and its image' : ''}? This can’t be undone.</span>
|
|
110
|
+
<button autoFocus onClick={remove} disabled={busy} className="h-8 rounded-lg bg-danger px-3 font-semibold text-surface disabled:opacity-60">
|
|
111
|
+
{busy ? 'Deleting…' : 'Delete'}
|
|
112
|
+
</button>
|
|
113
|
+
<button onClick={() => setConfirming(false)} className="h-8 rounded-lg px-3 font-medium hover:bg-surface">
|
|
114
|
+
Keep it
|
|
115
|
+
</button>
|
|
116
|
+
</div>
|
|
117
|
+
)}
|
|
118
|
+
</article>
|
|
119
|
+
)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function IconButton({ label, onClick, children, danger }: { label: string; onClick: () => void; children: ReactNode; danger?: boolean }) {
|
|
123
|
+
return (
|
|
124
|
+
<button onClick={onClick} aria-label={label} title={label.split(' “')[0]} className={`grid size-9 place-items-center rounded-lg text-muted transition-colors hover:bg-paper ${danger ? 'hover:text-danger' : 'hover:text-ink'}`}>
|
|
125
|
+
{children}
|
|
126
|
+
</button>
|
|
127
|
+
)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** A private image, shown with a signed link that works for one hour. */
|
|
131
|
+
function NoteImage({ path }: { path: string }) {
|
|
132
|
+
const [url, setUrl] = useState<string | null>(null)
|
|
133
|
+
const [failed, setFailed] = useState(false)
|
|
134
|
+
useEffect(() => {
|
|
135
|
+
let ignore = false
|
|
136
|
+
imageUrl(path).then(({ data, error }) => {
|
|
137
|
+
if (ignore) return
|
|
138
|
+
if (error) setFailed(true)
|
|
139
|
+
else setUrl(data.signedUrl)
|
|
140
|
+
})
|
|
141
|
+
return () => {
|
|
142
|
+
ignore = true
|
|
143
|
+
}
|
|
144
|
+
}, [path])
|
|
145
|
+
if (failed) return <p className="mt-3 text-sm text-muted">The image couldn’t be loaded.</p>
|
|
146
|
+
return (
|
|
147
|
+
<div className="mt-4 overflow-hidden rounded-xl border border-line bg-paper">
|
|
148
|
+
{url ? <img src={url} alt="" loading="lazy" className="block max-h-[26rem] w-full object-cover" /> : <div className="aspect-[16/9] animate-pulse" />}
|
|
149
|
+
</div>
|
|
150
|
+
)
|
|
151
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
// The signed-in screen: header, the composer, and your notes (live).
|
|
2
|
+
import { useEffect, useMemo, useState } from 'react'
|
|
3
|
+
import type { User } from 'usebecky'
|
|
4
|
+
import { brand } from '../brand'
|
|
5
|
+
import { listNotes, upsert, type Note } from '../lib/notes'
|
|
6
|
+
import { baas } from '../lib/usebecky'
|
|
7
|
+
import { Composer } from './Composer'
|
|
8
|
+
import { Logo, SearchIcon } from './icons'
|
|
9
|
+
import { NoteEntry } from './NoteEntry'
|
|
10
|
+
|
|
11
|
+
export function Notes({ user }: { user: User }) {
|
|
12
|
+
const [notes, setNotes] = useState<Note[]>([])
|
|
13
|
+
const [loading, setLoading] = useState(true)
|
|
14
|
+
const [error, setError] = useState('')
|
|
15
|
+
const [live, setLive] = useState(false)
|
|
16
|
+
const [query, setQuery] = useState('')
|
|
17
|
+
|
|
18
|
+
// Load your notes once.
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
let ignore = false
|
|
21
|
+
listNotes().then(({ data, error }) => {
|
|
22
|
+
if (ignore) return
|
|
23
|
+
if (error) setError(error.code === 'table_not_found' ? 'There is no "notes" table in your project yet. See "Connect it later" in the README.' : error.message)
|
|
24
|
+
else setNotes(data)
|
|
25
|
+
setLoading(false)
|
|
26
|
+
})
|
|
27
|
+
return () => {
|
|
28
|
+
ignore = true
|
|
29
|
+
}
|
|
30
|
+
}, [user.id])
|
|
31
|
+
|
|
32
|
+
// Live updates: changes from your other tabs and devices appear here right away.
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
const stop = baas.realtime.subscribe(
|
|
35
|
+
'notes',
|
|
36
|
+
{
|
|
37
|
+
onSubscribed: () => setLive(true),
|
|
38
|
+
onError: (err) => {
|
|
39
|
+
setLive(false)
|
|
40
|
+
console.warn(`Live updates are off: ${err.message}`)
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
(change) => {
|
|
44
|
+
if (change.event === 'DELETE') setNotes((list) => list.filter((n) => n.id !== change.old?.id))
|
|
45
|
+
else if (change.new) setNotes((list) => upsert(list, change.new as Note))
|
|
46
|
+
},
|
|
47
|
+
)
|
|
48
|
+
return () => {
|
|
49
|
+
stop()
|
|
50
|
+
setLive(false)
|
|
51
|
+
}
|
|
52
|
+
}, [user.id])
|
|
53
|
+
|
|
54
|
+
const shown = useMemo(() => {
|
|
55
|
+
const q = query.trim().toLowerCase()
|
|
56
|
+
if (!q) return notes
|
|
57
|
+
return notes.filter((n) => `${n.title} ${n.body ?? ''}`.toLowerCase().includes(q))
|
|
58
|
+
}, [notes, query])
|
|
59
|
+
|
|
60
|
+
return (
|
|
61
|
+
<div className="min-h-dvh">
|
|
62
|
+
<header className="sticky top-0 z-10 border-b border-line bg-[color-mix(in_oklab,var(--paper)_85%,transparent)] backdrop-blur-md">
|
|
63
|
+
<div className="mx-auto flex h-16 max-w-3xl items-center gap-4 px-5 sm:px-8">
|
|
64
|
+
<div className="flex items-center gap-2.5">
|
|
65
|
+
<Logo size={26} />
|
|
66
|
+
<span className="font-serif text-xl font-medium">{brand.name}</span>
|
|
67
|
+
</div>
|
|
68
|
+
<LiveBadge live={live} />
|
|
69
|
+
<div className="ml-auto flex min-w-0 items-center gap-3">
|
|
70
|
+
<span className="hidden truncate text-sm text-muted sm:block" title={user.email ?? ''}>
|
|
71
|
+
{user.email}
|
|
72
|
+
</span>
|
|
73
|
+
<button onClick={() => baas.auth.signOut()} className="h-9 shrink-0 rounded-lg border border-line px-3 text-sm font-medium transition-colors hover:bg-surface">
|
|
74
|
+
Sign out
|
|
75
|
+
</button>
|
|
76
|
+
</div>
|
|
77
|
+
</div>
|
|
78
|
+
</header>
|
|
79
|
+
|
|
80
|
+
<main className="mx-auto max-w-3xl px-3 pt-6 pb-24 sm:px-6 sm:pt-12">
|
|
81
|
+
<div className="mb-4 flex flex-wrap items-center justify-between gap-3 px-2">
|
|
82
|
+
<h1 className="font-serif text-3xl font-medium sm:text-4xl">
|
|
83
|
+
Your notes {!loading && notes.length > 0 && <span className="ml-1 font-sans text-base font-normal text-muted tabular-nums">{notes.length}</span>}
|
|
84
|
+
</h1>
|
|
85
|
+
{notes.length > 2 && (
|
|
86
|
+
<label className="relative block w-full sm:w-64">
|
|
87
|
+
<span className="sr-only">Search your notes</span>
|
|
88
|
+
<SearchIcon className="pointer-events-none absolute top-1/2 left-3.5 -translate-y-1/2 text-muted" />
|
|
89
|
+
<input
|
|
90
|
+
type="search"
|
|
91
|
+
value={query}
|
|
92
|
+
onChange={(e) => setQuery(e.target.value)}
|
|
93
|
+
placeholder="Search"
|
|
94
|
+
className="h-10 w-full rounded-xl border border-line bg-surface pr-3 pl-10 text-sm outline-none focus:border-accent"
|
|
95
|
+
/>
|
|
96
|
+
</label>
|
|
97
|
+
)}
|
|
98
|
+
</div>
|
|
99
|
+
|
|
100
|
+
{/* One sheet of paper: the composer on top, your notes below, a margin down the left. */}
|
|
101
|
+
<div className="margin-rule overflow-hidden rounded-[1.75rem] border border-line bg-surface shadow-card [--rule-x:1.25rem] sm:[--rule-x:7.5rem]">
|
|
102
|
+
<Composer user={user} onCreated={(note) => setNotes((list) => upsert(list, note))} onError={setError} />
|
|
103
|
+
|
|
104
|
+
{error && (
|
|
105
|
+
<p role="alert" className="border-t border-line py-3 pr-5 pl-9 text-sm text-danger sm:pl-36">
|
|
106
|
+
{error}
|
|
107
|
+
</p>
|
|
108
|
+
)}
|
|
109
|
+
|
|
110
|
+
{loading ? (
|
|
111
|
+
<Skeleton />
|
|
112
|
+
) : notes.length === 0 ? (
|
|
113
|
+
<Empty />
|
|
114
|
+
) : shown.length === 0 ? (
|
|
115
|
+
<p className="border-t border-line py-10 pr-5 pl-9 text-muted sm:pl-36">No notes match “{query}”.</p>
|
|
116
|
+
) : (
|
|
117
|
+
<ul aria-label="Your notes">
|
|
118
|
+
{shown.map((note) => (
|
|
119
|
+
<li key={note.id} className="border-t border-line">
|
|
120
|
+
<NoteEntry note={note} user={user} onChanged={(n) => setNotes((list) => upsert(list, n))} onDeleted={(id) => setNotes((list) => list.filter((n) => n.id !== id))} onError={setError} />
|
|
121
|
+
</li>
|
|
122
|
+
))}
|
|
123
|
+
</ul>
|
|
124
|
+
)}
|
|
125
|
+
</div>
|
|
126
|
+
</main>
|
|
127
|
+
</div>
|
|
128
|
+
)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function LiveBadge({ live }: { live: boolean }) {
|
|
132
|
+
return (
|
|
133
|
+
<span
|
|
134
|
+
className="hidden items-center gap-1.5 rounded-full border border-line px-2.5 py-1 text-xs font-medium text-muted sm:inline-flex"
|
|
135
|
+
title={live ? 'Changes from your other tabs and devices appear instantly' : 'Connecting for live updates'}
|
|
136
|
+
>
|
|
137
|
+
<span className={`size-1.5 rounded-full ${live ? 'bg-accent shadow-[0_0_0_3px_var(--accent-soft)]' : 'bg-muted/50'}`} />
|
|
138
|
+
{live ? 'Live' : 'Connecting'}
|
|
139
|
+
</span>
|
|
140
|
+
)
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function Empty() {
|
|
144
|
+
return (
|
|
145
|
+
<div className="border-t border-line py-14 pr-6 pl-9 sm:pl-36">
|
|
146
|
+
<p className="font-serif text-2xl">Your first page is blank</p>
|
|
147
|
+
<p className="mt-2 max-w-sm leading-relaxed text-muted">Write a note above. Then open this page in a second tab: new notes appear there by themselves.</p>
|
|
148
|
+
</div>
|
|
149
|
+
)
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function Skeleton() {
|
|
153
|
+
return (
|
|
154
|
+
<div aria-hidden="true">
|
|
155
|
+
{[0, 1, 2].map((i) => (
|
|
156
|
+
<div key={i} className="space-y-3 border-t border-line py-7 pr-6 pl-9 sm:pl-36">
|
|
157
|
+
<div className="h-5 w-1/3 animate-pulse rounded bg-paper" />
|
|
158
|
+
<div className="h-4 w-4/5 animate-pulse rounded bg-paper" />
|
|
159
|
+
</div>
|
|
160
|
+
))}
|
|
161
|
+
</div>
|
|
162
|
+
)
|
|
163
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// Shown when .env.local is missing: how to connect this app to a usebecky project.
|
|
2
|
+
import type { ReactNode } from 'react'
|
|
3
|
+
import { brand } from '../brand'
|
|
4
|
+
import { Logo } from './icons'
|
|
5
|
+
|
|
6
|
+
export function Setup() {
|
|
7
|
+
return (
|
|
8
|
+
<main className="mx-auto flex min-h-dvh max-w-xl flex-col justify-center px-6 py-16">
|
|
9
|
+
<div className="flex items-center gap-3">
|
|
10
|
+
<Logo />
|
|
11
|
+
<span className="font-serif text-2xl font-medium">{brand.name}</span>
|
|
12
|
+
</div>
|
|
13
|
+
<h1 className="mt-10 font-serif text-4xl leading-tight font-medium text-balance">Connect your project to start writing</h1>
|
|
14
|
+
<p className="mt-4 text-muted">This app needs your usebecky project's address and publishable key. It reads them from a file called <code className="font-mono text-[0.9em] text-ink">.env.local</code>.</p>
|
|
15
|
+
<ol className="mt-8 space-y-4">
|
|
16
|
+
<Step n={1} title="Connect it">
|
|
17
|
+
In this folder, run <Code>npx usebecky init</Code>. It signs you in, lets you pick a project and writes <Code>.env.local</Code>.
|
|
18
|
+
</Step>
|
|
19
|
+
<Step n={2} title="Create the notes table">
|
|
20
|
+
Follow the README, section <em>Connect it later</em>. It takes one paste into the SQL editor.
|
|
21
|
+
</Step>
|
|
22
|
+
<Step n={3} title="Restart">
|
|
23
|
+
Stop <Code>npm run dev</Code> with Ctrl+C and start it again. Vite reads <Code>.env.local</Code> when it starts.
|
|
24
|
+
</Step>
|
|
25
|
+
</ol>
|
|
26
|
+
</main>
|
|
27
|
+
)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function Step({ n, title, children }: { n: number; title: string; children: ReactNode }) {
|
|
31
|
+
return (
|
|
32
|
+
<li className="grid grid-cols-[2rem_1fr] gap-3 rounded-2xl border border-line bg-surface p-5">
|
|
33
|
+
<span className="grid size-7 place-items-center rounded-full bg-accent-soft text-sm font-semibold text-accent">{n}</span>
|
|
34
|
+
<div>
|
|
35
|
+
<p className="font-semibold">{title}</p>
|
|
36
|
+
<p className="mt-1 text-[0.95rem] leading-relaxed text-muted">{children}</p>
|
|
37
|
+
</div>
|
|
38
|
+
</li>
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function Code({ children }: { children: ReactNode }) {
|
|
43
|
+
return <code className="rounded-md bg-paper px-1.5 py-0.5 font-mono text-[0.85em] text-ink">{children}</code>
|
|
44
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
// Sign in or create an account with an email and a password.
|
|
2
|
+
import { useState, type FormEvent } from 'react'
|
|
3
|
+
import { brand } from '../brand'
|
|
4
|
+
import { baas } from '../lib/usebecky'
|
|
5
|
+
import { Logo } from './icons'
|
|
6
|
+
|
|
7
|
+
type Mode = 'sign-in' | 'sign-up'
|
|
8
|
+
|
|
9
|
+
export function SignIn() {
|
|
10
|
+
const [mode, setMode] = useState<Mode>('sign-in')
|
|
11
|
+
const [email, setEmail] = useState('')
|
|
12
|
+
const [password, setPassword] = useState('')
|
|
13
|
+
const [busy, setBusy] = useState(false)
|
|
14
|
+
const [message, setMessage] = useState<{ tone: 'error' | 'info'; text: string } | null>(null)
|
|
15
|
+
|
|
16
|
+
async function submit(event: FormEvent<HTMLFormElement>) {
|
|
17
|
+
event.preventDefault()
|
|
18
|
+
setBusy(true)
|
|
19
|
+
setMessage(null)
|
|
20
|
+
if (mode === 'sign-in') {
|
|
21
|
+
const { error } = await baas.auth.signIn({ email, password })
|
|
22
|
+
if (error) setMessage({ tone: 'error', text: error.code === 'invalid_credentials' ? 'That email and password don’t match. Check for typos, or create an account.' : error.message })
|
|
23
|
+
} else {
|
|
24
|
+
const { data, error } = await baas.auth.signUp({ email, password })
|
|
25
|
+
if (error) setMessage({ tone: 'error', text: error.message })
|
|
26
|
+
else if (!data.session) setMessage({ tone: 'info', text: `Almost there: open the email we sent to ${email} and click the link. Then sign in here.` })
|
|
27
|
+
}
|
|
28
|
+
setBusy(false)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const signUp = mode === 'sign-up'
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<main className="grid min-h-dvh lg:grid-cols-[1.1fr_1fr]">
|
|
35
|
+
{/* The brand side: a sheet of paper with a margin */}
|
|
36
|
+
<section className="margin-rule flex flex-col justify-between gap-12 px-8 pt-10 pb-12 [--rule-x:1.25rem] sm:px-14 sm:[--rule-x:2.25rem] lg:px-20 lg:pt-14 lg:pb-16 lg:[--rule-x:3.25rem]">
|
|
37
|
+
<div className="flex items-center gap-3">
|
|
38
|
+
<Logo />
|
|
39
|
+
<span className="font-serif text-xl font-medium">{brand.name}</span>
|
|
40
|
+
</div>
|
|
41
|
+
<div className="max-w-xl">
|
|
42
|
+
<h1 className="font-serif text-[clamp(3rem,7vw,5.75rem)] leading-[0.95] font-normal tracking-[-0.02em] text-balance">{brand.tagline}</h1>
|
|
43
|
+
<p className="mt-6 max-w-md text-lg leading-relaxed text-muted text-pretty">{brand.description}</p>
|
|
44
|
+
</div>
|
|
45
|
+
<p className="hidden text-sm text-muted lg:block">Your notes are private: only you can read them.</p>
|
|
46
|
+
</section>
|
|
47
|
+
|
|
48
|
+
{/* The form side */}
|
|
49
|
+
<section className="flex items-center justify-center border-line bg-surface px-6 py-12 lg:border-l">
|
|
50
|
+
<div className="w-full max-w-sm">
|
|
51
|
+
<h2 className="font-serif text-3xl font-medium">{signUp ? 'Create your account' : 'Welcome back'}</h2>
|
|
52
|
+
<p className="mt-2 text-muted">{signUp ? 'It takes ten seconds. No credit card.' : 'Sign in to see your notes.'}</p>
|
|
53
|
+
|
|
54
|
+
<form onSubmit={submit} className="mt-8 space-y-4">
|
|
55
|
+
<Field label="Email" type="email" autoComplete="email" value={email} onChange={setEmail} />
|
|
56
|
+
<Field label="Password" type="password" autoComplete={signUp ? 'new-password' : 'current-password'} value={password} onChange={setPassword} hint={signUp ? 'At least 6 characters.' : undefined} minLength={6} />
|
|
57
|
+
<button type="submit" disabled={busy} className="mt-2 h-12 w-full rounded-xl bg-accent font-semibold text-accent-ink transition-[filter,transform] hover:brightness-110 active:scale-[0.99] disabled:opacity-60">
|
|
58
|
+
{busy ? 'One moment…' : signUp ? 'Create account' : 'Sign in'}
|
|
59
|
+
</button>
|
|
60
|
+
</form>
|
|
61
|
+
|
|
62
|
+
{message && (
|
|
63
|
+
<p role={message.tone === 'error' ? 'alert' : 'status'} className={`mt-4 rounded-xl px-4 py-3 text-sm leading-relaxed ${message.tone === 'error' ? 'bg-[color-mix(in_oklab,var(--danger)_10%,transparent)] text-danger' : 'bg-accent-soft text-ink'}`}>
|
|
64
|
+
{message.text}
|
|
65
|
+
</p>
|
|
66
|
+
)}
|
|
67
|
+
|
|
68
|
+
<p className="mt-8 text-sm text-muted">
|
|
69
|
+
{signUp ? 'Already have an account?' : 'New here?'}{' '}
|
|
70
|
+
<button
|
|
71
|
+
type="button"
|
|
72
|
+
className="font-semibold text-accent underline-offset-4 hover:underline"
|
|
73
|
+
onClick={() => {
|
|
74
|
+
setMode(signUp ? 'sign-in' : 'sign-up')
|
|
75
|
+
setMessage(null)
|
|
76
|
+
}}
|
|
77
|
+
>
|
|
78
|
+
{signUp ? 'Sign in' : 'Create an account'}
|
|
79
|
+
</button>
|
|
80
|
+
</p>
|
|
81
|
+
</div>
|
|
82
|
+
</section>
|
|
83
|
+
</main>
|
|
84
|
+
)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function Field(props: { label: string; type: string; value: string; onChange: (v: string) => void; autoComplete: string; hint?: string; minLength?: number }) {
|
|
88
|
+
const id = `field-${props.label.toLowerCase()}`
|
|
89
|
+
return (
|
|
90
|
+
<div>
|
|
91
|
+
<label htmlFor={id} className="mb-1.5 block text-sm font-medium">
|
|
92
|
+
{props.label}
|
|
93
|
+
</label>
|
|
94
|
+
<input
|
|
95
|
+
id={id}
|
|
96
|
+
type={props.type}
|
|
97
|
+
required
|
|
98
|
+
minLength={props.minLength}
|
|
99
|
+
autoComplete={props.autoComplete}
|
|
100
|
+
value={props.value}
|
|
101
|
+
onChange={(e) => props.onChange(e.target.value)}
|
|
102
|
+
aria-describedby={props.hint ? `${id}-hint` : undefined}
|
|
103
|
+
className="h-12 w-full rounded-xl border border-line bg-paper px-4 text-base outline-none transition-colors placeholder:text-muted focus:border-accent focus:bg-surface"
|
|
104
|
+
/>
|
|
105
|
+
{props.hint && (
|
|
106
|
+
<p id={`${id}-hint`} className="mt-1.5 text-xs text-muted">
|
|
107
|
+
{props.hint}
|
|
108
|
+
</p>
|
|
109
|
+
)}
|
|
110
|
+
</div>
|
|
111
|
+
)
|
|
112
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// Small inline icons (no icon package needed). They inherit the text colour.
|
|
2
|
+
import type { SVGProps } from 'react'
|
|
3
|
+
|
|
4
|
+
const base = (props: SVGProps<SVGSVGElement>) => ({
|
|
5
|
+
width: 18,
|
|
6
|
+
height: 18,
|
|
7
|
+
viewBox: '0 0 24 24',
|
|
8
|
+
fill: 'none',
|
|
9
|
+
stroke: 'currentColor',
|
|
10
|
+
strokeWidth: 1.75,
|
|
11
|
+
strokeLinecap: 'round' as const,
|
|
12
|
+
strokeLinejoin: 'round' as const,
|
|
13
|
+
'aria-hidden': true,
|
|
14
|
+
...props,
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
export const ImageIcon = (p: SVGProps<SVGSVGElement>) => (
|
|
18
|
+
<svg {...base(p)}>
|
|
19
|
+
<rect x="3" y="4" width="18" height="16" rx="3" />
|
|
20
|
+
<circle cx="9" cy="10" r="1.75" />
|
|
21
|
+
<path d="m21 16-5.5-5.5L6 20" />
|
|
22
|
+
</svg>
|
|
23
|
+
)
|
|
24
|
+
export const PencilIcon = (p: SVGProps<SVGSVGElement>) => (
|
|
25
|
+
<svg {...base(p)}>
|
|
26
|
+
<path d="M4 20h4L19 9a2.8 2.8 0 0 0-4-4L4 16v4Z" />
|
|
27
|
+
<path d="m13.5 6.5 4 4" />
|
|
28
|
+
</svg>
|
|
29
|
+
)
|
|
30
|
+
export const TrashIcon = (p: SVGProps<SVGSVGElement>) => (
|
|
31
|
+
<svg {...base(p)}>
|
|
32
|
+
<path d="M4 7h16M10 11v6M14 11v6M6 7l1 12a2 2 0 0 0 2 2h6a2 2 0 0 0 2-2l1-12M9 7V4h6v3" />
|
|
33
|
+
</svg>
|
|
34
|
+
)
|
|
35
|
+
export const XIcon = (p: SVGProps<SVGSVGElement>) => (
|
|
36
|
+
<svg {...base(p)}>
|
|
37
|
+
<path d="M6 6l12 12M18 6 6 18" />
|
|
38
|
+
</svg>
|
|
39
|
+
)
|
|
40
|
+
export const SearchIcon = (p: SVGProps<SVGSVGElement>) => (
|
|
41
|
+
<svg {...base(p)}>
|
|
42
|
+
<circle cx="11" cy="11" r="6.5" />
|
|
43
|
+
<path d="m20 20-4.2-4.2" />
|
|
44
|
+
</svg>
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
/** The logo: a page with a margin line. Uses the brand colour. */
|
|
48
|
+
export const Logo = ({ size = 28 }: { size?: number }) => (
|
|
49
|
+
<svg width={size} height={size} viewBox="0 0 32 32" aria-hidden="true">
|
|
50
|
+
<rect x="4" y="3" width="24" height="26" rx="5" fill="var(--accent)" />
|
|
51
|
+
<rect x="10" y="3" width="2" height="26" fill="var(--paper)" opacity=".85" />
|
|
52
|
+
<path d="M15 11h8M15 16h8M15 21h5" stroke="var(--paper)" strokeWidth="2" strokeLinecap="round" />
|
|
53
|
+
</svg>
|
|
54
|
+
)
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
@import 'tailwindcss';
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
Your brand colour. Change this one value and the whole app follows,
|
|
5
|
+
in light and dark mode. Pick a colour dark enough for white text on it.
|
|
6
|
+
*/
|
|
7
|
+
:root {
|
|
8
|
+
--brand: #2f6b4f;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/* Light theme */
|
|
12
|
+
:root {
|
|
13
|
+
color-scheme: light;
|
|
14
|
+
--paper: #f2f3ee;
|
|
15
|
+
--surface: #ffffff;
|
|
16
|
+
--ink: #1b201d;
|
|
17
|
+
--muted: #5b655f;
|
|
18
|
+
--line: #dcdfd6;
|
|
19
|
+
--accent: var(--brand);
|
|
20
|
+
--accent-ink: #ffffff;
|
|
21
|
+
--accent-soft: color-mix(in oklab, var(--brand) 11%, var(--surface));
|
|
22
|
+
--danger: #b42318;
|
|
23
|
+
--shadow: 0 1px 0 rgb(27 32 29 / 0.04), 0 8px 24px -12px rgb(27 32 29 / 0.18);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/* Dark theme (follows your computer's setting) */
|
|
27
|
+
@media (prefers-color-scheme: dark) {
|
|
28
|
+
:root {
|
|
29
|
+
color-scheme: dark;
|
|
30
|
+
--paper: #101412;
|
|
31
|
+
--surface: #181d1a;
|
|
32
|
+
--ink: #e5eae5;
|
|
33
|
+
--muted: #9aa49e;
|
|
34
|
+
--line: #2a312d;
|
|
35
|
+
--accent: color-mix(in oklab, var(--brand) 55%, white);
|
|
36
|
+
--accent-ink: #0d120f;
|
|
37
|
+
--accent-soft: color-mix(in oklab, var(--brand) 30%, var(--surface));
|
|
38
|
+
--danger: #ff8a7a;
|
|
39
|
+
--shadow: 0 1px 0 rgb(0 0 0 / 0.3), 0 10px 30px -14px rgb(0 0 0 / 0.7);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
@theme inline {
|
|
44
|
+
--color-paper: var(--paper);
|
|
45
|
+
--color-surface: var(--surface);
|
|
46
|
+
--color-ink: var(--ink);
|
|
47
|
+
--color-muted: var(--muted);
|
|
48
|
+
--color-line: var(--line);
|
|
49
|
+
--color-accent: var(--accent);
|
|
50
|
+
--color-accent-ink: var(--accent-ink);
|
|
51
|
+
--color-accent-soft: var(--accent-soft);
|
|
52
|
+
--color-danger: var(--danger);
|
|
53
|
+
--shadow-card: var(--shadow);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
@theme {
|
|
57
|
+
--font-sans: 'Instrument Sans Variable', ui-sans-serif, system-ui, sans-serif;
|
|
58
|
+
--font-serif: 'Newsreader Variable', ui-serif, Georgia, serif;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
@layer base {
|
|
62
|
+
html {
|
|
63
|
+
background: var(--paper);
|
|
64
|
+
color: var(--ink);
|
|
65
|
+
-webkit-font-smoothing: antialiased;
|
|
66
|
+
text-rendering: optimizeLegibility;
|
|
67
|
+
}
|
|
68
|
+
body {
|
|
69
|
+
@apply font-sans;
|
|
70
|
+
min-height: 100dvh;
|
|
71
|
+
}
|
|
72
|
+
::selection {
|
|
73
|
+
background: var(--accent-soft);
|
|
74
|
+
}
|
|
75
|
+
:focus-visible {
|
|
76
|
+
outline: 2px solid var(--accent);
|
|
77
|
+
outline-offset: 2px;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/* The notebook margin: one thin brand-coloured rule, used on the composer and the sign-in page. */
|
|
82
|
+
@utility margin-rule {
|
|
83
|
+
position: relative;
|
|
84
|
+
&::before {
|
|
85
|
+
content: '';
|
|
86
|
+
position: absolute;
|
|
87
|
+
inset-block: 0;
|
|
88
|
+
inset-inline-start: var(--rule-x, 2.75rem);
|
|
89
|
+
width: 2px;
|
|
90
|
+
background: color-mix(in oklab, var(--accent) 70%, transparent);
|
|
91
|
+
pointer-events: none;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
@media (prefers-reduced-motion: no-preference) {
|
|
96
|
+
.note-enter {
|
|
97
|
+
animation: note-in 320ms cubic-bezier(0.2, 0.7, 0.2, 1);
|
|
98
|
+
}
|
|
99
|
+
@keyframes note-in {
|
|
100
|
+
from {
|
|
101
|
+
opacity: 0;
|
|
102
|
+
transform: translateY(6px) scale(0.985);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|