Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

refactor(community): extract shared CreateDialogShell for create dialogs (④b)

Gus083c77951d0d
diff --git a/src/web/src/components/community/category-settings-dialog.tsx b/src/web/src/components/community/category-settings-dialog.tsx
index 5c639bd7a..30b9a92f4 100644
--- a/src/web/src/components/community/category-settings-dialog.tsx
+++ b/src/web/src/components/community/category-settings-dialog.tsx
@@ -1,9 +1,9 @@
"use client"
import { useState } from "react"
-import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter } from "@/components/ui/dialog"
import { Button } from "@/components/ui/button"
import { onEnterSubmit } from "@/lib/ime"
+import { CreateDialogShell } from "./create-dialog-shell"
import { PrivateCategoryRow } from "./private-category-row"
// Category settings dialog — rename only. Privacy (public/private) is fixed at
@@ -24,29 +24,29 @@ export function CategorySettingsDialog({ name, isPrivate, onClose, onSave }: {
onClose()
}
return (
- <Dialog open onOpenChange={(o) => { if (!o) onClose() }}>
- <DialogContent className="w-105 max-w-[calc(100vw-2rem)] p-0">
- <DialogHeader className="px-5 pt-5 pb-0">
- <DialogTitle className="text-xs font-normal text-muted-foreground">Category settings</DialogTitle>
- </DialogHeader>
- <div className="space-y-6 px-5 pb-5 pt-2">
- {/* Category name = hero: large inline title input. */}
- <input
- value={nameDraft}
- onChange={(e) => setNameDraft(e.target.value)}
- onKeyDown={onEnterSubmit(save)}
- placeholder="e.g. Text channels"
- autoFocus
- aria-label="Category name"
- className="w-full border-0 bg-transparent p-0 text-[30px] font-medium leading-tight tracking-tight shadow-none outline-none placeholder:font-normal placeholder:text-muted-foreground/40 focus-visible:ring-0"
- />
- {isPrivate && <PrivateCategoryRow isPrivate locked />}
- </div>
- <DialogFooter className="mx-0 mb-0 flex-row items-center justify-end gap-2 px-5 pb-5">
+ <CreateDialogShell
+ onClose={onClose}
+ title="Category settings"
+ footer={
+ <>
<Button variant="ghost" size="sm" onClick={onClose}>Cancel</Button>
<Button size="sm" onClick={save} disabled={!trimmedName}>Save</Button>
- </DialogFooter>
- </DialogContent>
- </Dialog>
+ </>
+ }
+ >
+ <div className="space-y-6 px-5 pb-5 pt-2">
+ {/* Category name = hero: large inline title input. */}
+ <input
+ value={nameDraft}
+ onChange={(e) => setNameDraft(e.target.value)}
+ onKeyDown={onEnterSubmit(save)}
+ placeholder="e.g. Text channels"
+ autoFocus
+ aria-label="Category name"
+ className="w-full border-0 bg-transparent p-0 text-[30px] font-medium leading-tight tracking-tight shadow-none outline-none placeholder:font-normal placeholder:text-muted-foreground/40 focus-visible:ring-0"
+ />
+ {isPrivate && <PrivateCategoryRow isPrivate locked />}
+ </div>
+ </CreateDialogShell>
)
}
diff --git a/src/web/src/components/community/create-category-dialog.tsx b/src/web/src/components/community/create-category-dialog.tsx
index 706f5d809..2f6e8fe9e 100644
--- a/src/web/src/components/community/create-category-dialog.tsx
+++ b/src/web/src/components/community/create-category-dialog.tsx
@@ -1,9 +1,9 @@
"use client"
import { useState } from "react"
-import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter } from "@/components/ui/dialog"
import { Button } from "@/components/ui/button"
import { onEnterSubmit } from "@/lib/ime"
+import { CreateDialogShell } from "./create-dialog-shell"
import { PrivateCategoryRow } from "./private-category-row"
// Create Category dialog — name + private toggle (defaults to public). In a
@@ -24,31 +24,31 @@ export function CreateCategoryDialog({ onClose, onCreate, canTogglePrivate = tru
onClose()
}
return (
- <Dialog open onOpenChange={(o) => { if (!o) onClose() }}>
- <DialogContent className="w-105 max-w-[calc(100vw-2rem)] p-0">
- <DialogHeader className="px-5 pt-5 pb-0">
- <DialogTitle className="text-xs font-normal text-muted-foreground">New category</DialogTitle>
- </DialogHeader>
- <div className="space-y-6 px-5 pb-5 pt-2">
- {/* Category name = hero: large inline title input. */}
- <input
- value={name}
- onChange={(e) => setName(e.target.value)}
- onKeyDown={onEnterSubmit(submit)}
- placeholder="e.g. Text channels"
- autoFocus
- aria-label="Category name"
- className="w-full border-0 bg-transparent p-0 text-[30px] font-medium leading-tight tracking-tight shadow-none outline-none placeholder:font-normal placeholder:text-muted-foreground/40 focus-visible:ring-0"
- />
- {canTogglePrivate && (
- <PrivateCategoryRow isPrivate={isPrivate} onToggle={setIsPrivate} />
- )}
- </div>
- <DialogFooter className="mx-0 mb-0 flex-row items-center justify-end gap-2 px-5 pb-5">
+ <CreateDialogShell
+ onClose={onClose}
+ title="New category"
+ footer={
+ <>
<Button variant="ghost" size="sm" onClick={onClose}>Cancel</Button>
<Button size="sm" onClick={submit} disabled={!name.trim()}>Create category</Button>
- </DialogFooter>
- </DialogContent>
- </Dialog>
+ </>
+ }
+ >
+ <div className="space-y-6 px-5 pb-5 pt-2">
+ {/* Category name = hero: large inline title input. */}
+ <input
+ value={name}
+ onChange={(e) => setName(e.target.value)}
+ onKeyDown={onEnterSubmit(submit)}
+ placeholder="e.g. Text channels"
+ autoFocus
+ aria-label="Category name"
+ className="w-full border-0 bg-transparent p-0 text-[30px] font-medium leading-tight tracking-tight shadow-none outline-none placeholder:font-normal placeholder:text-muted-foreground/40 focus-visible:ring-0"
+ />
+ {canTogglePrivate && (
+ <PrivateCategoryRow isPrivate={isPrivate} onToggle={setIsPrivate} />
+ )}
+ </div>
+ </CreateDialogShell>
)
}
diff --git a/src/web/src/components/community/create-channel-dialog.tsx b/src/web/src/components/community/create-channel-dialog.tsx
index 95f6b1e14..4b2323592 100644
--- a/src/web/src/components/community/create-channel-dialog.tsx
+++ b/src/web/src/components/community/create-channel-dialog.tsx
@@ -3,7 +3,7 @@
import { useState } from "react"
import { Check } from "lucide-react"
import { EntityIcon } from "./entity-icon"
-import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter } from "@/components/ui/dialog"
+import { CreateDialogShell } from "./create-dialog-shell"
import { Button } from "@/components/ui/button"
import { tid } from "@/lib/community/testids"
import { onEnterSubmit } from "@/lib/ime"
@@ -38,14 +38,16 @@ export function CreateChannelDialog({ category, initial, onClose, onCreate }: {
}
return (
- <Dialog open onOpenChange={(o) => { if (!o) onClose() }}>
- <DialogContent className="w-105 max-w-[calc(100vw-2rem)] p-0">
- {/* Small breadcrumb for context; the name below is the hero. */}
- <DialogHeader className="px-5 pt-5 pb-0">
- <DialogTitle className="text-xs font-normal text-muted-foreground">
- {editing ? "Edit channel" : "New channel"}{category ? ` in ${category}` : ""}
- </DialogTitle>
- </DialogHeader>
+ <CreateDialogShell
+ onClose={onClose}
+ title={`${editing ? "Edit channel" : "New channel"}${category ? ` in ${category}` : ""}`}
+ footer={
+ <>
+ <Button variant="ghost" size="sm" onClick={onClose}>Cancel</Button>
+ <Button size="sm" data-testid={tid.createChannelSubmit} onClick={submit} disabled={!namePreview.slug}>{editing ? "Save" : "Create Channel"}</Button>
+ </>
+ }
+ >
<div className="space-y-6 px-5 pb-5 pt-2">
{/* Channel name = hero: large inline title input, glyph in front. */}
<div>
@@ -92,11 +94,6 @@ export function CreateChannelDialog({ category, initial, onClose, onCreate }: {
</div>
)}
</div>
- <DialogFooter className="mx-0 mb-0 flex-row items-center justify-end gap-2 px-5 pb-5">
- <Button variant="ghost" size="sm" onClick={onClose}>Cancel</Button>
- <Button size="sm" data-testid={tid.createChannelSubmit} onClick={submit} disabled={!namePreview.slug}>{editing ? "Save" : "Create Channel"}</Button>
- </DialogFooter>
- </DialogContent>
- </Dialog>
+ </CreateDialogShell>
)
}
diff --git a/src/web/src/components/community/create-dialog-shell.tsx b/src/web/src/components/community/create-dialog-shell.tsx
new file mode 100644
index 000000000..3a795daf2
--- /dev/null
+++ b/src/web/src/components/community/create-dialog-shell.tsx
@@ -0,0 +1,53 @@
+"use client"
+
+import type React from "react"
+import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter } from "@/components/ui/dialog"
+import { cn } from "@/lib/utils"
+
+// The shared frameless shell for the community create/edit dialogs
+// (create-server / create-channel / create-category / category-settings).
+// Extracted so the four stop copy-pasting the same unframed Dialog scaffold —
+// a single source for the 105-width container, the padding rhythm, the quiet
+// breadcrumb header, and the floating (borderless) footer. Body + footer
+// content are passed in; the shell only owns the frame.
+//
+// `title` is usually the quiet breadcrumb ("New channel in DEV"); pass
+// `mutedTitle={false}` for a full-weight heading (create-server's "choose"
+// step). `footerClassName` lets create-server switch to `justify-between`
+// (Back + action) instead of the default right-aligned actions.
+export function CreateDialogShell({
+ open = true,
+ onClose,
+ title,
+ mutedTitle = true,
+ footer,
+ footerClassName,
+ children,
+}: {
+ open?: boolean
+ onClose: () => void
+ title: React.ReactNode
+ mutedTitle?: boolean
+ // Omit for a footerless dialog (e.g. create-server's "choose" step).
+ footer?: React.ReactNode
+ footerClassName?: string
+ children: React.ReactNode
+}) {
+ return (
+ <Dialog open={open} onOpenChange={(o) => { if (!o) onClose() }}>
+ <DialogContent className="w-105 max-w-[calc(100vw-2rem)] p-0">
+ <DialogHeader className="px-5 pt-5 pb-0">
+ <DialogTitle className={mutedTitle ? "text-xs font-normal text-muted-foreground" : undefined}>
+ {title}
+ </DialogTitle>
+ </DialogHeader>
+ {children}
+ {footer !== undefined && (
+ <DialogFooter className={cn("mx-0 mb-0 flex-row items-center gap-2 px-5 pb-5", footerClassName ?? "justify-end")}>
+ {footer}
+ </DialogFooter>
+ )}
+ </DialogContent>
+ </Dialog>
+ )
+}
diff --git a/src/web/src/components/community/create-server-dialog.tsx b/src/web/src/components/community/create-server-dialog.tsx
index 18cf53624..34fe07b12 100644
--- a/src/web/src/components/community/create-server-dialog.tsx
+++ b/src/web/src/components/community/create-server-dialog.tsx
@@ -3,7 +3,7 @@
import { useRef, useState } from "react"
import { toast } from "sonner"
import { Plus, ChevronRight, Link2 } from "lucide-react"
-import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter } from "@/components/ui/dialog"
+import { CreateDialogShell } from "./create-dialog-shell"
import { Button } from "@/components/ui/button"
import { tid } from "@/lib/community/testids"
import { SlugHint } from "./slug-hint"
@@ -40,13 +40,29 @@ export function CreateServerDialog({ onClose, onCreateServer, onJoinServer }: {
}
return (
<>
- <Dialog open onOpenChange={(o) => { if (!o) onClose() }}>
- <DialogContent className="w-105 max-w-[calc(100vw-2rem)] p-0">
- <DialogHeader className="px-5 pt-5 pb-0">
- <DialogTitle className={step === "choose" ? "" : "text-xs font-normal text-muted-foreground"}>
- {step === "choose" ? "Create a Server" : step === "create" ? "Customize your server" : "Join a Server"}
- </DialogTitle>
- </DialogHeader>
+ <CreateDialogShell
+ onClose={onClose}
+ mutedTitle={step !== "choose"}
+ title={step === "choose" ? "Create a Server" : step === "create" ? "Customize your server" : "Join a Server"}
+ footerClassName="justify-between"
+ footer={step === "choose" ? undefined : (
+ <>
+ <Button variant="ghost" size="sm" onClick={() => setStep("choose")}>Back</Button>
+ <Button
+ size="sm"
+ data-testid={tid.createServerSubmit}
+ disabled={step === "create" ? !namePreview.slug : !invite.trim()}
+ onClick={() => {
+ if (step === "create") onCreateServer?.(name.trim(), iconFile ?? undefined)
+ else onJoinServer?.(invite.trim())
+ onClose()
+ }}
+ >
+ {step === "create" ? "Create" : "Join Server"}
+ </Button>
+ </>
+ )}
+ >
<div className="px-5 pb-5">
{step === "choose" && (
<div className="space-y-1">
@@ -110,25 +126,7 @@ export function CreateServerDialog({ onClose, onCreateServer, onJoinServer }: {
</div>
)}
</div>
- {step !== "choose" && (
- <DialogFooter className="mx-0 mb-0 flex-row items-center justify-between px-5 pb-5">
- <Button variant="ghost" size="sm" onClick={() => setStep("choose")}>Back</Button>
- <Button
- size="sm"
- data-testid={tid.createServerSubmit}
- disabled={step === "create" ? !namePreview.slug : !invite.trim()}
- onClick={() => {
- if (step === "create") onCreateServer?.(name.trim(), iconFile ?? undefined)
- else onJoinServer?.(invite.trim())
- onClose()
- }}
- >
- {step === "create" ? "Create" : "Join Server"}
- </Button>
- </DialogFooter>
- )}
- </DialogContent>
- </Dialog>
+ </CreateDialogShell>
{pendingCropSrc && (
<ImageCropDialog
imageSrc={pendingCropSrc.src}