create-feltkit 0.4.0 → 0.5.1
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.js +3 -3
- package/package.json +4 -4
- package/scaffold.d.ts +1 -1
- package/scaffold.js +8 -5
- package/template/README.md +72 -177
- package/template/_gitignore +4 -0
- package/template/agent/agent.ts +28 -0
- package/template/agent/channels/eve.ts +6 -0
- package/template/agent/instructions.md +24 -0
- package/template/agent/lib/deterministic.ts +46 -0
- package/template/agent/lib/feltkit-capabilities.json +294 -0
- package/template/agent/tools/crew_artifacts_create.ts +4 -0
- package/template/agent/tools/crew_context_read.ts +4 -0
- package/template/agent/tools/crew_context_record.ts +4 -0
- package/template/agent/tools/crew_context_search.ts +4 -0
- package/template/agent/tools/crew_decisions_propose.ts +4 -0
- package/template/agent/tools/crew_tasks_add.ts +6 -0
- package/template/agent/tools/crew_tasks_list.ts +4 -0
- package/template/agent/tools/crew_tasks_note.ts +4 -0
- package/template/agent/tools/crew_workspace_overview.ts +4 -0
- package/template/agent/tools/crew_workstreams_update.ts +6 -0
- package/template/agent/tools/web_fetch.ts +1 -0
- package/template/agent/tools/web_search.ts +3 -0
- package/template/feltkit/_generated/api.ts +8 -4
- package/template/feltkit/activity.ts +26 -0
- package/template/feltkit/app.ts +147 -54
- package/template/feltkit/boards.ts +10 -0
- package/template/feltkit/decisions.ts +99 -0
- package/template/feltkit/knowledge.ts +119 -0
- package/template/feltkit/model.ts +96 -0
- package/template/feltkit/work.ts +45 -0
- package/template/feltkit/workspace.ts +171 -0
- package/template/index.html +1 -1
- package/template/native/App.tsx +249 -0
- package/template/package.json +13 -7
- package/template/shared/rules.ts +23 -0
- package/template/src/App.tsx +177 -528
- package/template/src/screens/activity.tsx +66 -0
- package/template/src/screens/agent.tsx +188 -0
- package/template/src/screens/context.tsx +71 -0
- package/template/src/screens/decisions.tsx +89 -0
- package/template/src/screens/home.tsx +140 -0
- package/template/src/screens/team.tsx +13 -0
- package/template/src/screens/work.tsx +149 -0
- package/template/src/styles.css +201 -118
- package/template/src/ui.tsx +179 -0
- package/template/tests/crew.test.ts +111 -0
- package/template/tsconfig.json +18 -3
- package/template-managed/Dockerfile +2 -2
- package/template-managed/README.md +1 -1
- package/template-managed/package.json +3 -3
- package/template-tasks/README.md +383 -0
- package/template-tasks/_gitignore +12 -0
- package/template-tasks/feltkit/_generated/api.ts +10 -0
- package/template-tasks/feltkit/app.ts +73 -0
- package/template-tasks/index.html +17 -0
- package/template-tasks/native/App.tsx +220 -0
- package/template-tasks/native/native.json +5 -0
- package/template-tasks/package.json +30 -0
- package/template-tasks/public/apple-touch-icon.png +0 -0
- package/template-tasks/public/favicon.png +0 -0
- package/template-tasks/public/theme.js +7 -0
- package/template-tasks/shared/rules.ts +18 -0
- package/template-tasks/src/App.tsx +557 -0
- package/template-tasks/src/main.tsx +17 -0
- package/template-tasks/src/styles.css +134 -0
- package/template-tasks/src/theme.tsx +58 -0
- package/template-tasks/tsconfig.json +16 -0
- package/template-tasks/vite.config.ts +6 -0
- /package/{template → template-tasks}/feltkit/inbox.ts +0 -0
- /package/{template → template-tasks}/feltkit/projects.ts +0 -0
- /package/{template → template-tasks}/feltkit/tasks.ts +0 -0
- /package/{template → template-tasks}/public/feltkit-mark.png +0 -0
- /package/{template → template-tasks}/tests/tasks.test.ts +0 -0
|
@@ -0,0 +1,557 @@
|
|
|
1
|
+
import { useEffect, useMemo, useRef, useState, type FormEvent } from "react";
|
|
2
|
+
import { useConnectionState, useFeltKit, useMutation, useQueryState, useSession } from "@feltdb/feltkit/react";
|
|
3
|
+
import { api } from "../feltkit/_generated/api";
|
|
4
|
+
import { can, describe } from "../shared/rules";
|
|
5
|
+
import { ThemeToggle } from "./theme";
|
|
6
|
+
|
|
7
|
+
type Notice = { tone: "error" | "info"; text: string } | null;
|
|
8
|
+
|
|
9
|
+
export function App() {
|
|
10
|
+
const { session, signInAsDevUser, signIn, signUp, signOut } = useSession();
|
|
11
|
+
const live = useConnectionState();
|
|
12
|
+
const [notice, setNotice] = useState<Notice>(null);
|
|
13
|
+
const principal = session?.principal ?? null;
|
|
14
|
+
// UI hint only. The server enforces access on every call regardless of what the UI shows.
|
|
15
|
+
const canWrite = can(session?.permissions ?? [], "tasks.write");
|
|
16
|
+
const canComplete = can(session?.permissions ?? [], "tasks.complete");
|
|
17
|
+
|
|
18
|
+
// In development, sign in as the first dev user so the app works on first load.
|
|
19
|
+
const tried = useRef(false);
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
if (session && !principal && session.devUsers.length && !tried.current) {
|
|
22
|
+
tried.current = true;
|
|
23
|
+
void signInAsDevUser(session.devUsers[0]!.id);
|
|
24
|
+
}
|
|
25
|
+
}, [session, principal, signInAsDevUser]);
|
|
26
|
+
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
if (!notice) return;
|
|
29
|
+
const timer = setTimeout(() => setNotice(null), 6000);
|
|
30
|
+
return () => clearTimeout(timer);
|
|
31
|
+
}, [notice]);
|
|
32
|
+
|
|
33
|
+
const report = (error: unknown) => setNotice({ tone: "error", text: describe(error) });
|
|
34
|
+
|
|
35
|
+
// A link back into the app: a provider sign-in, a password reset, or an e-mail verification.
|
|
36
|
+
const client = useFeltKit();
|
|
37
|
+
const [resetToken, setResetToken] = useState<string | null>(null);
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
void client.handleRedirect().then((r) => {
|
|
40
|
+
if (r?.kind === "reset") setResetToken(r.token);
|
|
41
|
+
else if (r?.kind === "verified") setNotice({ tone: "info", text: `${r.email} is verified.` });
|
|
42
|
+
else if (r?.kind === "error" || r?.kind === "verify-failed") setNotice({ tone: "error", text: r.message });
|
|
43
|
+
});
|
|
44
|
+
}, [client]);
|
|
45
|
+
|
|
46
|
+
return (
|
|
47
|
+
<div className="shell">
|
|
48
|
+
<header className="topbar">
|
|
49
|
+
<div className="brand">
|
|
50
|
+
<img className="mark" src="/feltkit-mark.png" width="30" height="30" alt="" />
|
|
51
|
+
<span className="brand-name">Tasks</span>
|
|
52
|
+
{session && !session.environment.production && <span className="env">{session.environment.name}</span>}
|
|
53
|
+
</div>
|
|
54
|
+
<div className="topbar-right">
|
|
55
|
+
<span className={`live ${live ? "on" : ""}`} title={live ? "Live: changes from anyone appear here immediately" : "Connecting to the change stream…"}>
|
|
56
|
+
<span className="dot" /> {live ? "Live" : "Connecting"}
|
|
57
|
+
</span>
|
|
58
|
+
{session && session.devUsers.length > 0 && (
|
|
59
|
+
<label className="identity">
|
|
60
|
+
<span className="sr-only">Signed in as</span>
|
|
61
|
+
<select
|
|
62
|
+
value={principal?.id ?? ""}
|
|
63
|
+
onChange={(e) => (e.target.value ? signInAsDevUser(e.target.value).catch(report) : signOut())}
|
|
64
|
+
aria-label="Signed in as"
|
|
65
|
+
>
|
|
66
|
+
<option value="">Signed out</option>
|
|
67
|
+
{session.devUsers.map((u) => (
|
|
68
|
+
<option key={u.id} value={u.id}>
|
|
69
|
+
{u.name} · {u.roles.join(", ")}
|
|
70
|
+
</option>
|
|
71
|
+
))}
|
|
72
|
+
</select>
|
|
73
|
+
</label>
|
|
74
|
+
)}
|
|
75
|
+
{principal && !session?.devUsers.length && (
|
|
76
|
+
<button className="ghost signout" onClick={() => void signOut().catch(report)} title={principal.displayName ?? principal.id}>
|
|
77
|
+
Sign out
|
|
78
|
+
</button>
|
|
79
|
+
)}
|
|
80
|
+
<ThemeToggle />
|
|
81
|
+
{session?.dashboard && (
|
|
82
|
+
<a className="dashboard-link" href={session.dashboard} target="_blank" rel="noreferrer">
|
|
83
|
+
Dashboard ↗
|
|
84
|
+
</a>
|
|
85
|
+
)}
|
|
86
|
+
</div>
|
|
87
|
+
</header>
|
|
88
|
+
|
|
89
|
+
{notice && (
|
|
90
|
+
<div className={`notice ${notice.tone}`} role="status">
|
|
91
|
+
{notice.text}
|
|
92
|
+
<button className="ghost" onClick={() => setNotice(null)} aria-label="Dismiss">
|
|
93
|
+
×
|
|
94
|
+
</button>
|
|
95
|
+
</div>
|
|
96
|
+
)}
|
|
97
|
+
|
|
98
|
+
{!session ? (
|
|
99
|
+
<div className="center muted">Connecting…</div>
|
|
100
|
+
) : resetToken ? (
|
|
101
|
+
<div className="center">
|
|
102
|
+
<div className="card narrow">
|
|
103
|
+
<ResetForm token={resetToken} onDone={() => (setResetToken(null), setNotice({ tone: "info", text: "Your password is set. Other sessions were signed out." }))} />
|
|
104
|
+
</div>
|
|
105
|
+
</div>
|
|
106
|
+
) : !principal ? (
|
|
107
|
+
<SignedOut
|
|
108
|
+
devUsers={session.devUsers}
|
|
109
|
+
accounts={session.accounts ?? null}
|
|
110
|
+
onDevSignIn={(id) => signInAsDevUser(id).catch(report)}
|
|
111
|
+
onSignIn={signIn}
|
|
112
|
+
onSignUp={signUp}
|
|
113
|
+
/>
|
|
114
|
+
) : (
|
|
115
|
+
<Workspace canWrite={canWrite} canComplete={canComplete} role={principal.roles.join(", ")} onError={report} />
|
|
116
|
+
)}
|
|
117
|
+
|
|
118
|
+
{session && !session.environment.production && (
|
|
119
|
+
<footer className="footer">
|
|
120
|
+
Every project, task, and note lives in this app’s single FeltDB instance. Changes made by other people, agents (through AppPort), and services appear here live.
|
|
121
|
+
</footer>
|
|
122
|
+
)}
|
|
123
|
+
</div>
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function SignedOut(props: {
|
|
128
|
+
devUsers: Array<{ id: string; name: string; roles: string[] }>;
|
|
129
|
+
accounts: { signUp: boolean; email?: boolean; providers?: Array<{ id: string; name: string }> } | null;
|
|
130
|
+
onDevSignIn: (id: string) => void;
|
|
131
|
+
onSignIn: (input: { email: string; password: string }) => Promise<void>;
|
|
132
|
+
onSignUp: (input: { email: string; password: string; name?: string }) => Promise<void>;
|
|
133
|
+
}) {
|
|
134
|
+
return (
|
|
135
|
+
<div className="center">
|
|
136
|
+
<div className="card narrow">
|
|
137
|
+
{props.devUsers.length ? (
|
|
138
|
+
<>
|
|
139
|
+
<h1>Sign in</h1>
|
|
140
|
+
<p className="muted">Development identities from feltkit/app.ts:</p>
|
|
141
|
+
<div className="stack">
|
|
142
|
+
{props.devUsers.map((u) => (
|
|
143
|
+
<button key={u.id} className="secondary wide" onClick={() => props.onDevSignIn(u.id)}>
|
|
144
|
+
{u.name} <span className="muted">· {u.roles.join(", ")}</span>
|
|
145
|
+
</button>
|
|
146
|
+
))}
|
|
147
|
+
</div>
|
|
148
|
+
</>
|
|
149
|
+
) : props.accounts ? (
|
|
150
|
+
<AccountForm signUpOpen={props.accounts.signUp} email={Boolean(props.accounts.email)} providers={props.accounts.providers ?? []} onSignIn={props.onSignIn} onSignUp={props.onSignUp} />
|
|
151
|
+
) : (
|
|
152
|
+
<SessionForm />
|
|
153
|
+
)}
|
|
154
|
+
</div>
|
|
155
|
+
</div>
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* No dev users and no accounts: access is given by whoever operates the deployment (on AppBoundry,
|
|
161
|
+
* `appboundry admin sessions issue --user <id>`). The session they hand over is pasted here; the
|
|
162
|
+
* server decides whether it is valid, and what it may do.
|
|
163
|
+
*/
|
|
164
|
+
function SessionForm() {
|
|
165
|
+
const client = useFeltKit();
|
|
166
|
+
const [token, setToken] = useState("");
|
|
167
|
+
const [error, setError] = useState<string | null>(null);
|
|
168
|
+
const [busy, setBusy] = useState(false);
|
|
169
|
+
const submit = async (e: FormEvent) => {
|
|
170
|
+
e.preventDefault();
|
|
171
|
+
setError(null);
|
|
172
|
+
setBusy(true);
|
|
173
|
+
try {
|
|
174
|
+
client.setToken(token.trim());
|
|
175
|
+
const session = await client.session();
|
|
176
|
+
if (!session.principal) {
|
|
177
|
+
client.setToken(null);
|
|
178
|
+
setError("That session isn't valid, or it has expired or been revoked. Ask your operator for a new one.");
|
|
179
|
+
}
|
|
180
|
+
} catch (err) {
|
|
181
|
+
client.setToken(null);
|
|
182
|
+
setError(describe(err));
|
|
183
|
+
} finally {
|
|
184
|
+
setBusy(false);
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
return (
|
|
188
|
+
<form className="stack" onSubmit={submit}>
|
|
189
|
+
<h1>Sign in</h1>
|
|
190
|
+
<p className="muted">Access to this app is given by its operator. Paste the session they issued you.</p>
|
|
191
|
+
<label className="field">
|
|
192
|
+
<span>Session</span>
|
|
193
|
+
<input type="password" autoComplete="off" spellCheck={false} value={token} onChange={(e) => setToken(e.target.value)} placeholder="abs_…" required autoFocus />
|
|
194
|
+
</label>
|
|
195
|
+
{error && <p className="error-text" role="alert">{error}</p>}
|
|
196
|
+
<button className="wide" type="submit" disabled={busy || !token.trim()}>{busy ? "Signing in…" : "Sign in"}</button>
|
|
197
|
+
</form>
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/** Sign in to an existing account, or create one (auth.accounts in feltkit/app.ts). */
|
|
202
|
+
function AccountForm(props: {
|
|
203
|
+
signUpOpen: boolean;
|
|
204
|
+
/** The app sends account e-mail (auth.accounts.email): offer "forgot password". */
|
|
205
|
+
email: boolean;
|
|
206
|
+
providers: Array<{ id: string; name: string }>;
|
|
207
|
+
onSignIn: (input: { email: string; password: string }) => Promise<void>;
|
|
208
|
+
onSignUp: (input: { email: string; password: string; name?: string }) => Promise<void>;
|
|
209
|
+
}) {
|
|
210
|
+
const client = useFeltKit();
|
|
211
|
+
const [mode, setMode] = useState<"signin" | "signup" | "forgot">("signin");
|
|
212
|
+
const [name, setName] = useState("");
|
|
213
|
+
const [email, setEmail] = useState("");
|
|
214
|
+
const [password, setPassword] = useState("");
|
|
215
|
+
const [error, setError] = useState<string | null>(null);
|
|
216
|
+
const [info, setInfo] = useState<string | null>(null);
|
|
217
|
+
const [busy, setBusy] = useState(false);
|
|
218
|
+
const creating = mode === "signup";
|
|
219
|
+
const forgot = mode === "forgot";
|
|
220
|
+
const go = (next: typeof mode) => (setMode(next), setError(null), setInfo(null));
|
|
221
|
+
const submit = async (e: FormEvent) => {
|
|
222
|
+
e.preventDefault();
|
|
223
|
+
setError(null);
|
|
224
|
+
setInfo(null);
|
|
225
|
+
setBusy(true);
|
|
226
|
+
try {
|
|
227
|
+
if (forgot) setInfo((await client.requestPasswordReset(email)).message);
|
|
228
|
+
else if (creating) {
|
|
229
|
+
await props.onSignUp({ email, password, ...(name.trim() ? { name: name.trim() } : {}) });
|
|
230
|
+
if (!client.tokens.get()) setInfo("Check your e-mail: open the link we sent to verify your address, then sign in.");
|
|
231
|
+
} else await props.onSignIn({ email, password });
|
|
232
|
+
} catch (err) {
|
|
233
|
+
setError(describe(err));
|
|
234
|
+
} finally {
|
|
235
|
+
setBusy(false);
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
return (
|
|
239
|
+
<form className="stack" onSubmit={submit}>
|
|
240
|
+
<h1>{forgot ? "Reset your password" : creating ? "Create your account" : "Sign in"}</h1>
|
|
241
|
+
{!forgot &&
|
|
242
|
+
props.providers.map((p) => (
|
|
243
|
+
<button key={p.id} type="button" className="secondary wide" onClick={() => client.signInWith(p.id)}>
|
|
244
|
+
Continue with {p.name}
|
|
245
|
+
</button>
|
|
246
|
+
))}
|
|
247
|
+
{!forgot && props.providers.length > 0 && <p className="muted small-text">or with your e-mail address</p>}
|
|
248
|
+
{creating && <input value={name} onChange={(e) => setName(e.target.value)} placeholder="Name" aria-label="Name" autoComplete="name" />}
|
|
249
|
+
<input type="email" value={email} onChange={(e) => setEmail(e.target.value)} placeholder="E-mail" aria-label="E-mail" autoComplete="email" required />
|
|
250
|
+
{!forgot && (
|
|
251
|
+
<input
|
|
252
|
+
type="password"
|
|
253
|
+
value={password}
|
|
254
|
+
onChange={(e) => setPassword(e.target.value)}
|
|
255
|
+
placeholder={creating ? "Password (12+ characters)" : "Password"}
|
|
256
|
+
aria-label="Password"
|
|
257
|
+
autoComplete={creating ? "new-password" : "current-password"}
|
|
258
|
+
minLength={creating ? 12 : undefined}
|
|
259
|
+
required
|
|
260
|
+
/>
|
|
261
|
+
)}
|
|
262
|
+
{error && <p className="error-text">{error}</p>}
|
|
263
|
+
{info && <p className="muted">{info}</p>}
|
|
264
|
+
<button type="submit" disabled={busy || !email || (!forgot && !password)}>
|
|
265
|
+
{busy ? "One moment…" : forgot ? "Send reset link" : creating ? "Create account" : "Sign in"}
|
|
266
|
+
</button>
|
|
267
|
+
{mode === "signin" && props.email && (
|
|
268
|
+
<p className="muted small-text">
|
|
269
|
+
<button type="button" className="link" onClick={() => go("forgot")}>
|
|
270
|
+
Forgot your password?
|
|
271
|
+
</button>
|
|
272
|
+
</p>
|
|
273
|
+
)}
|
|
274
|
+
{(props.signUpOpen || forgot) && (
|
|
275
|
+
<p className="muted small-text">
|
|
276
|
+
{forgot ? "Remembered it? " : creating ? "Already have an account? " : "New here? "}
|
|
277
|
+
<button type="button" className="link" onClick={() => go(creating || forgot ? "signin" : "signup")}>
|
|
278
|
+
{creating || forgot ? "Sign in" : "Create an account"}
|
|
279
|
+
</button>
|
|
280
|
+
</p>
|
|
281
|
+
)}
|
|
282
|
+
</form>
|
|
283
|
+
);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/** A password reset link opened: choose a new password. */
|
|
287
|
+
function ResetForm({ token, onDone }: { token: string; onDone: () => void }) {
|
|
288
|
+
const client = useFeltKit();
|
|
289
|
+
const [password, setPassword] = useState("");
|
|
290
|
+
const [error, setError] = useState<string | null>(null);
|
|
291
|
+
const [busy, setBusy] = useState(false);
|
|
292
|
+
const submit = async (e: FormEvent) => {
|
|
293
|
+
e.preventDefault();
|
|
294
|
+
setError(null);
|
|
295
|
+
setBusy(true);
|
|
296
|
+
try {
|
|
297
|
+
await client.resetPassword(token, password);
|
|
298
|
+
onDone();
|
|
299
|
+
} catch (err) {
|
|
300
|
+
setError(describe(err));
|
|
301
|
+
} finally {
|
|
302
|
+
setBusy(false);
|
|
303
|
+
}
|
|
304
|
+
};
|
|
305
|
+
return (
|
|
306
|
+
<form className="stack" onSubmit={submit}>
|
|
307
|
+
<h1>Choose a new password</h1>
|
|
308
|
+
<input type="password" value={password} onChange={(e) => setPassword(e.target.value)} placeholder="New password (12+ characters)" aria-label="New password" autoComplete="new-password" minLength={12} required />
|
|
309
|
+
{error && <p className="error-text">{error}</p>}
|
|
310
|
+
<button type="submit" disabled={busy || !password}>
|
|
311
|
+
{busy ? "One moment…" : "Set password and sign in"}
|
|
312
|
+
</button>
|
|
313
|
+
</form>
|
|
314
|
+
);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
function Workspace({ canWrite, canComplete, role, onError }: { canWrite: boolean; canComplete: boolean; role: string; onError: (e: unknown) => void }) {
|
|
318
|
+
const projects = useQueryState(api.projects.list);
|
|
319
|
+
const [selected, setSelected] = useState<string | null>(null);
|
|
320
|
+
const createProject = useMutation(api.projects.create);
|
|
321
|
+
const [name, setName] = useState("");
|
|
322
|
+
|
|
323
|
+
const list = projects.data ?? [];
|
|
324
|
+
const current = useMemo(() => list.find((p) => p.id === selected) ?? list[0] ?? null, [list, selected]);
|
|
325
|
+
|
|
326
|
+
const submit = async (event: FormEvent) => {
|
|
327
|
+
event.preventDefault();
|
|
328
|
+
if (!name.trim()) return;
|
|
329
|
+
try {
|
|
330
|
+
const id = await createProject({ name });
|
|
331
|
+
setName("");
|
|
332
|
+
setSelected(id);
|
|
333
|
+
} catch (error) {
|
|
334
|
+
onError(error);
|
|
335
|
+
}
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
if (projects.isLoading && !projects.data) return <div className="center muted">Loading projects…</div>;
|
|
339
|
+
if (projects.error && !projects.data) return <div className="center"><div className="card narrow error-text">{describe(projects.error)}</div></div>;
|
|
340
|
+
|
|
341
|
+
return (
|
|
342
|
+
<div className="workspace">
|
|
343
|
+
<aside className="sidebar" aria-label="Projects">
|
|
344
|
+
<div className="sidebar-title">Projects</div>
|
|
345
|
+
<nav>
|
|
346
|
+
{list.map((p) => (
|
|
347
|
+
<button key={p.id} className={`project ${current?.id === p.id ? "active" : ""}`} onClick={() => setSelected(p.id)}>
|
|
348
|
+
<span className="project-name">{p.name}</span>
|
|
349
|
+
<span className="count" title={`${p.open} open, ${p.done} done`}>
|
|
350
|
+
{p.open}
|
|
351
|
+
</span>
|
|
352
|
+
</button>
|
|
353
|
+
))}
|
|
354
|
+
</nav>
|
|
355
|
+
{canWrite && (
|
|
356
|
+
<form onSubmit={submit} className="new-project">
|
|
357
|
+
<input value={name} onChange={(e) => setName(e.target.value)} placeholder="New project" aria-label="New project name" maxLength={80} />
|
|
358
|
+
</form>
|
|
359
|
+
)}
|
|
360
|
+
{!canWrite && <p className="hint">You’re signed in as a {role}. Viewers can read everything but change nothing.</p>}
|
|
361
|
+
</aside>
|
|
362
|
+
<main className="main">
|
|
363
|
+
{current ? (
|
|
364
|
+
<ProjectView key={current.id} project={current} canWrite={canWrite} canComplete={canComplete} onError={onError} />
|
|
365
|
+
) : (
|
|
366
|
+
<div className="empty">
|
|
367
|
+
<h1>Start your first project</h1>
|
|
368
|
+
<p className="muted">Projects hold tasks. Name one in the sidebar{canWrite ? "" : " (sign in as a member)"} to begin.</p>
|
|
369
|
+
{canWrite && (
|
|
370
|
+
<form onSubmit={submit} className="inline-form">
|
|
371
|
+
<input autoFocus value={name} onChange={(e) => setName(e.target.value)} placeholder="e.g. Launch plan" aria-label="Project name" />
|
|
372
|
+
<button className="primary" type="submit" disabled={!name.trim()}>
|
|
373
|
+
Create project
|
|
374
|
+
</button>
|
|
375
|
+
</form>
|
|
376
|
+
)}
|
|
377
|
+
</div>
|
|
378
|
+
)}
|
|
379
|
+
</main>
|
|
380
|
+
</div>
|
|
381
|
+
);
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
type Project = { id: string; name: string; open: number; done: number };
|
|
385
|
+
|
|
386
|
+
function ProjectView({ project, canWrite, canComplete, onError }: { project: Project; canWrite: boolean; canComplete: boolean; onError: (e: unknown) => void }) {
|
|
387
|
+
const tasks = useQueryState(api.tasks.list, { projectId: project.id });
|
|
388
|
+
const create = useMutation(api.tasks.create);
|
|
389
|
+
const [title, setTitle] = useState("");
|
|
390
|
+
const [busy, setBusy] = useState(false);
|
|
391
|
+
const [openTask, setOpenTask] = useState<string | null>(null);
|
|
392
|
+
|
|
393
|
+
const add = async (event: FormEvent) => {
|
|
394
|
+
event.preventDefault();
|
|
395
|
+
if (!title.trim()) return;
|
|
396
|
+
setBusy(true);
|
|
397
|
+
try {
|
|
398
|
+
await create({ projectId: project.id, title });
|
|
399
|
+
setTitle("");
|
|
400
|
+
} catch (error) {
|
|
401
|
+
onError(error);
|
|
402
|
+
} finally {
|
|
403
|
+
setBusy(false);
|
|
404
|
+
}
|
|
405
|
+
};
|
|
406
|
+
|
|
407
|
+
const items = tasks.data ?? [];
|
|
408
|
+
const open = items.filter((t) => !t.done).length;
|
|
409
|
+
return (
|
|
410
|
+
<section aria-label={project.name}>
|
|
411
|
+
<div className="project-header">
|
|
412
|
+
<h1>{project.name}</h1>
|
|
413
|
+
<span className="muted">
|
|
414
|
+
{open} open · {items.length - open} done
|
|
415
|
+
</span>
|
|
416
|
+
</div>
|
|
417
|
+
{canWrite && (
|
|
418
|
+
<form onSubmit={add} className="add-task">
|
|
419
|
+
<input value={title} onChange={(e) => setTitle(e.target.value)} placeholder="Add a task and press Enter" aria-label="New task" maxLength={200} disabled={busy} />
|
|
420
|
+
</form>
|
|
421
|
+
)}
|
|
422
|
+
{tasks.isLoading && !tasks.data ? (
|
|
423
|
+
<p className="muted pad">Loading tasks…</p>
|
|
424
|
+
) : items.length === 0 ? (
|
|
425
|
+
<div className="empty small">
|
|
426
|
+
<p>No tasks yet.</p>
|
|
427
|
+
<p className="muted">{canWrite ? "Add one above." : "A member can add tasks."}</p>
|
|
428
|
+
</div>
|
|
429
|
+
) : (
|
|
430
|
+
<ul className="tasks">
|
|
431
|
+
{items.map((task) => (
|
|
432
|
+
<TaskRow key={task.id} task={task} canWrite={canWrite} canComplete={canComplete} open={openTask === task.id} onToggleOpen={() => setOpenTask(openTask === task.id ? null : task.id)} onError={onError} />
|
|
433
|
+
))}
|
|
434
|
+
</ul>
|
|
435
|
+
)}
|
|
436
|
+
</section>
|
|
437
|
+
);
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
type Task = { id: string; title: string; details?: string; done: boolean; createdBy: string; completedBy?: string };
|
|
441
|
+
|
|
442
|
+
function TaskRow({ task, canWrite, canComplete, open, onToggleOpen, onError }: { task: Task; canWrite: boolean; canComplete: boolean; open: boolean; onToggleOpen: () => void; onError: (e: unknown) => void }) {
|
|
443
|
+
const setDone = useMutation(api.tasks.setDone);
|
|
444
|
+
const update = useMutation(api.tasks.update);
|
|
445
|
+
const remove = useMutation(api.tasks.remove);
|
|
446
|
+
const [editing, setEditing] = useState(false);
|
|
447
|
+
const [draft, setDraft] = useState(task.title);
|
|
448
|
+
const [details, setDetails] = useState(task.details ?? "");
|
|
449
|
+
|
|
450
|
+
useEffect(() => setDraft(task.title), [task.title]);
|
|
451
|
+
useEffect(() => setDetails(task.details ?? ""), [task.details]);
|
|
452
|
+
|
|
453
|
+
const save = async () => {
|
|
454
|
+
setEditing(false);
|
|
455
|
+
if (draft.trim() && draft.trim() !== task.title) await update({ id: task.id, title: draft }).catch(onError);
|
|
456
|
+
else setDraft(task.title);
|
|
457
|
+
};
|
|
458
|
+
|
|
459
|
+
return (
|
|
460
|
+
<li className={`task ${task.done ? "done" : ""} ${open ? "open" : ""}`}>
|
|
461
|
+
<div className="task-row">
|
|
462
|
+
<input type="checkbox" checked={task.done} disabled={!canComplete} onChange={(e) => setDone({ id: task.id, done: e.target.checked }).catch(onError)} aria-label={task.done ? "Reopen task" : "Complete task"} />
|
|
463
|
+
{editing ? (
|
|
464
|
+
<input
|
|
465
|
+
className="title-input"
|
|
466
|
+
value={draft}
|
|
467
|
+
autoFocus
|
|
468
|
+
onChange={(e) => setDraft(e.target.value)}
|
|
469
|
+
onBlur={save}
|
|
470
|
+
onKeyDown={(e) => {
|
|
471
|
+
if (e.key === "Enter") void save();
|
|
472
|
+
if (e.key === "Escape") {
|
|
473
|
+
setDraft(task.title);
|
|
474
|
+
setEditing(false);
|
|
475
|
+
}
|
|
476
|
+
}}
|
|
477
|
+
aria-label="Task title"
|
|
478
|
+
/>
|
|
479
|
+
) : (
|
|
480
|
+
<button className="title" onClick={onToggleOpen} onDoubleClick={() => canWrite && setEditing(true)} aria-expanded={open}>
|
|
481
|
+
{task.title}
|
|
482
|
+
</button>
|
|
483
|
+
)}
|
|
484
|
+
<span className="by muted">{task.done && task.completedBy ? `done by ${task.completedBy}` : task.createdBy}</span>
|
|
485
|
+
{canWrite && !editing && (
|
|
486
|
+
<button className="ghost icon" onClick={() => setEditing(true)} aria-label="Rename task" title="Rename">
|
|
487
|
+
✎
|
|
488
|
+
</button>
|
|
489
|
+
)}
|
|
490
|
+
</div>
|
|
491
|
+
{open && (
|
|
492
|
+
<div className="task-detail">
|
|
493
|
+
<label className="field">
|
|
494
|
+
<span>Details</span>
|
|
495
|
+
<textarea
|
|
496
|
+
value={details}
|
|
497
|
+
onChange={(e) => setDetails(e.target.value)}
|
|
498
|
+
onBlur={() => details !== (task.details ?? "") && update({ id: task.id, details }).catch(onError)}
|
|
499
|
+
placeholder={canWrite ? "Add details…" : "No details"}
|
|
500
|
+
readOnly={!canWrite}
|
|
501
|
+
rows={3}
|
|
502
|
+
maxLength={4000}
|
|
503
|
+
/>
|
|
504
|
+
</label>
|
|
505
|
+
<Notes taskId={task.id} canWrite={canWrite} onError={onError} />
|
|
506
|
+
{canWrite && (
|
|
507
|
+
<div className="row-end">
|
|
508
|
+
<button className="danger-link" onClick={() => remove({ id: task.id }).catch(onError)}>
|
|
509
|
+
Delete task
|
|
510
|
+
</button>
|
|
511
|
+
</div>
|
|
512
|
+
)}
|
|
513
|
+
</div>
|
|
514
|
+
)}
|
|
515
|
+
</li>
|
|
516
|
+
);
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
function Notes({ taskId, canWrite, onError }: { taskId: string; canWrite: boolean; onError: (e: unknown) => void }) {
|
|
520
|
+
const notes = useQueryState(api.tasks.notes, { taskId });
|
|
521
|
+
const addNote = useMutation(api.tasks.addNote);
|
|
522
|
+
const [text, setText] = useState("");
|
|
523
|
+
const submit = async (event: FormEvent) => {
|
|
524
|
+
event.preventDefault();
|
|
525
|
+
if (!text.trim()) return;
|
|
526
|
+
try {
|
|
527
|
+
await addNote({ taskId, text });
|
|
528
|
+
setText("");
|
|
529
|
+
} catch (error) {
|
|
530
|
+
onError(error);
|
|
531
|
+
}
|
|
532
|
+
};
|
|
533
|
+
return (
|
|
534
|
+
<div className="notes">
|
|
535
|
+
<div className="notes-title">
|
|
536
|
+
Notes <span className="muted">· stored by AppPort Services Files</span>
|
|
537
|
+
</div>
|
|
538
|
+
{(notes.data ?? []).map((n) => (
|
|
539
|
+
<div className="note" key={n.id}>
|
|
540
|
+
<div className="note-meta muted">
|
|
541
|
+
{n.author} · {new Date(n.createdAt).toLocaleString()}
|
|
542
|
+
</div>
|
|
543
|
+
<div className="note-text">{n.text}</div>
|
|
544
|
+
</div>
|
|
545
|
+
))}
|
|
546
|
+
{notes.data?.length === 0 && <p className="muted small-text">No notes yet.</p>}
|
|
547
|
+
{canWrite && (
|
|
548
|
+
<form onSubmit={submit} className="note-form">
|
|
549
|
+
<input value={text} onChange={(e) => setText(e.target.value)} placeholder="Leave a note" aria-label="New note" maxLength={8000} />
|
|
550
|
+
<button className="secondary" type="submit" disabled={!text.trim()}>
|
|
551
|
+
Add
|
|
552
|
+
</button>
|
|
553
|
+
</form>
|
|
554
|
+
)}
|
|
555
|
+
</div>
|
|
556
|
+
);
|
|
557
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { StrictMode } from "react";
|
|
2
|
+
import { createRoot } from "react-dom/client";
|
|
3
|
+
import { createClient } from "@feltdb/feltkit/client";
|
|
4
|
+
import { FeltKitProvider } from "@feltdb/feltkit/react";
|
|
5
|
+
import { App } from "./App";
|
|
6
|
+
import "./styles.css";
|
|
7
|
+
|
|
8
|
+
// Same origin as the page: `feltkit dev` serves the app, its functions, and AppPort together.
|
|
9
|
+
const client = createClient();
|
|
10
|
+
|
|
11
|
+
createRoot(document.getElementById("root")!).render(
|
|
12
|
+
<StrictMode>
|
|
13
|
+
<FeltKitProvider client={client}>
|
|
14
|
+
<App />
|
|
15
|
+
</FeltKitProvider>
|
|
16
|
+
</StrictMode>,
|
|
17
|
+
);
|