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,48 @@
|
|
|
1
|
+
import { StatusBar } from 'expo-status-bar'
|
|
2
|
+
import { useEffect, useState } from 'react'
|
|
3
|
+
import { ActivityIndicator, StyleSheet, Text, View } from 'react-native'
|
|
4
|
+
import { SafeAreaProvider } from 'react-native-safe-area-context'
|
|
5
|
+
import type { User } from 'usebecky'
|
|
6
|
+
import { baas, configured } from './lib/usebecky'
|
|
7
|
+
import { useTheme } from './lib/theme'
|
|
8
|
+
import { HomeScreen } from './screens/Home'
|
|
9
|
+
import { SignInScreen } from './screens/SignIn'
|
|
10
|
+
|
|
11
|
+
export default function App() {
|
|
12
|
+
const theme = useTheme()
|
|
13
|
+
// undefined = still loading the saved session, null = signed out.
|
|
14
|
+
const [user, setUser] = useState<User | null | undefined>(undefined)
|
|
15
|
+
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
// Runs once with the session saved on the phone, then on every sign-in and sign-out.
|
|
18
|
+
return baas.auth.onAuthStateChange((_event, session) => setUser(session?.user ?? null))
|
|
19
|
+
}, [])
|
|
20
|
+
|
|
21
|
+
return (
|
|
22
|
+
<SafeAreaProvider>
|
|
23
|
+
<StatusBar style={theme.dark ? 'light' : 'dark'} />
|
|
24
|
+
{!configured ? (
|
|
25
|
+
<View style={[styles.setup, { backgroundColor: theme.page }]}>
|
|
26
|
+
<Text style={[styles.setupTitle, { color: theme.ink }]}>Connect your project</Text>
|
|
27
|
+
<Text style={[styles.setupText, { color: theme.muted }]}>
|
|
28
|
+
In this folder, run npx usebecky init and pick a project made from the Mobile app template. Then restart Expo with npx expo start -c.
|
|
29
|
+
</Text>
|
|
30
|
+
</View>
|
|
31
|
+
) : user === undefined ? (
|
|
32
|
+
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center', backgroundColor: theme.page }}>
|
|
33
|
+
<ActivityIndicator color={theme.accent} />
|
|
34
|
+
</View>
|
|
35
|
+
) : user ? (
|
|
36
|
+
<HomeScreen user={user} />
|
|
37
|
+
) : (
|
|
38
|
+
<SignInScreen />
|
|
39
|
+
)}
|
|
40
|
+
</SafeAreaProvider>
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const styles = StyleSheet.create({
|
|
45
|
+
setup: { flex: 1, justifyContent: 'center', padding: 28 },
|
|
46
|
+
setupTitle: { fontSize: 30, fontWeight: '800', letterSpacing: -0.6 },
|
|
47
|
+
setupText: { fontSize: 17, lineHeight: 24, marginTop: 12 },
|
|
48
|
+
})
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# Daylist: a mobile app
|
|
2
|
+
|
|
3
|
+
An iPhone and Android app built with Expo (JavaScript and React Native) and usebecky. People sign in with a code from their email, keep a to-do list that updates live on all their phones, and add a profile photo.
|
|
4
|
+
|
|
5
|
+
## What's inside
|
|
6
|
+
|
|
7
|
+
- **Sign in with an emailed code**: no password to remember, and new people are signed up automatically (`screens/SignIn.tsx`).
|
|
8
|
+
- **A live to-do list**: add, tick and delete. Changes from another phone (or the dashboard) appear right away (`screens/Home.tsx`).
|
|
9
|
+
- **A profile photo**, uploaded to the public `avatars` bucket and saved on your profile (`components/Avatar.tsx`).
|
|
10
|
+
- **Stays signed in** after the app restarts (AsyncStorage, in `lib/usebecky.ts`).
|
|
11
|
+
- Light and dark mode follow the phone's setting (`lib/theme.ts`).
|
|
12
|
+
|
|
13
|
+
## Run it
|
|
14
|
+
|
|
15
|
+
You need Node.js 22.18 or newer on your computer (`node -v` shows the version).
|
|
16
|
+
|
|
17
|
+
1. Install **Expo Go** on your phone from the App Store or Google Play.
|
|
18
|
+
2. In this folder, run:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm run dev
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
3. Scan the QR code with the Camera app (iPhone) or with Expo Go (Android). Your phone and computer must be on the same Wi-Fi.
|
|
25
|
+
|
|
26
|
+
Press `i` for the iOS simulator or `a` for the Android emulator instead, if you have them installed.
|
|
27
|
+
|
|
28
|
+
The sign-in code arrives by email.
|
|
29
|
+
|
|
30
|
+
> On a public or office network where the phone can't see your computer, run `npx expo start --tunnel` instead.
|
|
31
|
+
|
|
32
|
+
## If something doesn't work
|
|
33
|
+
|
|
34
|
+
- **Expo Go says the project needs a newer (or older) SDK**: Expo Go only runs the newest Expo version. In this folder, run `npx expo install expo@latest && npx expo install --fix`, then `npm run dev` again.
|
|
35
|
+
- **The phone can't open the app**: check that the phone and computer are on the same Wi-Fi. On a public or office network, try `npx expo start --tunnel`.
|
|
36
|
+
- **"Could not reach the usebecky API" on the phone**: check that the phone is online. If `.env` sets `EXPO_PUBLIC_USEBECKY_URL`, it must be your Project URL from Dashboard → Settings → API keys; restart with `npx expo start -c` after changing it.
|
|
37
|
+
- **No sign-in email**: look in the spam folder, and use the newest code; each one works once.
|
|
38
|
+
|
|
39
|
+
## Make it yours
|
|
40
|
+
|
|
41
|
+
- **Name and colour**: `brand.ts` (`name` and `accent`).
|
|
42
|
+
- **The name under the app icon**: `app.json` (`name`). The icon is `assets/icon.png`.
|
|
43
|
+
- **Colours for light and dark mode**: `lib/theme.ts`.
|
|
44
|
+
|
|
45
|
+
## Connect it later
|
|
46
|
+
|
|
47
|
+
1. In this folder, run `npx usebecky init` and pick a project with the **To-do app (web or mobile)** ready-made setup. It has the `todos` table (with realtime on), `profiles` and the `avatars` bucket.
|
|
48
|
+
2. Restart Expo with `npx expo start -c`, so it reads the new `.env`.
|
|
49
|
+
|
|
50
|
+
## Learn more
|
|
51
|
+
|
|
52
|
+
The docs are at https://usebecky.com/docs, and in your dashboard under **Docs**.
|
|
53
|
+
|
|
54
|
+
- **Expo guide**: keeping people signed in, deep links, uploads, payments and push: https://usebecky.com/docs/frameworks/expo
|
|
55
|
+
- **Realtime guide**: live updates, filters and channels: https://usebecky.com/docs/guides/realtime
|
|
56
|
+
- **Starter apps**: all starters and how to change them: https://usebecky.com/docs/getting-started/starters
|
|
57
|
+
- Building in Swift or Kotlin instead? Follow the iOS guide (https://usebecky.com/docs/frameworks/ios) or the Android guide (https://usebecky.com/docs/frameworks/android).
|
|
58
|
+
|
|
59
|
+
Your AI assistant knows usebecky too: see `.claude/skills/usebecky` and `AGENTS.md`.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"expo": {
|
|
3
|
+
"name": "Daylist",
|
|
4
|
+
"slug": "daylist",
|
|
5
|
+
"scheme": "daylist",
|
|
6
|
+
"version": "1.0.0",
|
|
7
|
+
"orientation": "portrait",
|
|
8
|
+
"userInterfaceStyle": "automatic",
|
|
9
|
+
"icon": "./assets/icon.png",
|
|
10
|
+
"ios": {
|
|
11
|
+
"supportsTablet": true
|
|
12
|
+
},
|
|
13
|
+
"android": {
|
|
14
|
+
"edgeToEdgeEnabled": true
|
|
15
|
+
},
|
|
16
|
+
"plugins": [
|
|
17
|
+
[
|
|
18
|
+
"expo-image-picker",
|
|
19
|
+
{
|
|
20
|
+
"photosPermission": "Pick a photo for your profile."
|
|
21
|
+
}
|
|
22
|
+
]
|
|
23
|
+
]
|
|
24
|
+
}
|
|
25
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Your app's name and colour. The name shown under the app icon is in app.json ("name").
|
|
2
|
+
export const brand = {
|
|
3
|
+
name: 'Daylist',
|
|
4
|
+
tagline: 'Today’s list, on every phone you own.',
|
|
5
|
+
/** The accent colour: buttons, ticks and highlights. Pick one that white text reads well on. */
|
|
6
|
+
accent: '#c2185b',
|
|
7
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// Your profile photo. Tap it to pick a new one: it's uploaded to the public "avatars" bucket,
|
|
2
|
+
// in a folder named after your user id, and saved on your row in the "profiles" table.
|
|
3
|
+
import * as ImagePicker from 'expo-image-picker'
|
|
4
|
+
import { useEffect, useState } from 'react'
|
|
5
|
+
import { ActivityIndicator, Image, Platform, Pressable, StyleSheet, Text, View } from 'react-native'
|
|
6
|
+
import type { User } from 'usebecky'
|
|
7
|
+
import { baas } from '../lib/usebecky'
|
|
8
|
+
import { useTheme } from '../lib/theme'
|
|
9
|
+
|
|
10
|
+
export function Avatar({ user, onError }: { user: User; onError: (message: string) => void }) {
|
|
11
|
+
const t = useTheme()
|
|
12
|
+
const [url, setUrl] = useState<string | null>(null)
|
|
13
|
+
const [busy, setBusy] = useState(false)
|
|
14
|
+
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
baas
|
|
17
|
+
.from('profiles')
|
|
18
|
+
.select('avatar_url')
|
|
19
|
+
.eq('id', user.id)
|
|
20
|
+
.maybeSingle()
|
|
21
|
+
.then(({ data }) => setUrl((data?.avatar_url as string | null) ?? null))
|
|
22
|
+
}, [user.id])
|
|
23
|
+
|
|
24
|
+
async function pick() {
|
|
25
|
+
const picked = await ImagePicker.launchImageLibraryAsync({ mediaTypes: ['images'], allowsEditing: true, aspect: [1, 1], quality: 0.7 })
|
|
26
|
+
if (picked.canceled) return
|
|
27
|
+
const asset = picked.assets[0]
|
|
28
|
+
const path = `${user.id}/avatar.jpg`
|
|
29
|
+
setBusy(true)
|
|
30
|
+
// On a phone, React Native uploads the file when FormData gets its uri, name and type.
|
|
31
|
+
// In a web browser (npx expo start --web) the picked image is a blob: URL, so send the Blob itself.
|
|
32
|
+
let body: FormData | Blob
|
|
33
|
+
if (Platform.OS === 'web') body = await (await fetch(asset.uri)).blob()
|
|
34
|
+
else {
|
|
35
|
+
body = new FormData()
|
|
36
|
+
body.append('file', { uri: asset.uri, name: 'avatar.jpg', type: asset.mimeType ?? 'image/jpeg' } as unknown as Blob)
|
|
37
|
+
}
|
|
38
|
+
const { error } = await baas.storage.from('avatars').upload(path, body, { upsert: true, contentType: asset.mimeType ?? 'image/jpeg' })
|
|
39
|
+
if (error) {
|
|
40
|
+
setBusy(false)
|
|
41
|
+
return onError(`Your photo couldn’t be uploaded: ${error.message}`)
|
|
42
|
+
}
|
|
43
|
+
// A public link; "v=<time>" makes sure the phone doesn't show the old cached photo.
|
|
44
|
+
const publicUrl = `${baas.storage.from('avatars').getPublicUrl(path).data.publicUrl}&v=${Date.now()}`
|
|
45
|
+
await baas.from('profiles').update({ avatar_url: publicUrl }).eq('id', user.id)
|
|
46
|
+
setUrl(publicUrl)
|
|
47
|
+
setBusy(false)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const initial = (user.email ?? '?')[0].toUpperCase()
|
|
51
|
+
return (
|
|
52
|
+
<Pressable onPress={pick} accessibilityRole="button" accessibilityLabel={url ? 'Change your profile photo' : 'Add a profile photo'} hitSlop={8}>
|
|
53
|
+
<View style={[styles.circle, { backgroundColor: t.accentSoft, borderColor: t.surface }]}>
|
|
54
|
+
{url ? <Image source={{ uri: url }} style={styles.image} /> : <Text style={[styles.initial, { color: t.accent }]}>{initial}</Text>}
|
|
55
|
+
{busy && (
|
|
56
|
+
<View style={styles.overlay}>
|
|
57
|
+
<ActivityIndicator color="#fff" />
|
|
58
|
+
</View>
|
|
59
|
+
)}
|
|
60
|
+
</View>
|
|
61
|
+
<View style={[styles.badge, { backgroundColor: t.accent, borderColor: t.page }]}>
|
|
62
|
+
<Text style={[styles.plus, { color: t.onAccent }]}>+</Text>
|
|
63
|
+
</View>
|
|
64
|
+
</Pressable>
|
|
65
|
+
)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const styles = StyleSheet.create({
|
|
69
|
+
circle: { width: 52, height: 52, borderRadius: 26, overflow: 'hidden', alignItems: 'center', justifyContent: 'center', borderWidth: 2 },
|
|
70
|
+
image: { width: '100%', height: '100%' },
|
|
71
|
+
initial: { fontSize: 22, fontWeight: '700' },
|
|
72
|
+
overlay: { ...StyleSheet.absoluteFill, backgroundColor: 'rgba(0,0,0,0.35)', alignItems: 'center', justifyContent: 'center' },
|
|
73
|
+
badge: { position: 'absolute', right: -2, bottom: -2, width: 20, height: 20, borderRadius: 10, borderWidth: 2, alignItems: 'center', justifyContent: 'center' },
|
|
74
|
+
plus: { fontSize: 14, fontWeight: '800', lineHeight: 16 },
|
|
75
|
+
})
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// Small building blocks shared by the screens.
|
|
2
|
+
import type { ReactNode } from 'react'
|
|
3
|
+
import { ActivityIndicator, Pressable, StyleSheet, Text, TextInput, type TextInputProps } from 'react-native'
|
|
4
|
+
import { useTheme } from '../lib/theme'
|
|
5
|
+
|
|
6
|
+
export function Button({ title, onPress, busy, disabled, variant = 'primary' }: { title: string; onPress: () => void; busy?: boolean; disabled?: boolean; variant?: 'primary' | 'plain' }) {
|
|
7
|
+
const t = useTheme()
|
|
8
|
+
const primary = variant === 'primary'
|
|
9
|
+
return (
|
|
10
|
+
<Pressable
|
|
11
|
+
accessibilityRole="button"
|
|
12
|
+
accessibilityState={{ disabled: disabled || busy, busy }}
|
|
13
|
+
onPress={onPress}
|
|
14
|
+
disabled={disabled || busy}
|
|
15
|
+
style={({ pressed }) => [
|
|
16
|
+
styles.button,
|
|
17
|
+
primary ? { backgroundColor: t.accent } : { backgroundColor: 'transparent' },
|
|
18
|
+
{ opacity: disabled ? 0.45 : pressed ? 0.85 : 1 },
|
|
19
|
+
]}
|
|
20
|
+
>
|
|
21
|
+
{busy ? <ActivityIndicator color={primary ? t.onAccent : t.accent} /> : <Text style={[styles.buttonText, { color: primary ? t.onAccent : t.accent }]}>{title}</Text>}
|
|
22
|
+
</Pressable>
|
|
23
|
+
)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function Field(props: TextInputProps & { label: string }) {
|
|
27
|
+
const t = useTheme()
|
|
28
|
+
const { label, style, ...rest } = props
|
|
29
|
+
return (
|
|
30
|
+
<>
|
|
31
|
+
<Text style={[styles.label, { color: t.ink }]}>{label}</Text>
|
|
32
|
+
<TextInput
|
|
33
|
+
accessibilityLabel={label}
|
|
34
|
+
placeholderTextColor={t.muted}
|
|
35
|
+
style={[styles.input, { backgroundColor: t.surface, borderColor: t.line, color: t.ink }, style]}
|
|
36
|
+
{...rest}
|
|
37
|
+
/>
|
|
38
|
+
</>
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function Message({ tone, children }: { tone: 'error' | 'info'; children: ReactNode }) {
|
|
43
|
+
const t = useTheme()
|
|
44
|
+
return (
|
|
45
|
+
<Text accessibilityLiveRegion="polite" style={[styles.message, { color: tone === 'error' ? t.danger : t.muted }]}>
|
|
46
|
+
{children}
|
|
47
|
+
</Text>
|
|
48
|
+
)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const styles = StyleSheet.create({
|
|
52
|
+
button: { height: 52, borderRadius: 14, alignItems: 'center', justifyContent: 'center', paddingHorizontal: 20 },
|
|
53
|
+
buttonText: { fontSize: 17, fontWeight: '600' },
|
|
54
|
+
label: { fontSize: 15, fontWeight: '600', marginBottom: 8 },
|
|
55
|
+
input: { height: 52, borderRadius: 14, borderWidth: 1, paddingHorizontal: 16, fontSize: 17 },
|
|
56
|
+
message: { fontSize: 15, lineHeight: 21, marginTop: 14 },
|
|
57
|
+
})
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// Colours for light and dark mode. The accent comes from brand.ts.
|
|
2
|
+
import { useColorScheme } from 'react-native'
|
|
3
|
+
import { brand } from '../brand'
|
|
4
|
+
|
|
5
|
+
/** Mix a hex colour with white (amount 0..1), for a softer accent in dark mode. */
|
|
6
|
+
function lighten(hex: string, amount: number): string {
|
|
7
|
+
const n = parseInt(hex.slice(1), 16)
|
|
8
|
+
const mix = (c: number) => Math.round(c + (255 - c) * amount)
|
|
9
|
+
const [r, g, b] = [(n >> 16) & 255, (n >> 8) & 255, n & 255].map(mix)
|
|
10
|
+
return `#${((1 << 24) | (r << 16) | (g << 8) | b).toString(16).slice(1)}`
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const light = {
|
|
14
|
+
dark: false,
|
|
15
|
+
page: '#f6f4f5',
|
|
16
|
+
surface: '#ffffff',
|
|
17
|
+
ink: '#1b1619',
|
|
18
|
+
muted: '#6f666b',
|
|
19
|
+
line: '#e6e1e4',
|
|
20
|
+
accent: brand.accent,
|
|
21
|
+
onAccent: '#ffffff',
|
|
22
|
+
accentSoft: lighten(brand.accent, 0.88),
|
|
23
|
+
danger: '#b42318',
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const dark: typeof light = {
|
|
27
|
+
dark: true,
|
|
28
|
+
page: '#121012',
|
|
29
|
+
surface: '#1c191b',
|
|
30
|
+
ink: '#f2eef0',
|
|
31
|
+
muted: '#a39aa0',
|
|
32
|
+
line: '#2e2a2d',
|
|
33
|
+
accent: lighten(brand.accent, 0.35),
|
|
34
|
+
onAccent: '#1b1619',
|
|
35
|
+
accentSoft: '#3a2530',
|
|
36
|
+
danger: '#ff8b7e',
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export type Theme = typeof light
|
|
40
|
+
|
|
41
|
+
export function useTheme(): Theme {
|
|
42
|
+
return useColorScheme() === 'dark' ? dark : light
|
|
43
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Your usebecky client. Sessions are saved with AsyncStorage, so people stay signed in.
|
|
2
|
+
import AsyncStorage from '@react-native-async-storage/async-storage'
|
|
3
|
+
import { createClient } from 'usebecky'
|
|
4
|
+
|
|
5
|
+
/** False until .env has your project's publishable key (App.tsx then explains how to connect). */
|
|
6
|
+
export const configured = Boolean(process.env.EXPO_PUBLIC_USEBECKY_PUBLISHABLE_KEY)
|
|
7
|
+
|
|
8
|
+
export const baas = createClient(
|
|
9
|
+
process.env.EXPO_PUBLIC_USEBECKY_URL, // unset: the hosted API
|
|
10
|
+
process.env.EXPO_PUBLIC_USEBECKY_PUBLISHABLE_KEY || 'ub_pk_notconfigured_0',
|
|
11
|
+
{
|
|
12
|
+
storage: AsyncStorage, // keeps people signed in after the app restarts
|
|
13
|
+
detectSessionInUrl: false, // a native app has no address bar to read
|
|
14
|
+
},
|
|
15
|
+
)
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "daylist",
|
|
3
|
+
"private": true,
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"main": "index.ts",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "expo start",
|
|
8
|
+
"start": "expo start",
|
|
9
|
+
"ios": "expo start --ios",
|
|
10
|
+
"android": "expo start --android",
|
|
11
|
+
"typecheck": "tsc --noEmit"
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@react-native-async-storage/async-storage": "2.2.0",
|
|
15
|
+
"expo": "58.0.21",
|
|
16
|
+
"expo-constants": "58.0.14",
|
|
17
|
+
"expo-haptics": "58.0.7",
|
|
18
|
+
"expo-image-picker": "58.0.10",
|
|
19
|
+
"expo-status-bar": "58.0.4",
|
|
20
|
+
"react": "19.3.0",
|
|
21
|
+
"react-native": "0.88.1",
|
|
22
|
+
"react-native-safe-area-context": "5.10.1",
|
|
23
|
+
"usebecky": "^0.2.0"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@types/react": "19.3.0",
|
|
27
|
+
"typescript": "5.9.3"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
// Your to-do list. Each person sees only their own todos (an access rule on the table), and changes
|
|
2
|
+
// made on another phone or in the dashboard show up right away (realtime).
|
|
3
|
+
import * as Haptics from 'expo-haptics'
|
|
4
|
+
import { useEffect, useMemo, useState } from 'react'
|
|
5
|
+
import { FlatList, KeyboardAvoidingView, Platform, Pressable, StyleSheet, Text, TextInput, View } from 'react-native'
|
|
6
|
+
import { SafeAreaView } from 'react-native-safe-area-context'
|
|
7
|
+
import type { User } from 'usebecky'
|
|
8
|
+
import { Avatar } from '../components/Avatar'
|
|
9
|
+
import { Message } from '../components/ui'
|
|
10
|
+
import { baas } from '../lib/usebecky'
|
|
11
|
+
import { useTheme } from '../lib/theme'
|
|
12
|
+
|
|
13
|
+
type Todo = { id: string; title: string; done: boolean; created_at: string }
|
|
14
|
+
const COLUMNS = 'id, title, done, created_at'
|
|
15
|
+
|
|
16
|
+
function upsert(list: Todo[], todo: Todo): Todo[] {
|
|
17
|
+
return list.some((t) => t.id === todo.id) ? list.map((t) => (t.id === todo.id ? todo : t)) : [...list, todo]
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function HomeScreen({ user }: { user: User }) {
|
|
21
|
+
const t = useTheme()
|
|
22
|
+
const [todos, setTodos] = useState<Todo[]>([])
|
|
23
|
+
const [loading, setLoading] = useState(true)
|
|
24
|
+
const [title, setTitle] = useState('')
|
|
25
|
+
const [error, setError] = useState('')
|
|
26
|
+
const [live, setLive] = useState(false)
|
|
27
|
+
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
baas
|
|
30
|
+
.from('todos')
|
|
31
|
+
.select(COLUMNS)
|
|
32
|
+
.order('created_at', { ascending: true })
|
|
33
|
+
.then(({ data, error }) => {
|
|
34
|
+
if (error) setError(error.code === 'table_not_found' ? 'There is no "todos" table yet. Create the project from the Mobile app template (see the README).' : error.message)
|
|
35
|
+
else setTodos(data as Todo[])
|
|
36
|
+
setLoading(false)
|
|
37
|
+
})
|
|
38
|
+
const stop = baas.realtime.subscribe('todos', { onSubscribed: () => setLive(true), onError: () => setLive(false) }, (change) => {
|
|
39
|
+
if (change.event === 'DELETE') setTodos((list) => list.filter((x) => x.id !== change.old?.id))
|
|
40
|
+
else if (change.new) setTodos((list) => upsert(list, change.new as Todo))
|
|
41
|
+
})
|
|
42
|
+
return stop
|
|
43
|
+
}, [user.id])
|
|
44
|
+
|
|
45
|
+
async function add() {
|
|
46
|
+
const text = title.trim()
|
|
47
|
+
if (!text) return
|
|
48
|
+
setTitle('')
|
|
49
|
+
setError('')
|
|
50
|
+
const { data, error } = await baas.from('todos').insert({ title: text }).select(COLUMNS).single()
|
|
51
|
+
if (error) {
|
|
52
|
+
setTitle(text)
|
|
53
|
+
return setError(error.message)
|
|
54
|
+
}
|
|
55
|
+
setTodos((list) => upsert(list, data as Todo))
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async function toggle(todo: Todo) {
|
|
59
|
+
Haptics.selectionAsync().catch(() => {})
|
|
60
|
+
setTodos((list) => upsert(list, { ...todo, done: !todo.done })) // feels instant; the server confirms
|
|
61
|
+
const { error } = await baas.from('todos').update({ done: !todo.done }).eq('id', todo.id)
|
|
62
|
+
if (error) {
|
|
63
|
+
setTodos((list) => upsert(list, todo))
|
|
64
|
+
setError(error.message)
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async function remove(todo: Todo) {
|
|
69
|
+
setTodos((list) => list.filter((x) => x.id !== todo.id))
|
|
70
|
+
const { error } = await baas.from('todos').delete().eq('id', todo.id)
|
|
71
|
+
if (error) {
|
|
72
|
+
setTodos((list) => upsert(list, todo))
|
|
73
|
+
setError(error.message)
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const done = todos.filter((x) => x.done).length
|
|
78
|
+
const today = useMemo(() => new Date().toLocaleDateString(undefined, { weekday: 'long', day: 'numeric', month: 'long' }), [])
|
|
79
|
+
|
|
80
|
+
return (
|
|
81
|
+
<SafeAreaView style={[styles.screen, { backgroundColor: t.page }]} edges={['top', 'left', 'right']}>
|
|
82
|
+
<KeyboardAvoidingView behavior={Platform.OS === 'ios' ? 'padding' : undefined} style={styles.fill}>
|
|
83
|
+
<View style={styles.header}>
|
|
84
|
+
<View style={styles.fill}>
|
|
85
|
+
<Text style={[styles.date, { color: t.muted }]}>{today}</Text>
|
|
86
|
+
<Text style={[styles.title, { color: t.ink }]} accessibilityRole="header">
|
|
87
|
+
Your list
|
|
88
|
+
</Text>
|
|
89
|
+
</View>
|
|
90
|
+
<Avatar user={user} onError={setError} />
|
|
91
|
+
</View>
|
|
92
|
+
|
|
93
|
+
{todos.length > 0 && (
|
|
94
|
+
<View style={styles.progressRow} accessible accessibilityLabel={`${done} of ${todos.length} done`}>
|
|
95
|
+
<View style={[styles.track, { backgroundColor: t.line }]}>
|
|
96
|
+
<View style={[styles.bar, { backgroundColor: t.accent, width: `${(done / todos.length) * 100}%` }]} />
|
|
97
|
+
</View>
|
|
98
|
+
<Text style={[styles.count, { color: t.muted }]}>
|
|
99
|
+
{done} of {todos.length} done
|
|
100
|
+
</Text>
|
|
101
|
+
</View>
|
|
102
|
+
)}
|
|
103
|
+
|
|
104
|
+
<FlatList
|
|
105
|
+
data={todos}
|
|
106
|
+
keyExtractor={(x) => x.id}
|
|
107
|
+
contentContainerStyle={styles.list}
|
|
108
|
+
keyboardShouldPersistTaps="handled"
|
|
109
|
+
ListEmptyComponent={
|
|
110
|
+
loading ? undefined : (
|
|
111
|
+
<View style={styles.empty}>
|
|
112
|
+
<Text style={[styles.emptyTitle, { color: t.ink }]}>A clear day</Text>
|
|
113
|
+
<Text style={[styles.emptyText, { color: t.muted }]}>Add your first thing below. Sign in on another phone and watch it appear there too.</Text>
|
|
114
|
+
</View>
|
|
115
|
+
)
|
|
116
|
+
}
|
|
117
|
+
renderItem={({ item }) => (
|
|
118
|
+
<View style={[styles.row, { backgroundColor: t.surface, borderColor: t.line }]}>
|
|
119
|
+
<Pressable onPress={() => toggle(item)} accessibilityRole="checkbox" accessibilityState={{ checked: item.done }} accessibilityLabel={item.title} hitSlop={6} style={styles.rowMain}>
|
|
120
|
+
<View style={[styles.check, item.done ? { backgroundColor: t.accent, borderColor: t.accent } : { borderColor: t.muted }]}>{item.done && <Text style={[styles.tick, { color: t.onAccent }]}>✓</Text>}</View>
|
|
121
|
+
<Text style={[styles.todo, { color: item.done ? t.muted : t.ink }, item.done && styles.struck]}>{item.title}</Text>
|
|
122
|
+
</Pressable>
|
|
123
|
+
<Pressable onPress={() => remove(item)} accessibilityRole="button" accessibilityLabel={`Delete ${item.title}`} hitSlop={10} style={styles.delete}>
|
|
124
|
+
<Text style={[styles.deleteText, { color: t.muted }]}>×</Text>
|
|
125
|
+
</Pressable>
|
|
126
|
+
</View>
|
|
127
|
+
)}
|
|
128
|
+
ListFooterComponent={error ? <Message tone="error">{error}</Message> : undefined}
|
|
129
|
+
/>
|
|
130
|
+
|
|
131
|
+
<View style={[styles.composer, { borderTopColor: t.line, backgroundColor: t.page }]}>
|
|
132
|
+
<TextInput
|
|
133
|
+
value={title}
|
|
134
|
+
onChangeText={setTitle}
|
|
135
|
+
placeholder="Add something…"
|
|
136
|
+
placeholderTextColor={t.muted}
|
|
137
|
+
returnKeyType="done"
|
|
138
|
+
onSubmitEditing={add}
|
|
139
|
+
accessibilityLabel="New todo"
|
|
140
|
+
style={[styles.input, { backgroundColor: t.surface, borderColor: t.line, color: t.ink }]}
|
|
141
|
+
/>
|
|
142
|
+
<Pressable onPress={add} disabled={!title.trim()} accessibilityRole="button" accessibilityLabel="Add" style={[styles.add, { backgroundColor: t.accent, opacity: title.trim() ? 1 : 0.45 }]}>
|
|
143
|
+
<Text style={[styles.addText, { color: t.onAccent }]}>+</Text>
|
|
144
|
+
</Pressable>
|
|
145
|
+
</View>
|
|
146
|
+
<View style={[styles.footer, { backgroundColor: t.page }]}>
|
|
147
|
+
<Text style={[styles.footerText, { color: t.muted }]}>
|
|
148
|
+
<Text style={{ color: live ? t.accent : t.muted }}>●</Text> {live ? 'Live' : 'Connecting'} · {user.email}
|
|
149
|
+
</Text>
|
|
150
|
+
<Pressable onPress={() => baas.auth.signOut()} accessibilityRole="button" hitSlop={8}>
|
|
151
|
+
<Text style={[styles.footerText, { color: t.accent, fontWeight: '600' }]}>Sign out</Text>
|
|
152
|
+
</Pressable>
|
|
153
|
+
</View>
|
|
154
|
+
</KeyboardAvoidingView>
|
|
155
|
+
</SafeAreaView>
|
|
156
|
+
)
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const styles = StyleSheet.create({
|
|
160
|
+
screen: { flex: 1 },
|
|
161
|
+
fill: { flex: 1 },
|
|
162
|
+
header: { flexDirection: 'row', alignItems: 'center', paddingHorizontal: 20, paddingTop: 16, gap: 16 },
|
|
163
|
+
date: { fontSize: 15, fontWeight: '500' },
|
|
164
|
+
title: { fontSize: 38, fontWeight: '800', letterSpacing: -1, marginTop: 2 },
|
|
165
|
+
progressRow: { flexDirection: 'row', alignItems: 'center', gap: 12, paddingHorizontal: 20, marginTop: 18 },
|
|
166
|
+
track: { flex: 1, height: 6, borderRadius: 3, overflow: 'hidden' },
|
|
167
|
+
bar: { height: 6, borderRadius: 3 },
|
|
168
|
+
count: { fontSize: 14, fontVariant: ['tabular-nums'] },
|
|
169
|
+
list: { padding: 20, gap: 10, flexGrow: 1 },
|
|
170
|
+
empty: { paddingTop: 48, alignItems: 'flex-start' },
|
|
171
|
+
emptyTitle: { fontSize: 22, fontWeight: '700' },
|
|
172
|
+
emptyText: { fontSize: 16, lineHeight: 22, marginTop: 6, maxWidth: 300 },
|
|
173
|
+
row: { flexDirection: 'row', alignItems: 'center', borderRadius: 16, borderWidth: StyleSheet.hairlineWidth, paddingLeft: 14, paddingRight: 6, minHeight: 58 },
|
|
174
|
+
rowMain: { flex: 1, flexDirection: 'row', alignItems: 'center', gap: 14, paddingVertical: 14 },
|
|
175
|
+
check: { width: 26, height: 26, borderRadius: 13, borderWidth: 2, alignItems: 'center', justifyContent: 'center' },
|
|
176
|
+
tick: { fontSize: 15, fontWeight: '800' },
|
|
177
|
+
todo: { flex: 1, fontSize: 17, lineHeight: 23 },
|
|
178
|
+
struck: { textDecorationLine: 'line-through' },
|
|
179
|
+
delete: { width: 40, height: 40, alignItems: 'center', justifyContent: 'center' },
|
|
180
|
+
deleteText: { fontSize: 26, lineHeight: 28 },
|
|
181
|
+
composer: { flexDirection: 'row', gap: 10, paddingHorizontal: 16, paddingTop: 12, borderTopWidth: StyleSheet.hairlineWidth },
|
|
182
|
+
input: { flex: 1, height: 52, borderRadius: 26, borderWidth: 1, paddingHorizontal: 20, fontSize: 17 },
|
|
183
|
+
add: { width: 52, height: 52, borderRadius: 26, alignItems: 'center', justifyContent: 'center' },
|
|
184
|
+
addText: { fontSize: 30, fontWeight: '500', lineHeight: 34 },
|
|
185
|
+
footer: { flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', paddingHorizontal: 20, paddingVertical: 12, paddingBottom: 24 },
|
|
186
|
+
footerText: { fontSize: 13 },
|
|
187
|
+
})
|