From f4c69ef5e7092cda4a453b0a3bcd6975399e7182 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Boduro=C4=9Flu?= <80620802+burakboduroglu@users.noreply.github.com> Date: Thu, 23 Jul 2026 20:26:20 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20=E2=9C=A8=20Gmail-style=20messages=20pa?= =?UTF-8?q?ge,=20rich=20text=20editor,=20and=20fixed=20backend=20folder=20?= =?UTF-8?q?gates?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - redesign messages page into a 1-to-1 Gmail clone layout with left sidebar, dense rows, detail view, and floating compose box - add lightweight HTML RichTextEditor component with formatting toolbar (bold, italic, underline, strike, bullet/number lists) - render rich HTML mail body in detail view and strip HTML tags for row preview snippets - add Gmail inline reply box directly beneath the email detail content - add restore from archive/trash buttons and empty trash functionality - fix backend permission constraints (restrict archive to recipients, permanent delete to trash folder) - fix layout shift on row hover by fixing action container width and row height - fix toast notification container padding and vertical alignment --- src/api/client/types.ts | 1 + src/components/messages/gmail-compose-box.tsx | 203 +++++ src/components/messages/gmail-mail-detail.tsx | 317 ++++++++ src/components/messages/gmail-mail-row.tsx | 145 ++++ src/components/messages/message-item-card.tsx | 127 +++ src/components/messages/quick-reply-bar.tsx | 80 ++ src/components/ui/alert.tsx | 8 +- src/components/ui/rich-text-editor.tsx | 143 ++++ src/components/ui/toast.tsx | 8 +- src/pages/messages-page.tsx | 743 ++++++++---------- 10 files changed, 1361 insertions(+), 414 deletions(-) create mode 100644 src/components/messages/gmail-compose-box.tsx create mode 100644 src/components/messages/gmail-mail-detail.tsx create mode 100644 src/components/messages/gmail-mail-row.tsx create mode 100644 src/components/messages/message-item-card.tsx create mode 100644 src/components/messages/quick-reply-bar.tsx create mode 100644 src/components/ui/rich-text-editor.tsx diff --git a/src/api/client/types.ts b/src/api/client/types.ts index 1d6b9eb..ba08ff4 100644 --- a/src/api/client/types.ts +++ b/src/api/client/types.ts @@ -388,6 +388,7 @@ export type Message = { sent_at: number; read: boolean; folder: MessageFolder; + previous_folder?: MessageFolder | string | null; label: string | null; }; diff --git a/src/components/messages/gmail-compose-box.tsx b/src/components/messages/gmail-compose-box.tsx new file mode 100644 index 0000000..2ea8867 --- /dev/null +++ b/src/components/messages/gmail-compose-box.tsx @@ -0,0 +1,203 @@ +import { createSignal, createEffect, Show } from "solid-js"; +import { Button } from "@/components/ui/button"; +import { Input } from "@/components/ui/input"; +import { RichTextEditor } from "@/components/ui/rich-text-editor"; +import { UserSearchSelect } from "@/components/users/user-search-select"; +import { IconSend, IconTrash, IconX } from "@/components/ui/icons"; +import { postMessage } from "@/api/messages"; +import { formatApiError } from "@/api/client"; +import { useAuth } from "@/stores/auth-context"; +import { useT } from "@/stores/preferences-context"; + +interface GmailComposeBoxProps { + open: boolean; + onClose: () => void; + onSuccess: () => void; + initialRecipient?: string; + initialSubject?: string; + initialBody?: string; +} + +export function GmailComposeBox(props: GmailComposeBoxProps) { + const t = useT(); + const auth = useAuth(); + const [recipient, setRecipient] = createSignal(""); + const [subject, setSubject] = createSignal(""); + const [body, setBody] = createSignal(""); + const [label, setLabel] = createSignal(""); + const [isMinimized, setIsMinimized] = createSignal(false); + const [pending, setPending] = createSignal(false); + const [error, setError] = createSignal(""); + + createEffect(() => { + if (props.open) { + setRecipient(props.initialRecipient ?? ""); + setSubject(props.initialSubject ?? ""); + setBody(props.initialBody ?? ""); + setLabel(""); + setIsMinimized(false); + setError(""); + } + }); + + const reset = () => { + setRecipient(""); + setSubject(""); + setBody(""); + setLabel(""); + setError(""); + }; + + const handleClose = () => { + reset(); + props.onClose(); + }; + + const handleSend = async (e: SubmitEvent) => { + e.preventDefault(); + if (!recipient()) { + setError(t("messages.selectRecipient")); + return; + } + setError(""); + setPending(true); + + try { + await postMessage({ + recipient_id: recipient(), + subject: subject().trim(), + body: body().trim() || undefined, + label: label().trim() || undefined, + }); + props.onSuccess(); + handleClose(); + } catch (err) { + setError(formatApiError(err)); + } finally { + setPending(false); + } + }; + + return ( + +
+ {/* Gmail Header */} +
+
+ +

+ {subject() ? subject() : t("messages.newMessage")} +

+
+
+ + +
+
+ + {/* Gmail Form Content */} + +
+ {/* Recipient Line */} +
+ + {t("messages.recipient")}: + +
+ +
+
+ + {/* Subject Line */} +
+ + {t("form.title")}: + + setSubject(e.currentTarget.value)} + /> +
+ + {/* Optional Label Tag Line */} +
+ + Etiket: + + setLabel(e.currentTarget.value)} + /> +
+ + {/* Gmail Rich Text Editor Area */} +
+ +
+ + +

{error()}

+
+ + {/* Gmail Bottom Action Toolbar */} +
+ + + +
+
+
+
+
+ ); +} diff --git a/src/components/messages/gmail-mail-detail.tsx b/src/components/messages/gmail-mail-detail.tsx new file mode 100644 index 0000000..4543c69 --- /dev/null +++ b/src/components/messages/gmail-mail-detail.tsx @@ -0,0 +1,317 @@ +import { createSignal, Show } from "solid-js"; +import type { Message, MessageFolder } from "@/api/client"; +import { Badge } from "@/components/ui/badge"; +import { Button } from "@/components/ui/button"; +import { RichTextEditor } from "@/components/ui/rich-text-editor"; +import { IconSend, IconTrash, IconMessage, IconArchive, IconChevronLeft } from "@/components/ui/icons"; +import { postMessage } from "@/api/messages"; +import { formatApiError } from "@/api/client"; +import { personLabel } from "@/lib/person"; +import { useT } from "@/stores/preferences-context"; + +interface GmailMailDetailProps { + message: Message; + currentUserId?: string; + folder: string; + onBack: () => void; + onAction: (action: { folder?: MessageFolder; delete?: boolean }) => Promise; + onSuccess: () => void; + setFlash: (text: string) => void; +} + +export function GmailMailDetail(props: GmailMailDetailProps) { + const t = useT(); + const [isReplying, setIsReplying] = createSignal(false); + const [replyBody, setReplyBody] = createSignal(""); + const [sending, setSending] = createSignal(false); + const [error, setError] = createSignal(""); + + const isSent = () => props.folder === "sent" || props.message.sender.id === props.currentUserId; + const peer = () => (isSent() ? props.message.recipient : props.message.sender); + const peerName = () => personLabel(peer()); + const role = () => (isSent() ? props.message.recipient_role : props.message.sender_role); + + const restoreFolder = (): MessageFolder => { + if (props.message.previous_folder && (props.message.previous_folder as string) !== "deleted") { + return props.message.previous_folder as MessageFolder; + } + return isSent() ? "sent" : "inbox"; + }; + + const formattedDate = (ts: number) => { + const date = new Date(ts); + return date.toLocaleString([], { + year: "numeric", + month: "long", + day: "numeric", + hour: "2-digit", + minute: "2-digit", + }); + }; + + const handleStartReply = () => { + setIsReplying(true); + setReplyBody(""); + setError(""); + }; + + const handleSendReply = async (e: Event) => { + e.preventDefault(); + const content = replyBody().trim(); + if (!content || sending()) return; + + setError(""); + setSending(true); + + try { + const replySubject = props.message.subject.startsWith("Re:") + ? props.message.subject + : `Re: ${props.message.subject}`; + + await postMessage({ + recipient_id: peer().id, + subject: replySubject, + body: content, + }); + + props.setFlash(t("messages.sentToast")); + setIsReplying(false); + setReplyBody(""); + props.onSuccess(); + } catch (err: any) { + setError(formatApiError(err)); + } finally { + setSending(false); + } + }; + + return ( +
+ {/* Top Gmail Navigation & Action Bar */} +
+
+ + +
+ + {/* Move to Archive Action */} + + + + + {/* Restore out of Archive */} + + + + + {/* Restore out of Trash */} + + + + + {/* Move to Trash Action */} + + + + + {/* Permanent Delete Action */} + + + +
+ +
+ {formattedDate(props.message.sent_at)} +
+
+ + {/* Main Mail Content View Container */} +
+ {/* Email Subject Title Header */} +
+
+

+ {props.message.subject} +

+ + + {props.message.label} + + +
+
+ + {/* Sender Info Card */} +
+
+
+ {peerName().charAt(0).toUpperCase()} +
+
+
+ + {peerName()} + + + + {t(`role.${role()}` as any)} + + +
+

+ {isSent() ? `${t("messages.to")}: ` : `${t("messages.from")}: `} + {peerName()} +

+
+
+ + + + +
+ + {/* Email Body Card */} +
+
+
+ + {/* Gmail Style Inline Reply Area */} + +
+ + +
+ } + > + {/* Gmail Inline Reply Editor */} +
+
+
+ Yanıtla: + + {peerName()} + +
+ +
+ + + + +

{error()}

+
+ +
+ + + +
+ +
+
+ +
+
+ ); +} diff --git a/src/components/messages/gmail-mail-row.tsx b/src/components/messages/gmail-mail-row.tsx new file mode 100644 index 0000000..f08cee1 --- /dev/null +++ b/src/components/messages/gmail-mail-row.tsx @@ -0,0 +1,145 @@ +import { Show } from "solid-js"; +import type { Message } from "@/api/client"; +import { Badge } from "@/components/ui/badge"; +import { IconArchive, IconTrash, IconMessage } from "@/components/ui/icons"; +import { cn } from "@/lib/cn"; +import { personLabel } from "@/lib/person"; +import { useT } from "@/stores/preferences-context"; + +interface GmailMailRowProps { + message: Message; + currentUserId?: string; + folder: string; + isSelected: boolean; + onSelect: () => void; + onArchive?: () => void; + onTrash?: () => void; + onToggleRead?: () => void; +} + +export function GmailMailRow(props: GmailMailRowProps) { + const t = useT(); + + const isSent = () => props.folder === "sent" || props.message.sender.id === props.currentUserId; + const peer = () => (isSent() ? props.message.recipient : props.message.sender); + const peerName = () => personLabel(peer()); + const role = () => (isSent() ? props.message.recipient_role : props.message.sender_role); + const unread = () => !isSent() && !props.message.read; + + const formattedTime = (ts: number) => { + const date = new Date(ts); + const now = new Date(); + const isToday = + date.getDate() === now.getDate() && + date.getMonth() === now.getMonth() && + date.getFullYear() === now.getFullYear(); + + if (isToday) { + return date.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" }); + } + return date.toLocaleDateString([], { month: "short", day: "numeric" }); + }; + + return ( +
+ {/* Sender / Peer Name */} +
+ + {isSent() ? `${t("messages.to")}${peerName()}` : peerName()} + + + + {t(`role.${role()}` as any)} + + +
+ + {/* Subject + Body Snippet (Gmail Single Line) */} +
+ + {props.message.subject} + + + — {props.message.body.replace(/<[^>]*>?/gm, "").trim()} + +
+ + {/* Optional Tag Label */} + + + {props.message.label} + + + + {/* Fixed-width & Fixed-height Right Action Area */} +
+ {/* Time / Date (Default View) */} +
+ {formattedTime(props.message.sent_at)} +
+ + {/* Gmail Hover Quick Action Bar (Hover View - Fixed h-6 buttons to fit h-10 row cleanly) */} + +
+
+ ); +} diff --git a/src/components/messages/message-item-card.tsx b/src/components/messages/message-item-card.tsx new file mode 100644 index 0000000..27ce3f0 --- /dev/null +++ b/src/components/messages/message-item-card.tsx @@ -0,0 +1,127 @@ +import { Show } from "solid-js"; +import type { Message } from "@/api/client"; +import { Badge } from "@/components/ui/badge"; +import { cn } from "@/lib/cn"; +import { personLabel } from "@/lib/person"; +import { useT } from "@/stores/preferences-context"; + +interface MessageItemCardProps { + message: Message; + currentUserId?: string; + folder: string; + isSelected: boolean; + onSelect: () => void; +} + +export function MessageItemCard(props: MessageItemCardProps) { + const t = useT(); + + const isSent = () => props.folder === "sent" || props.message.sender.id === props.currentUserId; + const peer = () => (isSent() ? props.message.recipient : props.message.sender); + const peerName = () => personLabel(peer()); + const role = () => (isSent() ? props.message.recipient_role : props.message.sender_role); + const unread = () => !isSent() && !props.message.read; + + const initial = () => { + const name = peerName().trim(); + return name.charAt(0).toUpperCase() || "?"; + }; + + const formattedTime = (ts: number) => { + const date = new Date(ts); + const now = new Date(); + const isToday = + date.getDate() === now.getDate() && + date.getMonth() === now.getMonth() && + date.getFullYear() === now.getFullYear(); + + if (isToday) { + return date.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" }); + } + return date.toLocaleDateString([], { month: "short", day: "numeric" }); + }; + + return ( + + ); +} diff --git a/src/components/messages/quick-reply-bar.tsx b/src/components/messages/quick-reply-bar.tsx new file mode 100644 index 0000000..6c900af --- /dev/null +++ b/src/components/messages/quick-reply-bar.tsx @@ -0,0 +1,80 @@ +import { createSignal, Show } from "solid-js"; +import { Button } from "@/components/ui/button"; +import { Textarea } from "@/components/ui/textarea"; +import { IconSend } from "@/components/ui/icons"; +import { useT } from "@/stores/preferences-context"; + +interface QuickReplyBarProps { + recipientName: string; + defaultSubject: string; + onSend: (body: string, subject: string) => Promise; + disabled?: boolean; +} + +export function QuickReplyBar(props: QuickReplyBarProps) { + const t = useT(); + const [body, setBody] = createSignal(""); + const [sending, setSending] = createSignal(false); + const [error, setError] = createSignal(""); + + const handleSend = async (e?: Event) => { + if (e) e.preventDefault(); + const content = body().trim(); + if (!content || sending() || props.disabled) return; + + setError(""); + setSending(true); + + try { + const replySubject = props.defaultSubject.startsWith("Re:") + ? props.defaultSubject + : `Re: ${props.defaultSubject}`; + + await props.onSend(content, replySubject); + setBody(""); + } catch (err: any) { + setError(err?.message || "Mesaj gönderilemedi"); + } finally { + setSending(false); + } + }; + + const handleKeyDown = (e: KeyboardEvent) => { + if (e.key === "Enter" && !e.shiftKey) { + e.preventDefault(); + handleSend(); + } + }; + + return ( +
+
+ +

{error()}

+
+
+
+