Skip to content

Commit 120fdc3

Browse files
committed
Upgrade to reflect@0.39.202402011004
1 parent 8761b21 commit 120fdc3

14 files changed

+89
-75
lines changed

.github/workflows/deploy-reflect.yml

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Deploy Reflect to Production
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches: [main]
9+
10+
env:
11+
NODE_VERSION: "18.x"
12+
13+
jobs:
14+
deploy:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: Set up Node.js
20+
uses: actions/setup-node@v3
21+
with:
22+
node-version: ${{ env.NODE_VERSION }}
23+
cache: "npm"
24+
25+
- name: npm install
26+
run: |
27+
npm install
28+
29+
- name: publish
30+
env:
31+
REFLECT_AUTH_KEY: ${{ secrets.REFLECT_AUTH_KEY }}
32+
run: |
33+
npx reflect publish --server-path="./reflect/orchestrator/server.ts" --reflect-channel=canary --app=loop-orchestrator-${GITHUB_HEAD_REF//[^a-zA-Z0-9]/-} --auth-key-from-env=REFLECT_AUTH_KEY
34+
npx reflect publish --server-path="./reflect/share/server.ts" --reflect-channel=canary --app=loop-share-${GITHUB_HEAD_REF//[^a-zA-Z0-9]/-} --auth-key-from-env=REFLECT_AUTH_KEY
35+
npx reflect publish --server-path="./reflect/play/server.ts" --reflect-channel=canary --app=loop-play-${GITHUB_HEAD_REF//[^a-zA-Z0-9]/-} --auth-key-from-env=REFLECT_AUTH_KEY

README.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,5 @@ We will improve Reflect's APIs over time to not require separate apps for this t
2727

2828
# Publish
2929

30-
1. Remove the `apps` key from each of the `reflect.config.json` files
31-
2. Publish each app to reflect with `npx reflect publish`
32-
3. Publish the frontend to some host, i.e., Vercel and set `NEXT_PUBLIC_ORCHESTRATOR_SERVER`, `NEXT_PUBLIC_PLAY_SERVER`, and `NEXT_PUBLIC_SHARE_SERVER` accordingly.
30+
1. Publish each app to reflect with `npx reflect publish`
31+
2. Publish the frontend to some host, i.e., Vercel and set `NEXT_PUBLIC_ORCHESTRATOR_SERVER`, `NEXT_PUBLIC_PLAY_SERVER`, and `NEXT_PUBLIC_SHARE_SERVER` accordingly.

frontend/App.tsx

+10-10
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ import ShareModal from "./ShareModal";
1919
import { useElementSize, useWindowSize } from "./sizeHooks";
2020
import { event } from "nextjs-google-analytics";
2121
import styles from "./App.module.css";
22+
import { getReflectServer } from "./host";
2223

23-
const orchestratorServer =
24-
process.env.NEXT_PUBLIC_ORCHESTRATOR_SERVER ?? "http://127.0.0.1:8080/";
25-
const playServer =
26-
process.env.NEXT_PUBLIC_PLAY_SERVER ?? "http://127.0.0.1:8080/";
27-
const shareServer =
28-
process.env.NEXT_PUBLIC_SHARE_SERVER ?? "http://127.0.0.1:8080/";
24+
const orchestratorServer = getReflectServer(
25+
process.env.NEXT_PUBLIC_ORCHESTRATOR_SERVER
26+
);
27+
const playServer = getReflectServer(process.env.NEXT_PUBLIC_PLAY_SERVER);
28+
const shareServer = getReflectServer(process.env.NEXT_PUBLIC_SHARE_SERVER);
2929

3030
type RoomAssignment = { roomID: string; color: string };
3131

@@ -206,11 +206,11 @@ const animateMessage = (messageDiv: HTMLDivElement | null) => {
206206
const animateButton = (elementId: string) => {
207207
const element = document.getElementById(elementId);
208208
if (element) {
209-
element.classList.add('animated-button');
209+
element.classList.add("animated-button");
210210

211-
setTimeout(() => {
212-
element.classList.remove('animated-button');
213-
}, 600);
211+
setTimeout(() => {
212+
element.classList.remove("animated-button");
213+
}, 600);
214214
}
215215
};
216216

frontend/CursorField.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export default function CursorField({
6060
<Cursor
6161
selfClientID={r.clientID}
6262
client={client}
63-
key={client.id}
63+
key={client.clientID}
6464
appRect={appRect}
6565
docRect={docRect}
6666
/>
@@ -88,7 +88,7 @@ function Cursor({
8888
return (
8989
<div
9090
className={classNames(styles.cursor, {
91-
[styles.cursorSelf]: client.id === selfClientID,
91+
[styles.cursorSelf]: client.clientID === selfClientID,
9292
[styles.cursorTouch]: client.isTouch,
9393
})}
9494
style={{

frontend/PresenceBar.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export default function PresenceAvatars({
3939
key={"overflow"}
4040
/>
4141
) : (
42-
<PresenceAvatar client={client} key={client.id} />
42+
<PresenceAvatar client={client} key={client.clientID} />
4343
)
4444
)}
4545
</div>

frontend/host.ts

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export function getReflectServer(template: string | undefined) {
2+
if (!template) {
3+
throw new Error("Environment variable is required");
4+
}
5+
return applyTemplate(template);
6+
}
7+
8+
function applyTemplate(template: string) {
9+
const f = new Function(
10+
"NEXT_PUBLIC_VERCEL_GIT_COMMIT_REF",
11+
`return \`${template}\``
12+
);
13+
const branchName = process.env.NEXT_PUBLIC_VERCEL_GIT_COMMIT_REF ?? "";
14+
return f(branchName.replace(/\//g, "-"));
15+
}

package-lock.json

+9-19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
},
1414
"dependencies": {
1515
"@badrap/valita": "^0.3.0",
16-
"@rocicorp/rails": "^0.7.1",
17-
"@rocicorp/reflect": "^0.38.202312080119",
16+
"@rocicorp/rails": "^0.10.0",
17+
"@rocicorp/reflect": "^0.39.202402011004",
1818
"@vercel/og": "^0.5.20",
1919
"classnames": "^2.3.2",
2020
"nanoid": "^5.0.3",

reflect/model/cell.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ async function setCellEnabled(
5959
await cellGenerated.delete(tx, id);
6060
}
6161
}
62-
const client = await getClient(tx, tx.clientID);
62+
const client = await getClient(tx);
6363
await cellGenerated.put(tx, {
6464
id,
6565
color: client?.color ?? colorIDFromID(tx.clientID),

reflect/model/client.ts

+4-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as v from "@badrap/valita";
2-
import { Update, generate } from "@rocicorp/rails";
2+
import { Update, generatePresence } from "@rocicorp/rails";
33
import { WriteTransaction } from "@rocicorp/reflect";
44

55
const cursorSchema = v.object({ x: v.number(), y: v.number() });
@@ -8,7 +8,7 @@ const locationSchema = v.object({
88
country: v.string(),
99
});
1010
const clientModelSchema = v.object({
11-
id: v.string(),
11+
clientID: v.string(),
1212
color: v.string(),
1313
cursor: cursorSchema.optional(),
1414
location: locationSchema.optional(),
@@ -19,7 +19,7 @@ export type Cursor = v.Infer<typeof cursorSchema>;
1919
export type Location = v.Infer<typeof locationSchema>;
2020
export type Client = v.Infer<typeof clientModelSchema>;
2121
export type ClientUpdate = Update<Client>;
22-
const clientGenerated = generate(
22+
const clientGenerated = generatePresence(
2323
"client",
2424
clientModelSchema.parse.bind(clientModelSchema)
2525
);
@@ -30,21 +30,17 @@ const initClient = async (
3030
tx: WriteTransaction,
3131
{ color }: { color: string }
3232
) => {
33-
const id = tx.clientID;
3433
const client = {
35-
id,
3634
color,
3735
};
38-
await clientGenerated.put(tx, client);
36+
await clientGenerated.set(tx, client);
3937
};
4038

4139
const updateLocation = async (tx: WriteTransaction, location: Location) => {
4240
if (!allowLocation(location)) {
4341
return;
4442
}
45-
const id = tx.clientID;
4643
const client = {
47-
id,
4844
location,
4945
};
5046
await clientGenerated.update(tx, client);
@@ -60,14 +56,12 @@ function allowLocation(location: Location): boolean {
6056

6157
const updateCursor = async (tx: WriteTransaction, cursor: Cursor) => {
6258
await clientGenerated.update(tx, {
63-
id: tx.clientID,
6459
cursor,
6560
});
6661
};
6762

6863
const markAsTouchClient = async (tx: WriteTransaction) => {
6964
await clientGenerated.update(tx, {
70-
id: tx.clientID,
7165
isTouch: true,
7266
});
7367
};
+2-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
11
{
2-
"server": "server.ts",
3-
"apps": {
4-
"default": {
5-
"appID": "lqhif59k"
6-
}
7-
}
8-
}
2+
"server": "server.ts"
3+
}

reflect/play/reflect.config.json

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
11
{
2-
"server": "server.ts",
3-
"apps": {
4-
"default": {
5-
"appID": "loxvdsq5"
6-
}
7-
}
8-
}
2+
"server": "server.ts"
3+
}

reflect/share/reflect.config.json

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
11
{
2-
"server": "server.ts",
3-
"apps": {
4-
"default": {
5-
"appID": "loxv5ldt"
6-
}
7-
}
8-
}
2+
"server": "server.ts"
3+
}

reflect/subscriptions.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@ import { PLAY_M } from "./play/mutators";
55
import { SHARE_M } from "./share/mutators";
66

77
export function useSelfColor(r: Reflect<PLAY_M | SHARE_M> | undefined) {
8-
return useSubscribe(
9-
r,
10-
async (tx) => (await getClient(tx, tx.clientID))?.color,
11-
null
12-
);
8+
return useSubscribe(r, async (tx) => (await getClient(tx))?.color, null);
139
}
1410

1511
export function usePresentClients(
@@ -21,7 +17,7 @@ export function usePresentClients(
2117
async (tx) => {
2218
const presentClients = [];
2319
for (const clientID of presentClientIDs) {
24-
const client = await getClient(tx, clientID);
20+
const client = await getClient(tx, { clientID });
2521
if (client) {
2622
presentClients.push(client);
2723
}

0 commit comments

Comments
 (0)