@pylonsync/create-pylon 0.3.53 → 0.3.54
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/bin/create-pylon.js +98 -42
- package/package.json +1 -1
- package/templates/backend/b2b/apps/api/functions/archiveProject.ts +15 -0
- package/templates/backend/b2b/apps/api/functions/createOrg.ts +43 -0
- package/templates/backend/b2b/apps/api/functions/createProject.ts +25 -0
- package/templates/backend/b2b/apps/api/functions/inviteMember.ts +49 -0
- package/templates/backend/b2b/apps/api/functions/myOrgs.ts +37 -0
- package/templates/backend/b2b/apps/api/functions/orgMembers.ts +13 -0
- package/templates/backend/b2b/apps/api/functions/orgProjects.ts +18 -0
- package/templates/backend/b2b/apps/api/functions/removeMember.ts +29 -0
- package/templates/backend/b2b/apps/api/functions/setMemberRole.ts +38 -0
- package/templates/backend/b2b/apps/api/package.json +20 -0
- package/templates/backend/b2b/apps/api/schema.ts +171 -0
- package/templates/backend/b2b/apps/api/tsconfig.json +13 -0
- package/templates/backend/chat/apps/api/functions/createRoom.ts +32 -0
- package/templates/backend/chat/apps/api/functions/listRooms.ts +15 -0
- package/templates/backend/chat/apps/api/functions/roomMessages.ts +20 -0
- package/templates/backend/chat/apps/api/functions/sendMessage.ts +37 -0
- package/templates/backend/chat/apps/api/package.json +20 -0
- package/templates/backend/chat/apps/api/schema.ts +93 -0
- package/templates/backend/chat/apps/api/tsconfig.json +13 -0
- package/templates/backend/consumer/apps/api/functions/createPost.ts +48 -0
- package/templates/backend/consumer/apps/api/functions/deletePost.ts +21 -0
- package/templates/backend/consumer/apps/api/functions/feed.ts +57 -0
- package/templates/backend/consumer/apps/api/functions/myProfile.ts +17 -0
- package/templates/backend/consumer/apps/api/functions/profilePosts.ts +17 -0
- package/templates/backend/consumer/apps/api/functions/toggleLike.ts +48 -0
- package/templates/backend/consumer/apps/api/functions/upsertProfile.ts +70 -0
- package/templates/backend/consumer/apps/api/package.json +20 -0
- package/templates/backend/consumer/apps/api/schema.ts +130 -0
- package/templates/backend/consumer/apps/api/tsconfig.json +13 -0
- package/templates/expo/chat/apps/expo/App.tsx +414 -0
- package/templates/expo/chat/apps/expo/app.json +25 -0
- package/templates/expo/chat/apps/expo/babel.config.js +6 -0
- package/templates/expo/chat/apps/expo/package.json +30 -0
- package/templates/expo/chat/apps/expo/tsconfig.json +16 -0
- package/templates/expo/consumer/apps/expo/App.tsx +360 -0
- package/templates/expo/consumer/apps/expo/app.json +25 -0
- package/templates/expo/consumer/apps/expo/babel.config.js +6 -0
- package/templates/expo/consumer/apps/expo/package.json +30 -0
- package/templates/expo/consumer/apps/expo/tsconfig.json +16 -0
- package/templates/ios/chat/apps/ios/Package.swift +34 -0
- package/templates/ios/chat/apps/ios/Sources/__APP_NAME_PASCAL__/ChatRootView.swift +120 -0
- package/templates/ios/chat/apps/ios/Sources/__APP_NAME_PASCAL__/Models.swift +26 -0
- package/templates/ios/chat/apps/ios/Sources/__APP_NAME_PASCAL__/RoomView.swift +137 -0
- package/templates/ios/chat/apps/ios/Sources/__APP_NAME_PASCAL__/__APP_NAME_PASCAL__App.swift +35 -0
- package/templates/ios/chat/apps/ios/project.yml +42 -0
- package/templates/ios/consumer/apps/ios/Sources/__APP_NAME_PASCAL__/FeedView.swift +170 -0
- package/templates/ios/consumer/apps/ios/Sources/__APP_NAME_PASCAL__/Models.swift +42 -0
- package/templates/ios/consumer/apps/ios/Sources/__APP_NAME_PASCAL__/ProfileSetupView.swift +60 -0
- package/templates/ios/consumer/apps/ios/Sources/__APP_NAME_PASCAL__/RootView.swift +30 -0
- package/templates/ios/consumer/apps/ios/Sources/__APP_NAME_PASCAL__/__APP_NAME_PASCAL__App.swift +29 -0
- package/templates/ios/consumer/apps/ios/project.yml +42 -0
- package/templates/ios/todo/apps/ios/Package.swift +23 -0
- package/templates/mac/b2b/apps/mac/Package.swift +22 -0
- package/templates/mac/b2b/apps/mac/Sources/__APP_NAME_PASCAL__/Models.swift +15 -0
- package/templates/mac/b2b/apps/mac/Sources/__APP_NAME_PASCAL__/OrgPickerView.swift +178 -0
- package/templates/mac/b2b/apps/mac/Sources/__APP_NAME_PASCAL__/__APP_NAME_PASCAL__App.swift +30 -0
- package/templates/mac/b2b/apps/mac/__APP_NAME_PASCAL__.entitlements +13 -0
- package/templates/mac/b2b/apps/mac/project.yml +34 -0
- package/templates/mac/barebones/apps/mac/Package.swift +33 -0
- package/templates/mac/barebones/apps/mac/Sources/__APP_NAME_PASCAL__/ContentView.swift +104 -0
- package/templates/mac/barebones/apps/mac/Sources/__APP_NAME_PASCAL__/Models.swift +17 -0
- package/templates/mac/barebones/apps/mac/Sources/__APP_NAME_PASCAL__/__APP_NAME_PASCAL__App.swift +30 -0
- package/templates/mac/barebones/apps/mac/__APP_NAME_PASCAL__.entitlements +13 -0
- package/templates/mac/barebones/apps/mac/project.yml +34 -0
- package/templates/mac/chat/apps/mac/Package.swift +33 -0
- package/templates/mac/chat/apps/mac/Sources/__APP_NAME_PASCAL__/ChatRootView.swift +140 -0
- package/templates/mac/chat/apps/mac/Sources/__APP_NAME_PASCAL__/Models.swift +26 -0
- package/templates/mac/chat/apps/mac/Sources/__APP_NAME_PASCAL__/RoomView.swift +137 -0
- package/templates/mac/chat/apps/mac/Sources/__APP_NAME_PASCAL__/__APP_NAME_PASCAL__App.swift +37 -0
- package/templates/mac/chat/apps/mac/__APP_NAME_PASCAL__.entitlements +13 -0
- package/templates/mac/chat/apps/mac/project.yml +34 -0
- package/templates/mac/consumer/apps/mac/Package.swift +33 -0
- package/templates/mac/consumer/apps/mac/Sources/__APP_NAME_PASCAL__/FeedView.swift +170 -0
- package/templates/mac/consumer/apps/mac/Sources/__APP_NAME_PASCAL__/Models.swift +42 -0
- package/templates/mac/consumer/apps/mac/Sources/__APP_NAME_PASCAL__/ProfileSetupView.swift +60 -0
- package/templates/mac/consumer/apps/mac/Sources/__APP_NAME_PASCAL__/RootView.swift +30 -0
- package/templates/mac/consumer/apps/mac/Sources/__APP_NAME_PASCAL__/__APP_NAME_PASCAL__App.swift +31 -0
- package/templates/mac/consumer/apps/mac/__APP_NAME_PASCAL__.entitlements +13 -0
- package/templates/mac/consumer/apps/mac/project.yml +34 -0
- package/templates/mac/todo/apps/mac/Package.swift +33 -0
- package/templates/mac/todo/apps/mac/Sources/__APP_NAME_PASCAL__/Models.swift +19 -0
- package/templates/mac/todo/apps/mac/Sources/__APP_NAME_PASCAL__/TodoListView.swift +244 -0
- package/templates/mac/todo/apps/mac/Sources/__APP_NAME_PASCAL__/__APP_NAME_PASCAL__App.swift +30 -0
- package/templates/mac/todo/apps/mac/__APP_NAME_PASCAL__.entitlements +13 -0
- package/templates/mac/todo/apps/mac/project.yml +34 -0
- package/templates/web/b2b/apps/web/next-env.d.ts +2 -0
- package/templates/web/b2b/apps/web/next.config.ts +24 -0
- package/templates/web/b2b/apps/web/package.json +29 -0
- package/templates/web/b2b/apps/web/postcss.config.mjs +3 -0
- package/templates/web/b2b/apps/web/src/app/components/OrgPicker.tsx +171 -0
- package/templates/web/b2b/apps/web/src/app/globals.css +6 -0
- package/templates/web/b2b/apps/web/src/app/layout.tsx +21 -0
- package/templates/web/b2b/apps/web/src/app/page.tsx +39 -0
- package/templates/web/b2b/apps/web/src/lib/pylon.ts +5 -0
- package/templates/web/b2b/apps/web/tsconfig.json +26 -0
- package/templates/web/chat/apps/web/next-env.d.ts +2 -0
- package/templates/web/chat/apps/web/next.config.ts +24 -0
- package/templates/web/chat/apps/web/package.json +29 -0
- package/templates/web/chat/apps/web/postcss.config.mjs +3 -0
- package/templates/web/chat/apps/web/src/app/components/ChatRoom.tsx +250 -0
- package/templates/web/chat/apps/web/src/app/globals.css +6 -0
- package/templates/web/chat/apps/web/src/app/layout.tsx +21 -0
- package/templates/web/chat/apps/web/src/app/page.tsx +51 -0
- package/templates/web/chat/apps/web/src/lib/pylon.ts +5 -0
- package/templates/web/chat/apps/web/tsconfig.json +26 -0
- package/templates/web/consumer/apps/web/next-env.d.ts +2 -0
- package/templates/web/consumer/apps/web/next.config.ts +24 -0
- package/templates/web/consumer/apps/web/package.json +29 -0
- package/templates/web/consumer/apps/web/postcss.config.mjs +3 -0
- package/templates/web/consumer/apps/web/src/app/components/Feed.tsx +295 -0
- package/templates/web/consumer/apps/web/src/app/globals.css +6 -0
- package/templates/web/consumer/apps/web/src/app/layout.tsx +21 -0
- package/templates/web/consumer/apps/web/src/app/page.tsx +55 -0
- package/templates/web/consumer/apps/web/src/lib/pylon.ts +5 -0
- package/templates/web/consumer/apps/web/tsconfig.json +26 -0
- /package/templates/{mobile/barebones/apps/mobile → ios/barebones/apps/ios}/Package.swift +0 -0
- /package/templates/{mobile/barebones/apps/mobile → ios/barebones/apps/ios}/Sources/__APP_NAME_PASCAL__/ContentView.swift +0 -0
- /package/templates/{mobile/barebones/apps/mobile → ios/barebones/apps/ios}/Sources/__APP_NAME_PASCAL__/Models.swift +0 -0
- /package/templates/{mobile/barebones/apps/mobile → ios/barebones/apps/ios}/Sources/__APP_NAME_PASCAL__/__APP_NAME_PASCAL__App.swift +0 -0
- /package/templates/{mobile/barebones/apps/mobile → ios/barebones/apps/ios}/project.yml +0 -0
- /package/templates/{mobile/todo/apps/mobile → ios/consumer/apps/ios}/Package.swift +0 -0
- /package/templates/{mobile/todo/apps/mobile → ios/todo/apps/ios}/Sources/__APP_NAME_PASCAL__/Models.swift +0 -0
- /package/templates/{mobile/todo/apps/mobile → ios/todo/apps/ios}/Sources/__APP_NAME_PASCAL__/TodoListView.swift +0 -0
- /package/templates/{mobile/todo/apps/mobile → ios/todo/apps/ios}/Sources/__APP_NAME_PASCAL__/__APP_NAME_PASCAL__App.swift +0 -0
- /package/templates/{mobile/todo/apps/mobile → ios/todo/apps/ios}/project.yml +0 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { mutation, v } from "@pylonsync/functions";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Create-or-update the caller's Profile. Handle is unique (case-
|
|
5
|
+
* insensitive); we lowercase + check before inserting. On update
|
|
6
|
+
* we don't re-check the handle if it didn't change.
|
|
7
|
+
*/
|
|
8
|
+
export default mutation({
|
|
9
|
+
args: {
|
|
10
|
+
handle: v.string(),
|
|
11
|
+
displayName: v.string(),
|
|
12
|
+
bio: v.string(),
|
|
13
|
+
},
|
|
14
|
+
async handler(
|
|
15
|
+
ctx,
|
|
16
|
+
args: { handle: string; displayName: string; bio: string },
|
|
17
|
+
) {
|
|
18
|
+
if (!ctx.auth.userId) {
|
|
19
|
+
throw ctx.error("UNAUTHENTICATED", "log in first");
|
|
20
|
+
}
|
|
21
|
+
const handle = args.handle.trim().toLowerCase();
|
|
22
|
+
if (!/^[a-z0-9_]{2,20}$/.test(handle)) {
|
|
23
|
+
throw ctx.error(
|
|
24
|
+
"INVALID_HANDLE",
|
|
25
|
+
"handle must be 2–20 chars: lowercase letters, digits, underscore",
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
const displayName = args.displayName.trim();
|
|
29
|
+
if (!displayName) {
|
|
30
|
+
throw ctx.error("EMPTY_NAME", "displayName cannot be empty");
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const existing = (await ctx.db.query("Profile", {
|
|
34
|
+
userId: ctx.auth.userId,
|
|
35
|
+
})) as any[];
|
|
36
|
+
|
|
37
|
+
if (existing.length === 0) {
|
|
38
|
+
// New profile — handle must be unique
|
|
39
|
+
const dup = (await ctx.db.query("Profile", { handle })) as any[];
|
|
40
|
+
if (dup.length > 0) {
|
|
41
|
+
throw ctx.error("HANDLE_TAKEN", `@${handle} is taken`);
|
|
42
|
+
}
|
|
43
|
+
const id = await ctx.db.insert("Profile", {
|
|
44
|
+
userId: ctx.auth.userId,
|
|
45
|
+
handle,
|
|
46
|
+
displayName,
|
|
47
|
+
bio: args.bio.trim() || null,
|
|
48
|
+
createdAt: new Date().toISOString(),
|
|
49
|
+
});
|
|
50
|
+
return await ctx.db.get("Profile", id);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const profile = existing[0];
|
|
54
|
+
// Update — re-check handle uniqueness only if changing
|
|
55
|
+
if (profile.handle !== handle) {
|
|
56
|
+
const dup = ((await ctx.db.query("Profile", { handle })) as any[]).filter(
|
|
57
|
+
(p) => p.id !== profile.id,
|
|
58
|
+
);
|
|
59
|
+
if (dup.length > 0) {
|
|
60
|
+
throw ctx.error("HANDLE_TAKEN", `@${handle} is taken`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
await ctx.db.update("Profile", profile.id, {
|
|
64
|
+
handle,
|
|
65
|
+
displayName,
|
|
66
|
+
bio: args.bio.trim() || null,
|
|
67
|
+
});
|
|
68
|
+
return await ctx.db.get("Profile", profile.id);
|
|
69
|
+
},
|
|
70
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@__APP_NAME_KEBAB__/api",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"private": true,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "pylon dev schema.ts --port 4321",
|
|
8
|
+
"build": "pylon codegen schema.ts --out pylon.manifest.json && pylon codegen client pylon.manifest.json --out pylon.client.ts",
|
|
9
|
+
"schema:push": "pylon schema push pylon.manifest.json --sqlite dev.db",
|
|
10
|
+
"schema:inspect": "pylon schema inspect --sqlite dev.db"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@pylonsync/sdk": "^__PYLON_VERSION__",
|
|
14
|
+
"@pylonsync/functions": "^__PYLON_VERSION__"
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"@pylonsync/cli": "^__PYLON_VERSION__",
|
|
18
|
+
"typescript": "^5.5.0"
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import {
|
|
2
|
+
entity,
|
|
3
|
+
field,
|
|
4
|
+
query,
|
|
5
|
+
action,
|
|
6
|
+
policy,
|
|
7
|
+
buildManifest,
|
|
8
|
+
} from "@pylonsync/sdk";
|
|
9
|
+
|
|
10
|
+
// ---------------------------------------------------------------------------
|
|
11
|
+
// Consumer feed schema. The shape:
|
|
12
|
+
//
|
|
13
|
+
// Profile — public-facing card per User. Handle, display name, bio.
|
|
14
|
+
// Post — one row per post. authorId references the Profile that
|
|
15
|
+
// created it; body holds the text.
|
|
16
|
+
// Like — pivot row: which Profile liked which Post. Composite
|
|
17
|
+
// uniqueness enforced via the ordering of inserts (one
|
|
18
|
+
// row per (profileId, postId) pair).
|
|
19
|
+
//
|
|
20
|
+
// Reads are wide-open by design — feeds are public. Writes require
|
|
21
|
+
// the caller to own the Profile in question (auth.userId == profileId
|
|
22
|
+
// for Profile updates; auth.userId must own a Profile to post).
|
|
23
|
+
// ---------------------------------------------------------------------------
|
|
24
|
+
|
|
25
|
+
const Profile = entity("Profile", {
|
|
26
|
+
userId: field.id("User"),
|
|
27
|
+
handle: field.string(),
|
|
28
|
+
displayName: field.string(),
|
|
29
|
+
bio: field.string().optional(),
|
|
30
|
+
createdAt: field.datetime(),
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const Post = entity("Post", {
|
|
34
|
+
authorId: field.id("Profile"),
|
|
35
|
+
body: field.string(),
|
|
36
|
+
createdAt: field.datetime(),
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const Like = entity("Like", {
|
|
40
|
+
profileId: field.id("Profile"),
|
|
41
|
+
postId: field.id("Post"),
|
|
42
|
+
createdAt: field.datetime(),
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// ---------------------------------------------------------------------------
|
|
46
|
+
// Function declarations
|
|
47
|
+
// ---------------------------------------------------------------------------
|
|
48
|
+
|
|
49
|
+
const myProfile = query("myProfile");
|
|
50
|
+
const feed = query("feed");
|
|
51
|
+
const profilePosts = query("profilePosts");
|
|
52
|
+
|
|
53
|
+
const upsertProfile = action("upsertProfile", {
|
|
54
|
+
input: [
|
|
55
|
+
{ name: "handle", type: "string" },
|
|
56
|
+
{ name: "displayName", type: "string" },
|
|
57
|
+
{ name: "bio", type: "string" },
|
|
58
|
+
],
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
const createPost = action("createPost", {
|
|
62
|
+
input: [{ name: "body", type: "string" }],
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const deletePost = action("deletePost", {
|
|
66
|
+
input: [{ name: "id", type: "id(Post)" }],
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
const toggleLike = action("toggleLike", {
|
|
70
|
+
input: [{ name: "postId", type: "id(Post)" }],
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
// ---------------------------------------------------------------------------
|
|
74
|
+
// Policies — public reads, owner-only writes.
|
|
75
|
+
// ---------------------------------------------------------------------------
|
|
76
|
+
|
|
77
|
+
const profilePolicy = policy({
|
|
78
|
+
name: "profile_public",
|
|
79
|
+
entity: "Profile",
|
|
80
|
+
allowRead: "true",
|
|
81
|
+
allowInsert: "auth.userId == data.userId",
|
|
82
|
+
allowUpdate: "auth.userId == data.userId",
|
|
83
|
+
allowDelete: "auth.userId == data.userId",
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
const postPolicy = policy({
|
|
87
|
+
name: "post_public",
|
|
88
|
+
entity: "Post",
|
|
89
|
+
allowRead: "true",
|
|
90
|
+
// Caller must own a Profile that's being claimed as the author.
|
|
91
|
+
allowInsert:
|
|
92
|
+
"exists(Profile where id = data.authorId and userId = auth.userId)",
|
|
93
|
+
allowUpdate:
|
|
94
|
+
"exists(Profile where id = data.authorId and userId = auth.userId)",
|
|
95
|
+
allowDelete:
|
|
96
|
+
"exists(Profile where id = data.authorId and userId = auth.userId)",
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
const likePolicy = policy({
|
|
100
|
+
name: "like_public",
|
|
101
|
+
entity: "Like",
|
|
102
|
+
allowRead: "true",
|
|
103
|
+
// Caller must own the Profile doing the liking.
|
|
104
|
+
allowInsert:
|
|
105
|
+
"exists(Profile where id = data.profileId and userId = auth.userId)",
|
|
106
|
+
allowUpdate: "false",
|
|
107
|
+
allowDelete:
|
|
108
|
+
"exists(Profile where id = data.profileId and userId = auth.userId)",
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
// ---------------------------------------------------------------------------
|
|
112
|
+
// Manifest
|
|
113
|
+
// ---------------------------------------------------------------------------
|
|
114
|
+
|
|
115
|
+
const manifest = buildManifest({
|
|
116
|
+
name: "__APP_NAME_SNAKE__",
|
|
117
|
+
version: "0.0.1",
|
|
118
|
+
entities: [Profile, Post, Like],
|
|
119
|
+
queries: [myProfile, feed, profilePosts],
|
|
120
|
+
actions: [
|
|
121
|
+
upsertProfile,
|
|
122
|
+
createPost,
|
|
123
|
+
deletePost,
|
|
124
|
+
toggleLike,
|
|
125
|
+
],
|
|
126
|
+
policies: [profilePolicy, postPolicy, likePolicy],
|
|
127
|
+
routes: [],
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
console.log(JSON.stringify(manifest));
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "Bundler",
|
|
6
|
+
"strict": true,
|
|
7
|
+
"skipLibCheck": true,
|
|
8
|
+
"noEmit": true,
|
|
9
|
+
"esModuleInterop": true,
|
|
10
|
+
"allowSyntheticDefaultImports": true
|
|
11
|
+
},
|
|
12
|
+
"include": ["schema.ts", "functions/**/*.ts"]
|
|
13
|
+
}
|
|
@@ -0,0 +1,414 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from "react";
|
|
2
|
+
import {
|
|
3
|
+
View,
|
|
4
|
+
Text,
|
|
5
|
+
TextInput,
|
|
6
|
+
Pressable,
|
|
7
|
+
FlatList,
|
|
8
|
+
ActivityIndicator,
|
|
9
|
+
StyleSheet,
|
|
10
|
+
Platform,
|
|
11
|
+
Alert,
|
|
12
|
+
KeyboardAvoidingView,
|
|
13
|
+
SafeAreaView,
|
|
14
|
+
} from "react-native";
|
|
15
|
+
import { StatusBar } from "expo-status-bar";
|
|
16
|
+
import { init, callFn } from "@pylonsync/react-native";
|
|
17
|
+
|
|
18
|
+
const PYLON_BASE_URL =
|
|
19
|
+
process.env.EXPO_PUBLIC_PYLON_BASE_URL ??
|
|
20
|
+
(Platform.OS === "android" ? "http://10.0.2.2:4321" : "http://localhost:4321");
|
|
21
|
+
|
|
22
|
+
type Room = {
|
|
23
|
+
id: string;
|
|
24
|
+
slug: string;
|
|
25
|
+
name: string;
|
|
26
|
+
createdAt: string;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
type Message = {
|
|
30
|
+
id: string;
|
|
31
|
+
roomId: string;
|
|
32
|
+
authorId: string;
|
|
33
|
+
authorName: string;
|
|
34
|
+
body: string;
|
|
35
|
+
createdAt: string;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
let initPromise: Promise<void> | null = null;
|
|
39
|
+
function ensureInit() {
|
|
40
|
+
if (!initPromise) {
|
|
41
|
+
initPromise = init({
|
|
42
|
+
baseUrl: PYLON_BASE_URL,
|
|
43
|
+
appName: "__APP_NAME_SNAKE__",
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
return initPromise;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export default function App() {
|
|
50
|
+
const [ready, setReady] = useState(false);
|
|
51
|
+
const [rooms, setRooms] = useState<Room[]>([]);
|
|
52
|
+
const [active, setActive] = useState<Room | null>(null);
|
|
53
|
+
const [authorName, setAuthorName] = useState("anonymous");
|
|
54
|
+
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
ensureInit().then(async () => {
|
|
57
|
+
try {
|
|
58
|
+
const list = await callFn<Room[]>("listRooms", {});
|
|
59
|
+
setRooms(list);
|
|
60
|
+
setActive(list[0] ?? null);
|
|
61
|
+
} catch (e) {
|
|
62
|
+
Alert.alert("Load failed", String(e));
|
|
63
|
+
}
|
|
64
|
+
setReady(true);
|
|
65
|
+
});
|
|
66
|
+
}, []);
|
|
67
|
+
|
|
68
|
+
if (!ready) {
|
|
69
|
+
return (
|
|
70
|
+
<View style={[styles.screen, styles.center]}>
|
|
71
|
+
<ActivityIndicator />
|
|
72
|
+
</View>
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (!active) {
|
|
77
|
+
return (
|
|
78
|
+
<RoomCreate
|
|
79
|
+
authorName={authorName}
|
|
80
|
+
onAuthorNameChange={setAuthorName}
|
|
81
|
+
onCreated={(r) => {
|
|
82
|
+
setRooms((prev) => [...prev, r]);
|
|
83
|
+
setActive(r);
|
|
84
|
+
}}
|
|
85
|
+
/>
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return (
|
|
90
|
+
<RoomView
|
|
91
|
+
room={active}
|
|
92
|
+
rooms={rooms}
|
|
93
|
+
onSwitch={setActive}
|
|
94
|
+
authorName={authorName}
|
|
95
|
+
onAuthorNameChange={setAuthorName}
|
|
96
|
+
onCreate={(r) => {
|
|
97
|
+
setRooms((prev) => [...prev, r]);
|
|
98
|
+
setActive(r);
|
|
99
|
+
}}
|
|
100
|
+
/>
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function RoomCreate({
|
|
105
|
+
authorName,
|
|
106
|
+
onAuthorNameChange,
|
|
107
|
+
onCreated,
|
|
108
|
+
}: {
|
|
109
|
+
authorName: string;
|
|
110
|
+
onAuthorNameChange: (s: string) => void;
|
|
111
|
+
onCreated: (r: Room) => void;
|
|
112
|
+
}) {
|
|
113
|
+
const [name, setName] = useState("General");
|
|
114
|
+
const [slug, setSlug] = useState("general");
|
|
115
|
+
const [creating, setCreating] = useState(false);
|
|
116
|
+
|
|
117
|
+
async function create() {
|
|
118
|
+
setCreating(true);
|
|
119
|
+
try {
|
|
120
|
+
const r = await callFn<Room>("createRoom", {
|
|
121
|
+
slug: slug.toLowerCase(),
|
|
122
|
+
name,
|
|
123
|
+
});
|
|
124
|
+
onCreated(r);
|
|
125
|
+
} catch (e) {
|
|
126
|
+
Alert.alert("Create failed", String(e));
|
|
127
|
+
} finally {
|
|
128
|
+
setCreating(false);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return (
|
|
133
|
+
<SafeAreaView style={styles.screen}>
|
|
134
|
+
<StatusBar style="auto" />
|
|
135
|
+
<View style={styles.content}>
|
|
136
|
+
<Text style={styles.title}>__APP_NAME__</Text>
|
|
137
|
+
<Text style={styles.subtitle}>No rooms yet — create one.</Text>
|
|
138
|
+
<TextInput
|
|
139
|
+
style={styles.input}
|
|
140
|
+
placeholder="Your display name"
|
|
141
|
+
value={authorName}
|
|
142
|
+
onChangeText={onAuthorNameChange}
|
|
143
|
+
/>
|
|
144
|
+
<TextInput
|
|
145
|
+
style={styles.input}
|
|
146
|
+
placeholder="Room name"
|
|
147
|
+
value={name}
|
|
148
|
+
onChangeText={setName}
|
|
149
|
+
/>
|
|
150
|
+
<TextInput
|
|
151
|
+
style={styles.input}
|
|
152
|
+
placeholder="Slug"
|
|
153
|
+
value={slug}
|
|
154
|
+
onChangeText={(s) => setSlug(s.toLowerCase())}
|
|
155
|
+
autoCapitalize="none"
|
|
156
|
+
autoCorrect={false}
|
|
157
|
+
/>
|
|
158
|
+
<Pressable
|
|
159
|
+
onPress={create}
|
|
160
|
+
disabled={creating || !name.trim() || !slug.trim()}
|
|
161
|
+
style={({ pressed }) => [
|
|
162
|
+
styles.button,
|
|
163
|
+
(creating || !name.trim() || !slug.trim()) && styles.buttonDisabled,
|
|
164
|
+
pressed && styles.buttonPressed,
|
|
165
|
+
]}
|
|
166
|
+
>
|
|
167
|
+
<Text style={styles.buttonLabel}>
|
|
168
|
+
{creating ? "Creating…" : "Create room"}
|
|
169
|
+
</Text>
|
|
170
|
+
</Pressable>
|
|
171
|
+
</View>
|
|
172
|
+
</SafeAreaView>
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function RoomView({
|
|
177
|
+
room,
|
|
178
|
+
rooms,
|
|
179
|
+
onSwitch,
|
|
180
|
+
authorName,
|
|
181
|
+
onAuthorNameChange,
|
|
182
|
+
onCreate,
|
|
183
|
+
}: {
|
|
184
|
+
room: Room;
|
|
185
|
+
rooms: Room[];
|
|
186
|
+
onSwitch: (r: Room) => void;
|
|
187
|
+
authorName: string;
|
|
188
|
+
onAuthorNameChange: (s: string) => void;
|
|
189
|
+
onCreate: (r: Room) => void;
|
|
190
|
+
}) {
|
|
191
|
+
const [messages, setMessages] = useState<Message[]>([]);
|
|
192
|
+
const [draft, setDraft] = useState("");
|
|
193
|
+
const [sending, setSending] = useState(false);
|
|
194
|
+
const listRef = useRef<FlatList<Message>>(null);
|
|
195
|
+
|
|
196
|
+
useEffect(() => {
|
|
197
|
+
void load();
|
|
198
|
+
const t = setInterval(load, 1500);
|
|
199
|
+
return () => clearInterval(t);
|
|
200
|
+
async function load() {
|
|
201
|
+
try {
|
|
202
|
+
const m = await callFn<Message[]>("roomMessages", { roomId: room.id });
|
|
203
|
+
setMessages(m);
|
|
204
|
+
} catch {
|
|
205
|
+
// ignore — will retry on next tick
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}, [room.id]);
|
|
209
|
+
|
|
210
|
+
useEffect(() => {
|
|
211
|
+
if (messages.length > 0) {
|
|
212
|
+
listRef.current?.scrollToEnd({ animated: true });
|
|
213
|
+
}
|
|
214
|
+
}, [messages.length]);
|
|
215
|
+
|
|
216
|
+
async function send() {
|
|
217
|
+
const body = draft.trim();
|
|
218
|
+
if (!body) return;
|
|
219
|
+
setSending(true);
|
|
220
|
+
setDraft("");
|
|
221
|
+
try {
|
|
222
|
+
const msg = await callFn<Message>("sendMessage", {
|
|
223
|
+
roomId: room.id,
|
|
224
|
+
body,
|
|
225
|
+
authorName,
|
|
226
|
+
});
|
|
227
|
+
setMessages((prev) => [...prev, msg]);
|
|
228
|
+
} catch (e) {
|
|
229
|
+
setDraft(body);
|
|
230
|
+
Alert.alert("Send failed", String(e));
|
|
231
|
+
} finally {
|
|
232
|
+
setSending(false);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
async function createRoom() {
|
|
237
|
+
const name = window?.prompt?.("Room name?") ?? null;
|
|
238
|
+
if (!name) return;
|
|
239
|
+
const slug = name
|
|
240
|
+
.toLowerCase()
|
|
241
|
+
.replace(/[^a-z0-9]+/g, "-")
|
|
242
|
+
.replace(/^-|-$/g, "");
|
|
243
|
+
try {
|
|
244
|
+
const r = await callFn<Room>("createRoom", { slug, name });
|
|
245
|
+
onCreate(r);
|
|
246
|
+
} catch (e) {
|
|
247
|
+
Alert.alert("Create failed", String(e));
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
return (
|
|
252
|
+
<SafeAreaView style={styles.screen}>
|
|
253
|
+
<StatusBar style="auto" />
|
|
254
|
+
<KeyboardAvoidingView
|
|
255
|
+
style={styles.flex}
|
|
256
|
+
behavior={Platform.OS === "ios" ? "padding" : undefined}
|
|
257
|
+
keyboardVerticalOffset={64}
|
|
258
|
+
>
|
|
259
|
+
<View style={styles.header}>
|
|
260
|
+
<View>
|
|
261
|
+
<Text style={styles.title}>{room.name}</Text>
|
|
262
|
+
<Text style={styles.handle}>#{room.slug}</Text>
|
|
263
|
+
</View>
|
|
264
|
+
{rooms.length > 1 && (
|
|
265
|
+
<Pressable
|
|
266
|
+
onPress={() => {
|
|
267
|
+
// Cycle to next room — simplest "switch room" UX without a sidebar.
|
|
268
|
+
const idx = rooms.findIndex((r) => r.id === room.id);
|
|
269
|
+
onSwitch(rooms[(idx + 1) % rooms.length]);
|
|
270
|
+
}}
|
|
271
|
+
>
|
|
272
|
+
<Text style={styles.switchBtn}>Next room →</Text>
|
|
273
|
+
</Pressable>
|
|
274
|
+
)}
|
|
275
|
+
</View>
|
|
276
|
+
|
|
277
|
+
<View style={styles.namebar}>
|
|
278
|
+
<Text style={styles.namelabel}>You:</Text>
|
|
279
|
+
<TextInput
|
|
280
|
+
style={styles.nameinput}
|
|
281
|
+
value={authorName}
|
|
282
|
+
onChangeText={onAuthorNameChange}
|
|
283
|
+
autoCapitalize="none"
|
|
284
|
+
/>
|
|
285
|
+
</View>
|
|
286
|
+
|
|
287
|
+
<FlatList
|
|
288
|
+
ref={listRef}
|
|
289
|
+
data={messages}
|
|
290
|
+
keyExtractor={(m) => m.id}
|
|
291
|
+
contentContainerStyle={{ padding: 16 }}
|
|
292
|
+
ListEmptyComponent={() => (
|
|
293
|
+
<Text style={styles.empty}>No messages yet. Say hi.</Text>
|
|
294
|
+
)}
|
|
295
|
+
renderItem={({ item }) => (
|
|
296
|
+
<View style={styles.msg}>
|
|
297
|
+
<View style={styles.msgHead}>
|
|
298
|
+
<Text style={styles.msgName}>{item.authorName}</Text>
|
|
299
|
+
<Text style={styles.msgTime}>
|
|
300
|
+
{new Date(item.createdAt).toLocaleTimeString(undefined, {
|
|
301
|
+
hour: "numeric",
|
|
302
|
+
minute: "2-digit",
|
|
303
|
+
})}
|
|
304
|
+
</Text>
|
|
305
|
+
</View>
|
|
306
|
+
<Text style={styles.msgBody}>{item.body}</Text>
|
|
307
|
+
</View>
|
|
308
|
+
)}
|
|
309
|
+
/>
|
|
310
|
+
|
|
311
|
+
<View style={styles.composer}>
|
|
312
|
+
<TextInput
|
|
313
|
+
style={styles.composerInput}
|
|
314
|
+
value={draft}
|
|
315
|
+
onChangeText={setDraft}
|
|
316
|
+
placeholder={`Message ${room.name}…`}
|
|
317
|
+
multiline
|
|
318
|
+
editable={!sending}
|
|
319
|
+
/>
|
|
320
|
+
<Pressable
|
|
321
|
+
onPress={send}
|
|
322
|
+
disabled={sending || !draft.trim()}
|
|
323
|
+
style={({ pressed }) => [
|
|
324
|
+
styles.button,
|
|
325
|
+
(sending || !draft.trim()) && styles.buttonDisabled,
|
|
326
|
+
pressed && styles.buttonPressed,
|
|
327
|
+
]}
|
|
328
|
+
>
|
|
329
|
+
<Text style={styles.buttonLabel}>Send</Text>
|
|
330
|
+
</Pressable>
|
|
331
|
+
</View>
|
|
332
|
+
</KeyboardAvoidingView>
|
|
333
|
+
</SafeAreaView>
|
|
334
|
+
);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
const styles = StyleSheet.create({
|
|
338
|
+
screen: { flex: 1, backgroundColor: "#fff" },
|
|
339
|
+
flex: { flex: 1 },
|
|
340
|
+
center: { alignItems: "center", justifyContent: "center" },
|
|
341
|
+
content: { padding: 20, gap: 12 },
|
|
342
|
+
title: { fontSize: 24, fontWeight: "600" },
|
|
343
|
+
subtitle: { color: "#666" },
|
|
344
|
+
handle: { fontFamily: "Menlo", fontSize: 12, color: "#999" },
|
|
345
|
+
header: {
|
|
346
|
+
paddingHorizontal: 20,
|
|
347
|
+
paddingTop: 12,
|
|
348
|
+
paddingBottom: 8,
|
|
349
|
+
flexDirection: "row",
|
|
350
|
+
justifyContent: "space-between",
|
|
351
|
+
alignItems: "flex-end",
|
|
352
|
+
borderBottomWidth: 1,
|
|
353
|
+
borderColor: "#e5e5e5",
|
|
354
|
+
},
|
|
355
|
+
switchBtn: { color: "#3b82f6", fontSize: 13 },
|
|
356
|
+
namebar: {
|
|
357
|
+
flexDirection: "row",
|
|
358
|
+
alignItems: "center",
|
|
359
|
+
gap: 6,
|
|
360
|
+
paddingHorizontal: 20,
|
|
361
|
+
paddingVertical: 6,
|
|
362
|
+
backgroundColor: "#fafafa",
|
|
363
|
+
},
|
|
364
|
+
namelabel: { fontSize: 12, color: "#666" },
|
|
365
|
+
nameinput: {
|
|
366
|
+
flex: 1,
|
|
367
|
+
borderBottomWidth: 1,
|
|
368
|
+
borderColor: "#d4d4d8",
|
|
369
|
+
fontSize: 13,
|
|
370
|
+
paddingVertical: 2,
|
|
371
|
+
},
|
|
372
|
+
input: {
|
|
373
|
+
borderWidth: 1,
|
|
374
|
+
borderColor: "#d4d4d8",
|
|
375
|
+
borderRadius: 6,
|
|
376
|
+
paddingHorizontal: 12,
|
|
377
|
+
paddingVertical: 8,
|
|
378
|
+
fontSize: 14,
|
|
379
|
+
},
|
|
380
|
+
button: {
|
|
381
|
+
backgroundColor: "#171717",
|
|
382
|
+
borderRadius: 6,
|
|
383
|
+
paddingHorizontal: 16,
|
|
384
|
+
paddingVertical: 12,
|
|
385
|
+
alignItems: "center",
|
|
386
|
+
},
|
|
387
|
+
buttonDisabled: { opacity: 0.5 },
|
|
388
|
+
buttonPressed: { opacity: 0.8 },
|
|
389
|
+
buttonLabel: { color: "#fff", fontWeight: "600", fontSize: 13 },
|
|
390
|
+
empty: { textAlign: "center", color: "#999", marginTop: 32 },
|
|
391
|
+
msg: { marginBottom: 16 },
|
|
392
|
+
msgHead: { flexDirection: "row", alignItems: "baseline", gap: 6 },
|
|
393
|
+
msgName: { fontSize: 13, fontWeight: "500" },
|
|
394
|
+
msgTime: { fontSize: 11, color: "#999" },
|
|
395
|
+
msgBody: { fontSize: 14, marginTop: 2 },
|
|
396
|
+
composer: {
|
|
397
|
+
flexDirection: "row",
|
|
398
|
+
gap: 8,
|
|
399
|
+
padding: 12,
|
|
400
|
+
borderTopWidth: 1,
|
|
401
|
+
borderColor: "#e5e5e5",
|
|
402
|
+
},
|
|
403
|
+
composerInput: {
|
|
404
|
+
flex: 1,
|
|
405
|
+
minHeight: 36,
|
|
406
|
+
maxHeight: 120,
|
|
407
|
+
borderWidth: 1,
|
|
408
|
+
borderColor: "#d4d4d8",
|
|
409
|
+
borderRadius: 6,
|
|
410
|
+
paddingHorizontal: 12,
|
|
411
|
+
paddingVertical: 8,
|
|
412
|
+
fontSize: 14,
|
|
413
|
+
},
|
|
414
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"expo": {
|
|
3
|
+
"name": "__APP_NAME__",
|
|
4
|
+
"slug": "__APP_NAME_KEBAB__",
|
|
5
|
+
"version": "0.0.1",
|
|
6
|
+
"orientation": "portrait",
|
|
7
|
+
"userInterfaceStyle": "automatic",
|
|
8
|
+
"ios": {
|
|
9
|
+
"supportsTablet": true,
|
|
10
|
+
"bundleIdentifier": "com.example.__APP_NAME_SNAKE__",
|
|
11
|
+
"infoPlist": {
|
|
12
|
+
"NSAppTransportSecurity": {
|
|
13
|
+
"NSAllowsLocalNetworking": true
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"android": {
|
|
18
|
+
"package": "com.example.__APP_NAME_SNAKE__",
|
|
19
|
+
"usesCleartextTraffic": true
|
|
20
|
+
},
|
|
21
|
+
"web": {
|
|
22
|
+
"bundler": "metro"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@__APP_NAME_KEBAB__/expo",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"private": true,
|
|
5
|
+
"main": "node_modules/expo/AppEntry.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"start": "expo start",
|
|
8
|
+
"android": "expo start --android",
|
|
9
|
+
"ios": "expo start --ios",
|
|
10
|
+
"web": "expo start --web"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@pylonsync/sdk": "^__PYLON_VERSION__",
|
|
14
|
+
"@pylonsync/react": "^__PYLON_VERSION__",
|
|
15
|
+
"@pylonsync/react-native": "^__PYLON_VERSION__",
|
|
16
|
+
"@pylonsync/sync": "^__PYLON_VERSION__",
|
|
17
|
+
"@react-native-async-storage/async-storage": "1.23.1",
|
|
18
|
+
"@react-native-community/netinfo": "11.3.1",
|
|
19
|
+
"expo": "~51.0.0",
|
|
20
|
+
"expo-status-bar": "~1.12.1",
|
|
21
|
+
"react": "19.0.0",
|
|
22
|
+
"react-dom": "19.0.0",
|
|
23
|
+
"react-native": "0.74.5"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@babel/core": "^7.20.0",
|
|
27
|
+
"@types/react": "^19.0.0",
|
|
28
|
+
"typescript": "^5.5.0"
|
|
29
|
+
}
|
|
30
|
+
}
|