@kidecms/core 0.19.0 → 0.20.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/admin/components/AssetsGrid.tsx +57 -58
- package/admin/components/CollaborationReviewBar.tsx +245 -61
- package/admin/layouts/AdminLayout.astro +41 -2
- package/admin/lib/collaboration.ts +91 -0
- package/admin/views/EditView.astro +1 -1
- package/admin/views/NeedsYouView.astro +100 -0
- package/admin/views/edit/EditScripts.astro +90 -15
- package/core/admin.ts +2 -0
- package/core/api.ts +31 -2
- package/core/collaboration.ts +73 -0
- package/core/generator.ts +19 -2
- package/core/index.ts +8 -2
- package/middleware/auth.ts +7 -1
- package/package.json +1 -1
- package/routes/admin/[...path].astro +19 -6
- package/routes/admin/setup.astro +3 -2
- package/routes/api/[collection]/[...path].ts +12 -5
- package/routes/api/auth/setup.ts +7 -5
- package/routes/api/collaboration/index.ts +15 -0
- package/admin/components/Untitled +0 -1
|
@@ -803,7 +803,7 @@ export default function AssetsGrid({
|
|
|
803
803
|
|
|
804
804
|
{/* ── Main: search, grid, pagination ── */}
|
|
805
805
|
<div className="min-w-0 space-y-4 lg:border-l lg:pl-8">
|
|
806
|
-
<div className="top-0 z-20 flex items-center justify-between gap-3
|
|
806
|
+
<div className="bg-background sticky top-0 z-20 -mx-0.5 flex items-center justify-between gap-3 px-0.5 py-3">
|
|
807
807
|
<div className="relative w-full sm:max-w-xs">
|
|
808
808
|
<Search className="text-muted-foreground pointer-events-none absolute top-1/2 left-3 size-4 -translate-y-1/2" />
|
|
809
809
|
<Input
|
|
@@ -813,39 +813,62 @@ export default function AssetsGrid({
|
|
|
813
813
|
className="pl-9 text-sm"
|
|
814
814
|
/>
|
|
815
815
|
</div>
|
|
816
|
-
|
|
817
|
-
className=
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
816
|
+
{selectedIds.size > 0 ? (
|
|
817
|
+
<div className="flex shrink-0 items-center gap-2">
|
|
818
|
+
<span className="text-sm font-medium">
|
|
819
|
+
{selectedIds.size}
|
|
820
|
+
<span className="hidden sm:inline"> selected</span>
|
|
821
|
+
</span>
|
|
822
|
+
<Button
|
|
823
|
+
variant="destructive"
|
|
824
|
+
onClick={() => {
|
|
825
|
+
resetDialogState();
|
|
826
|
+
setBulkDeleteOpen(true);
|
|
827
|
+
void loadBulkUsage(Array.from(selectedIds));
|
|
828
|
+
}}
|
|
829
|
+
>
|
|
830
|
+
<Trash2 className="size-4" />
|
|
831
|
+
Delete
|
|
832
|
+
</Button>
|
|
833
|
+
<Button variant="outline" onClick={clearSelection}>
|
|
834
|
+
Cancel
|
|
835
|
+
</Button>
|
|
836
|
+
</div>
|
|
837
|
+
) : (
|
|
838
|
+
<label
|
|
839
|
+
className={cn(
|
|
840
|
+
buttonVariants(),
|
|
841
|
+
"shrink-0",
|
|
842
|
+
uploading ? "pointer-events-none opacity-70" : "cursor-pointer",
|
|
843
|
+
)}
|
|
844
|
+
>
|
|
845
|
+
{uploading ? (
|
|
846
|
+
<>
|
|
847
|
+
<Loader2 className="size-4 animate-spin" />
|
|
848
|
+
{uploadProgress < 100
|
|
849
|
+
? `Uploading ${uploadCount > 1 ? `${uploadCount} files` : "file"}… ${uploadProgress}%`
|
|
850
|
+
: "Processing…"}
|
|
851
|
+
</>
|
|
852
|
+
) : (
|
|
853
|
+
<>
|
|
854
|
+
<Upload className="size-4" />
|
|
855
|
+
Upload
|
|
856
|
+
</>
|
|
857
|
+
)}
|
|
858
|
+
<input
|
|
859
|
+
type="file"
|
|
860
|
+
name="file"
|
|
861
|
+
accept="image/*,video/*,audio/*,.pdf,.doc,.docx"
|
|
862
|
+
multiple
|
|
863
|
+
disabled={uploading}
|
|
864
|
+
className="hidden"
|
|
865
|
+
onChange={(e) => {
|
|
866
|
+
if (e.target.files?.length) handleFilesSelected(e.target.files);
|
|
867
|
+
e.target.value = "";
|
|
868
|
+
}}
|
|
869
|
+
/>
|
|
870
|
+
</label>
|
|
871
|
+
)}
|
|
849
872
|
</div>
|
|
850
873
|
{uploading && (
|
|
851
874
|
<div
|
|
@@ -877,30 +900,6 @@ export default function AssetsGrid({
|
|
|
877
900
|
</div>
|
|
878
901
|
)}
|
|
879
902
|
|
|
880
|
-
{/* Selection toolbar */}
|
|
881
|
-
{selectedIds.size > 0 && (
|
|
882
|
-
<div className="bg-background sticky top-4 z-20 flex items-center justify-between gap-3 rounded-lg border px-3 py-2 shadow-sm">
|
|
883
|
-
<span className="text-sm font-medium">{selectedIds.size} selected</span>
|
|
884
|
-
<div className="flex items-center gap-2">
|
|
885
|
-
<Button
|
|
886
|
-
variant="destructive"
|
|
887
|
-
size="sm"
|
|
888
|
-
onClick={() => {
|
|
889
|
-
resetDialogState();
|
|
890
|
-
setBulkDeleteOpen(true);
|
|
891
|
-
void loadBulkUsage(Array.from(selectedIds));
|
|
892
|
-
}}
|
|
893
|
-
>
|
|
894
|
-
<Trash2 className="size-3.5" />
|
|
895
|
-
Delete
|
|
896
|
-
</Button>
|
|
897
|
-
<Button variant="outline" size="sm" onClick={clearSelection}>
|
|
898
|
-
Cancel
|
|
899
|
-
</Button>
|
|
900
|
-
</div>
|
|
901
|
-
</div>
|
|
902
|
-
)}
|
|
903
|
-
|
|
904
903
|
{/* Grid or empty state. Keep the current grid visible while a new
|
|
905
904
|
filter/page loads (dimmed) to avoid an empty-then-fill flash. */}
|
|
906
905
|
{items.length > 0 ? (
|
|
@@ -1,11 +1,26 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
3
|
import { useRef, useState } from "react";
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
Check,
|
|
6
|
+
ChevronDown,
|
|
7
|
+
Clock,
|
|
8
|
+
EllipsisVertical,
|
|
9
|
+
GitCommitVertical,
|
|
10
|
+
MessageSquare,
|
|
11
|
+
MessageSquarePlus,
|
|
12
|
+
UserRound,
|
|
13
|
+
} from "lucide-react";
|
|
5
14
|
|
|
6
15
|
import { cn } from "../lib/utils";
|
|
7
16
|
import { buttonVariants } from "./ui/button";
|
|
8
|
-
import {
|
|
17
|
+
import {
|
|
18
|
+
DropdownMenu,
|
|
19
|
+
DropdownMenuContent,
|
|
20
|
+
DropdownMenuItem,
|
|
21
|
+
DropdownMenuSeparator,
|
|
22
|
+
DropdownMenuTrigger,
|
|
23
|
+
} from "./ui/dropdown-menu";
|
|
9
24
|
import { Sheet, SheetContent, SheetTitle } from "./ui/sheet";
|
|
10
25
|
import { REVIEW_STATE_META, type CollabActivity, type CollabComment, type CollabUser } from "../lib/collaboration";
|
|
11
26
|
import type { ReviewState } from "../../core";
|
|
@@ -23,6 +38,19 @@ type Props = {
|
|
|
23
38
|
canApprove: boolean;
|
|
24
39
|
};
|
|
25
40
|
|
|
41
|
+
function EmptyAvatar({ size = "size-6" }: { size?: string }) {
|
|
42
|
+
return (
|
|
43
|
+
<span
|
|
44
|
+
className={cn(
|
|
45
|
+
size,
|
|
46
|
+
"border-muted-foreground/80 text-muted-foreground inline-flex shrink-0 items-center justify-center rounded-full border border-dashed",
|
|
47
|
+
)}
|
|
48
|
+
>
|
|
49
|
+
<UserRound className="size-3" />
|
|
50
|
+
</span>
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
26
54
|
function Avatar({ initials, color, size = "size-6" }: { initials: string; color: string; size?: string }) {
|
|
27
55
|
return (
|
|
28
56
|
<span
|
|
@@ -48,6 +76,13 @@ export default function CollaborationReviewBar(props: Props) {
|
|
|
48
76
|
const [draft, setDraft] = useState("");
|
|
49
77
|
const [busy, setBusy] = useState(false);
|
|
50
78
|
|
|
79
|
+
// Self-assign stays a one-click action at the top — with a long roster, hunting
|
|
80
|
+
// for your own name is the slow path. It is only offered when it would change
|
|
81
|
+
// something, and you are then dropped from the roster below so the same person
|
|
82
|
+
// never appears twice.
|
|
83
|
+
const showAssignToMe = !!currentUser && editor?.id !== currentUser.id;
|
|
84
|
+
const rosterUsers = showAssignToMe ? assignableUsers.filter((u) => u.id !== currentUser!.id) : assignableUsers;
|
|
85
|
+
|
|
51
86
|
const post = async (payload: Record<string, unknown>) => {
|
|
52
87
|
setBusy(true);
|
|
53
88
|
try {
|
|
@@ -89,7 +124,15 @@ export default function CollaborationReviewBar(props: Props) {
|
|
|
89
124
|
}
|
|
90
125
|
};
|
|
91
126
|
|
|
92
|
-
const commentInputRef = useRef<
|
|
127
|
+
const commentInputRef = useRef<HTMLTextAreaElement>(null);
|
|
128
|
+
|
|
129
|
+
// Grow with the text instead of scrolling a one-line box: a comment you cannot
|
|
130
|
+
// read back while writing it is the main thing wrong with a single-line field.
|
|
131
|
+
const autoGrow = (el: HTMLTextAreaElement | null) => {
|
|
132
|
+
if (!el) return;
|
|
133
|
+
el.style.height = "auto";
|
|
134
|
+
el.style.height = `${Math.min(el.scrollHeight, 160)}px`;
|
|
135
|
+
};
|
|
93
136
|
const openComments = (focus = false) => {
|
|
94
137
|
setTab("comments");
|
|
95
138
|
setOpen(true);
|
|
@@ -110,9 +153,11 @@ export default function CollaborationReviewBar(props: Props) {
|
|
|
110
153
|
field: null,
|
|
111
154
|
body,
|
|
112
155
|
resolved: false,
|
|
156
|
+
edited: false,
|
|
113
157
|
},
|
|
114
158
|
]);
|
|
115
159
|
setDraft("");
|
|
160
|
+
if (commentInputRef.current) commentInputRef.current.style.height = "auto";
|
|
116
161
|
} catch (err) {
|
|
117
162
|
window.alert(err instanceof Error ? err.message : "Could not add comment.");
|
|
118
163
|
}
|
|
@@ -129,6 +174,51 @@ export default function CollaborationReviewBar(props: Props) {
|
|
|
129
174
|
}
|
|
130
175
|
};
|
|
131
176
|
|
|
177
|
+
// Mirrors the server rule in authorizeComment(): the author, or an approver
|
|
178
|
+
// tidying a thread. The API re-checks — this only decides what to render.
|
|
179
|
+
const [editingId, setEditingId] = useState<string | null>(null);
|
|
180
|
+
const [editDraft, setEditDraft] = useState("");
|
|
181
|
+
|
|
182
|
+
// Author-only, matching the server. Approvers can remove a comment but not
|
|
183
|
+
// rewrite one that carries someone else's name.
|
|
184
|
+
const canEditComment = (comment: CollabComment) => !!currentUser && comment.author.id === currentUser.id;
|
|
185
|
+
|
|
186
|
+
const startEdit = (comment: CollabComment) => {
|
|
187
|
+
setEditingId(comment.id);
|
|
188
|
+
setEditDraft(comment.body);
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
const saveEdit = async (comment: CollabComment) => {
|
|
192
|
+
const body = editDraft.trim();
|
|
193
|
+
if (!body || body === comment.body) {
|
|
194
|
+
setEditingId(null);
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
const snapshot = comments;
|
|
198
|
+
setComments((prev) => prev.map((c) => (c.id === comment.id ? { ...c, body, edited: true } : c)));
|
|
199
|
+
setEditingId(null);
|
|
200
|
+
try {
|
|
201
|
+
await post({ action: "updateComment", commentId: comment.id, body });
|
|
202
|
+
} catch (err) {
|
|
203
|
+
setComments(snapshot);
|
|
204
|
+
window.alert(err instanceof Error ? err.message : "Could not save comment.");
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
const canDeleteComment = (comment: CollabComment) =>
|
|
209
|
+
!!currentUser && (comment.author.id === currentUser.id || canApprove);
|
|
210
|
+
|
|
211
|
+
const deleteComment = async (comment: CollabComment) => {
|
|
212
|
+
const snapshot = comments;
|
|
213
|
+
setComments((prev) => prev.filter((c) => c.id !== comment.id));
|
|
214
|
+
try {
|
|
215
|
+
await post({ action: "deleteComment", commentId: comment.id });
|
|
216
|
+
} catch (err) {
|
|
217
|
+
setComments(snapshot);
|
|
218
|
+
window.alert(err instanceof Error ? err.message : "Could not delete comment.");
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
|
|
132
222
|
const meta = REVIEW_STATE_META[reviewState];
|
|
133
223
|
const canEdit = reviewState === "in_progress" || reviewState === "changes_requested";
|
|
134
224
|
|
|
@@ -236,27 +326,31 @@ export default function CollaborationReviewBar(props: Props) {
|
|
|
236
326
|
className="hover:bg-foreground/5 flex items-center gap-1.5 rounded-md px-1.5 py-1 outline-none disabled:opacity-60"
|
|
237
327
|
>
|
|
238
328
|
<span className="text-muted-foreground text-xs">Assignee</span>
|
|
239
|
-
{editor
|
|
240
|
-
<span className={cn("text-sm", editor
|
|
241
|
-
{editor?.name
|
|
329
|
+
{editor ? <Avatar initials={editor.initials} color={editor.color} /> : <EmptyAvatar />}
|
|
330
|
+
<span className={cn("text-sm", editor && "font-medium")}>
|
|
331
|
+
{editor ? (editor.id === currentUser?.id ? "You" : editor.name) : "No assignee"}
|
|
242
332
|
</span>
|
|
243
333
|
<ChevronDown className="text-muted-foreground size-3.5" />
|
|
244
334
|
</DropdownMenuTrigger>
|
|
245
335
|
<DropdownMenuContent align="end" className="min-w-48">
|
|
246
|
-
{
|
|
247
|
-
|
|
248
|
-
<
|
|
249
|
-
|
|
250
|
-
|
|
336
|
+
{showAssignToMe && currentUser && (
|
|
337
|
+
<>
|
|
338
|
+
<DropdownMenuItem onClick={() => changeEditor(currentUser.id)}>
|
|
339
|
+
<Avatar initials={currentUser.initials} color={currentUser.color} size="size-5" />
|
|
340
|
+
<span className="flex-1 font-medium">Assign to me</span>
|
|
341
|
+
</DropdownMenuItem>
|
|
342
|
+
<DropdownMenuSeparator />
|
|
343
|
+
</>
|
|
251
344
|
)}
|
|
252
345
|
<DropdownMenuItem onClick={() => changeEditor("")}>
|
|
253
|
-
<
|
|
346
|
+
<EmptyAvatar size="size-5" />
|
|
347
|
+
<span className="flex-1">No assignee</span>
|
|
254
348
|
{!editor && <Check className="text-muted-foreground size-3.5" />}
|
|
255
349
|
</DropdownMenuItem>
|
|
256
|
-
{
|
|
350
|
+
{rosterUsers.map((u) => (
|
|
257
351
|
<DropdownMenuItem key={u.id} onClick={() => changeEditor(u.id)}>
|
|
258
352
|
<Avatar initials={u.initials} color={u.color} size="size-5" />
|
|
259
|
-
<span className="flex-1">{u.name}</span>
|
|
353
|
+
<span className="flex-1">{u.id === currentUser?.id ? `${u.name} (you)` : u.name}</span>
|
|
260
354
|
{editor?.id === u.id && <Check className="text-muted-foreground size-3.5" />}
|
|
261
355
|
</DropdownMenuItem>
|
|
262
356
|
))}
|
|
@@ -314,10 +408,12 @@ export default function CollaborationReviewBar(props: Props) {
|
|
|
314
408
|
<li className="text-muted-foreground px-4 py-8 text-center text-sm">No comments yet.</li>
|
|
315
409
|
)}
|
|
316
410
|
{comments.map((c) => (
|
|
317
|
-
<li key={c.id} className="
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
411
|
+
<li key={c.id} className="px-4 py-4">
|
|
412
|
+
{/* Same border+padding as the body below, so the avatar's left edge
|
|
413
|
+
lines up with the comment text in both read and edit states. */}
|
|
414
|
+
<div className="flex min-w-0 items-center gap-3 border border-transparent px-2">
|
|
415
|
+
<Avatar initials={c.author.initials} color={c.author.color} size="size-7" />
|
|
416
|
+
<div className="flex min-w-0 flex-1 flex-wrap items-center gap-x-2 gap-y-1">
|
|
321
417
|
<span className="text-sm font-medium">{c.author.name}</span>
|
|
322
418
|
<span className="text-muted-foreground text-xs">{c.time}</span>
|
|
323
419
|
{c.field && (
|
|
@@ -325,58 +421,146 @@ export default function CollaborationReviewBar(props: Props) {
|
|
|
325
421
|
on {c.field}
|
|
326
422
|
</span>
|
|
327
423
|
)}
|
|
328
|
-
<
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
424
|
+
<DropdownMenu>
|
|
425
|
+
<DropdownMenuTrigger
|
|
426
|
+
disabled={busy}
|
|
427
|
+
aria-label="Comment actions"
|
|
428
|
+
className="text-muted-foreground hover:bg-foreground/5 hover:text-foreground ml-auto rounded-md p-1 outline-none disabled:opacity-60"
|
|
429
|
+
>
|
|
430
|
+
<EllipsisVertical className="size-3.5" />
|
|
431
|
+
</DropdownMenuTrigger>
|
|
432
|
+
<DropdownMenuContent align="end" className="min-w-32">
|
|
433
|
+
{canEditComment(c) && (
|
|
434
|
+
<DropdownMenuItem onClick={() => startEdit(c)}>Edit</DropdownMenuItem>
|
|
435
|
+
)}
|
|
436
|
+
<DropdownMenuItem onClick={() => toggleResolve(c)}>
|
|
437
|
+
{c.resolved ? "Reopen" : "Resolve"}
|
|
438
|
+
</DropdownMenuItem>
|
|
439
|
+
{canDeleteComment(c) && (
|
|
440
|
+
<DropdownMenuItem variant="destructive" onClick={() => deleteComment(c)}>
|
|
441
|
+
Delete
|
|
442
|
+
</DropdownMenuItem>
|
|
443
|
+
)}
|
|
444
|
+
</DropdownMenuContent>
|
|
445
|
+
</DropdownMenu>
|
|
336
446
|
</div>
|
|
337
|
-
<p className={cn("mt-1 text-sm", c.resolved && "text-muted-foreground line-through")}>{c.body}</p>
|
|
338
447
|
</div>
|
|
448
|
+
{editingId === c.id ? (
|
|
449
|
+
<form
|
|
450
|
+
className="mt-2 grid gap-2"
|
|
451
|
+
onSubmit={(e) => {
|
|
452
|
+
e.preventDefault();
|
|
453
|
+
void saveEdit(c);
|
|
454
|
+
}}
|
|
455
|
+
>
|
|
456
|
+
<textarea
|
|
457
|
+
autoFocus
|
|
458
|
+
rows={1}
|
|
459
|
+
ref={autoGrow}
|
|
460
|
+
value={editDraft}
|
|
461
|
+
onChange={(e) => {
|
|
462
|
+
setEditDraft(e.target.value);
|
|
463
|
+
autoGrow(e.target);
|
|
464
|
+
}}
|
|
465
|
+
onKeyDown={(e) => {
|
|
466
|
+
if (e.key === "Escape") setEditingId(null);
|
|
467
|
+
if (e.key === "Enter" && !e.shiftKey) {
|
|
468
|
+
e.preventDefault();
|
|
469
|
+
void saveEdit(c);
|
|
470
|
+
}
|
|
471
|
+
}}
|
|
472
|
+
className="border-input bg-background w-full resize-none rounded-md border px-2 py-1 text-sm outline-none"
|
|
473
|
+
/>
|
|
474
|
+
<div className="flex justify-end gap-2">
|
|
475
|
+
<button
|
|
476
|
+
type="button"
|
|
477
|
+
onClick={() => setEditingId(null)}
|
|
478
|
+
className={cn(buttonVariants({ variant: "outline", size: "sm" }))}
|
|
479
|
+
>
|
|
480
|
+
Cancel
|
|
481
|
+
</button>
|
|
482
|
+
<button type="submit" disabled={busy} className={cn(buttonVariants({ size: "sm" }))}>
|
|
483
|
+
Save
|
|
484
|
+
</button>
|
|
485
|
+
</div>
|
|
486
|
+
</form>
|
|
487
|
+
) : (
|
|
488
|
+
<p
|
|
489
|
+
className={cn(
|
|
490
|
+
"mt-2 rounded-md border border-transparent px-2 py-1 text-sm whitespace-pre-wrap",
|
|
491
|
+
c.resolved && "text-muted-foreground line-through",
|
|
492
|
+
)}
|
|
493
|
+
>
|
|
494
|
+
{c.body}
|
|
495
|
+
{c.edited && <span className="text-muted-foreground ml-1.5 text-[10px]">(edited)</span>}
|
|
496
|
+
</p>
|
|
497
|
+
)}
|
|
339
498
|
</li>
|
|
340
499
|
))}
|
|
341
500
|
</ul>
|
|
342
|
-
<div className="bg-background sticky bottom-0 flex items-
|
|
343
|
-
<MessageSquarePlus className="text-muted-foreground size-4 shrink-0" />
|
|
344
|
-
<
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
501
|
+
<div className="bg-background sticky bottom-0 flex items-start gap-2 border-t px-4 py-3">
|
|
502
|
+
<MessageSquarePlus className="text-muted-foreground mt-2 size-4 shrink-0" />
|
|
503
|
+
<div className="min-w-0 flex-1">
|
|
504
|
+
<textarea
|
|
505
|
+
ref={commentInputRef}
|
|
506
|
+
rows={1}
|
|
507
|
+
value={draft}
|
|
508
|
+
disabled={busy || !currentUser}
|
|
509
|
+
onChange={(e) => {
|
|
510
|
+
setDraft(e.target.value);
|
|
511
|
+
autoGrow(e.target);
|
|
512
|
+
}}
|
|
513
|
+
onKeyDown={(e) => {
|
|
514
|
+
// Enter sends; Shift+Enter starts a new line.
|
|
515
|
+
if (e.key === "Enter" && !e.shiftKey) {
|
|
516
|
+
e.preventDefault();
|
|
517
|
+
submitComment();
|
|
518
|
+
}
|
|
519
|
+
}}
|
|
520
|
+
placeholder={currentUser ? "Write a comment…" : "Sign in to comment"}
|
|
521
|
+
className="border-input bg-background w-full resize-none rounded-md border px-3 py-1.5 text-sm outline-none"
|
|
522
|
+
/>
|
|
523
|
+
{draft.trim() && (
|
|
524
|
+
// Only the non-obvious half needs teaching — they already found Enter.
|
|
525
|
+
<p className="text-muted-foreground mt-1.5 flex items-center gap-1.5 text-xs">
|
|
526
|
+
<kbd className="text-foreground/45 inline-flex items-center gap-1 rounded border px-1.5 py-0.5 font-sans text-[11px] leading-none font-medium">
|
|
527
|
+
Shift + Enter
|
|
528
|
+
</kbd>
|
|
529
|
+
for a new line
|
|
530
|
+
</p>
|
|
531
|
+
)}
|
|
532
|
+
</div>
|
|
356
533
|
</div>
|
|
357
534
|
</div>
|
|
358
535
|
)}
|
|
359
536
|
|
|
360
|
-
{tab === "activity" &&
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
537
|
+
{tab === "activity" &&
|
|
538
|
+
(activity.length === 0 ? (
|
|
539
|
+
// Centre it: a lone line pinned to the top of a full-height sheet reads
|
|
540
|
+
// as a layout bug rather than an empty state.
|
|
541
|
+
<div className="text-muted-foreground flex flex-1 flex-col items-center justify-center gap-2 px-4 text-sm">
|
|
542
|
+
<Clock className="size-5 opacity-40" />
|
|
543
|
+
<p>No activity yet.</p>
|
|
544
|
+
</div>
|
|
545
|
+
) : (
|
|
546
|
+
<ul className="flex-1 space-y-4 overflow-y-auto px-4 py-4">
|
|
547
|
+
{activity.map((a, i) => (
|
|
548
|
+
<li key={i} className="flex gap-3">
|
|
549
|
+
<div className="flex flex-col items-center">
|
|
550
|
+
<Avatar initials={a.actor.initials} color={a.actor.color} />
|
|
551
|
+
{i < activity.length - 1 && <GitCommitVertical className="text-border mt-1 size-4" />}
|
|
552
|
+
</div>
|
|
553
|
+
<div className="min-w-0 flex-1 pt-0.5">
|
|
554
|
+
<p className="text-sm">
|
|
555
|
+
<span className="font-medium">{a.actor.name}</span>{" "}
|
|
556
|
+
<span className="text-muted-foreground">{a.text}</span>
|
|
557
|
+
</p>
|
|
558
|
+
<span className="text-muted-foreground text-xs">{a.time}</span>
|
|
559
|
+
</div>
|
|
560
|
+
</li>
|
|
561
|
+
))}
|
|
562
|
+
</ul>
|
|
563
|
+
))}
|
|
380
564
|
</SheetContent>
|
|
381
565
|
</Sheet>
|
|
382
566
|
</>
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
import "virtual:kide/admin-css";
|
|
3
3
|
import { cms } from "virtual:kide/api";
|
|
4
|
+
import config from "virtual:kide/config";
|
|
4
5
|
|
|
5
6
|
import {
|
|
6
7
|
ChevronDown,
|
|
@@ -79,6 +80,10 @@ import MobileSidebar from "../components/MobileSidebar";
|
|
|
79
80
|
import SidebarUserMenu from "../components/SidebarUserMenu";
|
|
80
81
|
import Toast from "../components/Toast.astro";
|
|
81
82
|
import { cn } from "../lib/utils";
|
|
83
|
+
import { eligibleCollabSlugs, loadNeedsYou } from "../lib/collaboration";
|
|
84
|
+
import { canRead } from "../lib/access";
|
|
85
|
+
import { isApprover, resolveCollaboration } from "../../core";
|
|
86
|
+
import { collaboration } from "virtual:kide/runtime";
|
|
82
87
|
|
|
83
88
|
const {
|
|
84
89
|
title = "Admin",
|
|
@@ -131,6 +136,25 @@ const pinnedIcons: Record<string, any> = {
|
|
|
131
136
|
users: Users,
|
|
132
137
|
};
|
|
133
138
|
|
|
139
|
+
// "Needs you" queue — the nav entry only exists when collaboration is switched on
|
|
140
|
+
// for at least one readable collection, and its badge is the whole notification
|
|
141
|
+
// story for now: without a count nobody visits a queue they have to remember.
|
|
142
|
+
const needsYouSlugs = eligibleCollabSlugs(config, user, resolveCollaboration, canRead);
|
|
143
|
+
let needsYouCount = 0;
|
|
144
|
+
if (needsYouSlugs.size > 0 && user) {
|
|
145
|
+
try {
|
|
146
|
+
const queue = await loadNeedsYou({
|
|
147
|
+
collaboration,
|
|
148
|
+
userId: String(user.id),
|
|
149
|
+
isApprover: isApprover(config, user.role),
|
|
150
|
+
eligibleSlugs: needsYouSlugs,
|
|
151
|
+
});
|
|
152
|
+
needsYouCount = queue.length;
|
|
153
|
+
} catch {
|
|
154
|
+
// Table may not exist yet on first run — a missing badge beats a broken layout.
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
134
158
|
// Unread submissions badge — shown next to "Forms" in the sidebar.
|
|
135
159
|
let unreadSubmissions = 0;
|
|
136
160
|
try {
|
|
@@ -187,10 +211,25 @@ type NavItem = {
|
|
|
187
211
|
weight: number;
|
|
188
212
|
group: string;
|
|
189
213
|
badge?: number;
|
|
214
|
+
/** Word after the count. "new" suits an inbox of arrivals; a work queue is not new. */
|
|
215
|
+
badgeLabel?: string;
|
|
190
216
|
};
|
|
191
217
|
const navItems: NavItem[] = [];
|
|
192
218
|
|
|
193
219
|
// Built-in nav items with default weights (spaced by 10 for easy interleaving)
|
|
220
|
+
if (needsYouSlugs.size > 0) {
|
|
221
|
+
navItems.push({
|
|
222
|
+
href: "/admin/needs-you",
|
|
223
|
+
label: "Needs you",
|
|
224
|
+
Icon: Inbox,
|
|
225
|
+
active: activeCollection === "needs-you",
|
|
226
|
+
badge: needsYouCount > 0 ? needsYouCount : undefined,
|
|
227
|
+
badgeLabel: "open",
|
|
228
|
+
weight: -10,
|
|
229
|
+
group: "Content",
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
|
|
194
233
|
navItems.push({
|
|
195
234
|
href: "/admin/recent",
|
|
196
235
|
label: "Recent",
|
|
@@ -390,7 +429,7 @@ const navGroups = [...new Set(navItems.map((item) => item.group))]
|
|
|
390
429
|
<span class="flex-1">{item.label}</span>
|
|
391
430
|
{item.badge ? (
|
|
392
431
|
<span class="text-muted-foreground/80 text-xs tabular-nums">
|
|
393
|
-
{item.badge > 99 ? "99+" : item.badge} new
|
|
432
|
+
{item.badge > 99 ? "99+" : item.badge} {item.badgeLabel ?? "new"}
|
|
394
433
|
</span>
|
|
395
434
|
) : null}
|
|
396
435
|
</a>
|
|
@@ -470,7 +509,7 @@ const navGroups = [...new Set(navItems.map((item) => item.group))]
|
|
|
470
509
|
<span class="flex-1">{item.label}</span>
|
|
471
510
|
{item.badge ? (
|
|
472
511
|
<span class="text-muted-foreground/80 text-xs tabular-nums">
|
|
473
|
-
{item.badge > 99 ? "99+" : item.badge} new
|
|
512
|
+
{item.badge > 99 ? "99+" : item.badge} {item.badgeLabel ?? "new"}
|
|
474
513
|
</span>
|
|
475
514
|
) : null}
|
|
476
515
|
</a>
|