SarahXia0405 commited on
Commit
964aab3
·
verified ·
1 Parent(s): 9d3ff63

Update web/src/components/sidebar/LeftSidebar.tsx

Browse files
web/src/components/sidebar/LeftSidebar.tsx CHANGED
@@ -6,7 +6,8 @@ import { Badge } from "../ui/badge";
6
 
7
  import { SavedChatSection } from "./SavedChatSection";
8
 
9
- import { Pencil, Check, X, MailPlus, Users, GraduationCap } from "lucide-react";
 
10
  import { toast } from "sonner";
11
 
12
  import {
@@ -212,25 +213,10 @@ export function LeftSidebar(props: Props) {
212
 
213
  const memberCount = (groupMembers || []).length;
214
 
215
- // localStorage keys (Team space editing)
216
- const groupNameStorageKey = useMemo(
217
- () => `clare_group_name__${currentWorkspaceId}`,
218
- [currentWorkspaceId]
219
- );
220
- const groupNoStorageKey = useMemo(
221
- () => `clare_group_no__${currentWorkspaceId}`,
222
- [currentWorkspaceId]
223
- );
224
-
225
- // group name (Team space editable)
226
- const [groupName, setGroupName] = useState<string>(wsGroupName);
227
- const [editingGroupName, setEditingGroupName] = useState(false);
228
- const [draftGroupName, setDraftGroupName] = useState<string>(wsGroupName);
229
 
230
- // group no (Team space editable)
231
- const [groupNo, setGroupNo] = useState<number>(toIntOrFallback(wsGroupNo, 1));
232
- const [editingGroupNo, setEditingGroupNo] = useState(false);
233
- const [draftGroupNo, setDraftGroupNo] = useState<string>(String(toIntOrFallback(wsGroupNo, 1)));
234
 
235
  // Invite dialog state
236
  const [inviteOpen, setInviteOpen] = useState(false);
@@ -246,69 +232,6 @@ export function LeftSidebar(props: Props) {
246
  setInviteOpen(false);
247
  };
248
 
249
- // hydrate persisted editable values (Team space)
250
- useEffect(() => {
251
- const storedName =
252
- typeof window !== "undefined" ? window.localStorage.getItem(groupNameStorageKey) : null;
253
- const name = storedName && storedName.trim() ? storedName : wsGroupName;
254
- setGroupName(name);
255
- setDraftGroupName(name);
256
- setEditingGroupName(false);
257
-
258
- const storedNo =
259
- typeof window !== "undefined" ? window.localStorage.getItem(groupNoStorageKey) : null;
260
- const no =
261
- storedNo && storedNo.trim()
262
- ? toIntOrFallback(storedNo, toIntOrFallback(wsGroupNo, 1))
263
- : toIntOrFallback(wsGroupNo, 1);
264
- setGroupNo(no);
265
- setDraftGroupNo(String(no));
266
- setEditingGroupNo(false);
267
- }, [groupNameStorageKey, groupNoStorageKey, wsGroupName, wsGroupNo]);
268
-
269
- const saveGroupName = async () => {
270
- const next = (draftGroupName || "").trim() || "My Group";
271
- setGroupName(next);
272
- setDraftGroupName(next);
273
- setEditingGroupName(false);
274
-
275
- if (onRenameGroupName) {
276
- try {
277
- await onRenameGroupName(currentWorkspaceId, next);
278
- return;
279
- } catch {}
280
- }
281
- try {
282
- window.localStorage.setItem(groupNameStorageKey, next);
283
- } catch {}
284
- };
285
-
286
- const cancelGroupName = () => {
287
- setDraftGroupName(groupName);
288
- setEditingGroupName(false);
289
- };
290
-
291
- const saveGroupNo = async () => {
292
- const nextNo = toIntOrFallback(draftGroupNo, groupNo);
293
- setGroupNo(nextNo);
294
- setDraftGroupNo(String(nextNo));
295
- setEditingGroupNo(false);
296
-
297
- if (onRenameGroupNo) {
298
- try {
299
- await onRenameGroupNo(currentWorkspaceId, nextNo);
300
- return;
301
- } catch {}
302
- }
303
- try {
304
- window.localStorage.setItem(groupNoStorageKey, String(nextNo));
305
- } catch {}
306
- };
307
-
308
- const cancelGroupNo = () => {
309
- setDraftGroupNo(String(groupNo));
310
- setEditingGroupNo(false);
311
- };
312
 
313
  // --------- Contacts ---------
314
  const instructorName = (courseInfo as any)?.instructor?.name ?? "N/A";
@@ -321,7 +244,7 @@ export function LeftSidebar(props: Props) {
321
  <div className="h-full w-full flex flex-col min-h-0 bg-background text-foreground">
322
  {/* ================= TOP (non-scroll) ================= */}
323
  <div className="flex-shrink-0">
324
- {/* removed Welcome section entirely */}
325
 
326
  <div className="mt-2 mb-4">
327
  <Divider />
@@ -353,83 +276,19 @@ export function LeftSidebar(props: Props) {
353
  /* ===== Team/Group (editable card) ===== */
354
  <div className="rounded-2xl border bg-background overflow-hidden">
355
  <div className="px-4 pt-4 pb-3 space-y-3">
356
- {/* Line 1: group name editable */}
357
- {!editingGroupName ? (
358
- <div className="flex items-center gap-2">
359
- <div className="text-[18px] font-semibold truncate">{groupName || "My Group"}</div>
360
- <button
361
- type="button"
362
- className="inline-flex items-center text-muted-foreground hover:text-foreground"
363
- onClick={() => setEditingGroupName(true)}
364
- aria-label="Edit group name"
365
- >
366
- <Pencil className="w-4 h-4" />
367
- </button>
368
- </div>
369
- ) : (
370
- <div className="flex items-center gap-2">
371
- <Input
372
- value={draftGroupName}
373
- onChange={(e) => setDraftGroupName(e.target.value)}
374
- onKeyDown={(e) => {
375
- if (e.key === "Enter") saveGroupName();
376
- if (e.key === "Escape") cancelGroupName();
377
- }}
378
- className="h-8 w-[220px]"
379
- autoFocus
380
- />
381
- <Button size="icon" variant="ghost" className="h-8 w-8" onClick={saveGroupName}>
382
- <Check className="w-4 h-4" />
383
- </Button>
384
- <Button size="icon" variant="ghost" className="h-8 w-8" onClick={cancelGroupName}>
385
- <X className="w-4 h-4" />
386
- </Button>
387
- </div>
388
- )}
389
 
390
  {/* Line 2: Group {no}(✏️) ({count}) + Invite */}
391
  <div className="flex items-center justify-between gap-3">
392
  <div className="flex items-center gap-2">
393
  <Users className="w-4 h-4 text-muted-foreground" />
394
-
395
- {!editingGroupNo ? (
396
- <div className="text-[16px] font-medium">
397
- Group{" "}
398
- <span className="inline-flex items-center gap-1">
399
- {groupNo}
400
- <button
401
- type="button"
402
- className="inline-flex items-center text-muted-foreground hover:text-foreground"
403
- onClick={() => setEditingGroupNo(true)}
404
- aria-label="Edit group number"
405
- >
406
- <Pencil className="w-4 h-4" />
407
- </button>
408
- </span>{" "}
409
- ({memberCount})
410
- </div>
411
- ) : (
412
- <div className="flex items-center gap-2">
413
- <div className="text-[16px] font-medium">Group</div>
414
- <Input
415
- value={draftGroupNo}
416
- onChange={(e) => setDraftGroupNo(e.target.value)}
417
- onKeyDown={(e) => {
418
- if (e.key === "Enter") saveGroupNo();
419
- if (e.key === "Escape") cancelGroupNo();
420
- }}
421
- className="h-8 w-[80px]"
422
- autoFocus
423
- />
424
- <div className="text-[16px] font-medium">({memberCount})</div>
425
- <Button size="icon" variant="ghost" className="h-8 w-8" onClick={saveGroupNo}>
426
- <Check className="w-4 h-4" />
427
- </Button>
428
- <Button size="icon" variant="ghost" className="h-8 w-8" onClick={cancelGroupNo}>
429
- <X className="w-4 h-4" />
430
- </Button>
431
- </div>
432
- )}
433
  </div>
434
 
435
  <Button
 
6
 
7
  import { SavedChatSection } from "./SavedChatSection";
8
 
9
+ import { MailPlus, Users, GraduationCap } from "lucide-react";
10
+
11
  import { toast } from "sonner";
12
 
13
  import {
 
213
 
214
  const memberCount = (groupMembers || []).length;
215
 
216
+ // YYYYYYYYYYYY Name and Number
217
+ const groupName = useMemo(() => wsGroupName || "YYY", [wsGroupName]);
218
+ const groupNo = useMemo(() => toIntOrFallback(wsGroupNo, 1), [wsGroupNo]);
 
 
 
 
 
 
 
 
 
 
 
219
 
 
 
 
 
220
 
221
  // Invite dialog state
222
  const [inviteOpen, setInviteOpen] = useState(false);
 
232
  setInviteOpen(false);
233
  };
234
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
235
 
236
  // --------- Contacts ---------
237
  const instructorName = (courseInfo as any)?.instructor?.name ?? "N/A";
 
244
  <div className="h-full w-full flex flex-col min-h-0 bg-background text-foreground">
245
  {/* ================= TOP (non-scroll) ================= */}
246
  <div className="flex-shrink-0">
247
+ {/* removed Welcome section entirely */}
248
 
249
  <div className="mt-2 mb-4">
250
  <Divider />
 
276
  /* ===== Team/Group (editable card) ===== */
277
  <div className="rounded-2xl border bg-background overflow-hidden">
278
  <div className="px-4 pt-4 pb-3 space-y-3">
279
+ {/* Line 1: group name (read-only) */}
280
+ <div className="flex items-center gap-2">
281
+ <div className="text-[18px] font-semibold truncate">{groupName}</div>
282
+ </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
283
 
284
  {/* Line 2: Group {no}(✏️) ({count}) + Invite */}
285
  <div className="flex items-center justify-between gap-3">
286
  <div className="flex items-center gap-2">
287
  <Users className="w-4 h-4 text-muted-foreground" />
288
+
289
+ <div className="text-[16px] font-medium">
290
+ Group <span className="font-semibold">{groupNo}</span> ({memberCount})
291
+ </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
292
  </div>
293
 
294
  <Button