✨ Gmail-style messages page, rich text editor, and fixed backend folder gates
Browse files at this commitf4c69ef5e7092cda4a453b0a3bcd6975399e7182Parent: 9c62a4a- feat
- ✨ Gmail-style messages page, rich text editor, and fixed backend folder gates
10 changed files +1361 -414
- src/api/client/types.ts +1 -0
- src/components/messages/gmail-compose-box.tsx +203 -0
- src/components/messages/gmail-mail-detail.tsx +317 -0
- src/components/messages/gmail-mail-row.tsx +145 -0
- src/components/messages/message-item-card.tsx +127 -0
- src/components/messages/quick-reply-bar.tsx +80 -0
- src/components/ui/alert.tsx +4 -4
- src/components/ui/rich-text-editor.tsx +143 -0
- src/components/ui/toast.tsx +4 -4
- src/pages/messages-page.tsx +337 -406
src/api/client/types.tsmodified+1 -0
| @@ -388,6 +388,7 @@ export type Message = { | |||
| 388 | sent_at: number; | 388 | sent_at: number; |
| 389 | read: boolean; | 389 | read: boolean; |
| 390 | folder: MessageFolder; | 390 | folder: MessageFolder; |
| 391 | + previous_folder?: MessageFolder | string | null; | ||
| 391 | label: string | null; | 392 | label: string | null; |
| 392 | }; | 393 | }; |
| 393 | 394 | ||
src/components/messages/gmail-compose-box.tsxadded+203 -0
| @@ -0,0 +1,203 @@ | |||
| 1 | +import { createSignal, createEffect, Show } from "solid-js"; | ||
| 2 | +import { Button } from "@/components/ui/button"; | ||
| 3 | +import { Input } from "@/components/ui/input"; | ||
| 4 | +import { RichTextEditor } from "@/components/ui/rich-text-editor"; | ||
| 5 | +import { UserSearchSelect } from "@/components/users/user-search-select"; | ||
| 6 | +import { IconSend, IconTrash, IconX } from "@/components/ui/icons"; | ||
| 7 | +import { postMessage } from "@/api/messages"; | ||
| 8 | +import { formatApiError } from "@/api/client"; | ||
| 9 | +import { useAuth } from "@/stores/auth-context"; | ||
| 10 | +import { useT } from "@/stores/preferences-context"; | ||
| 11 | + | ||
| 12 | +interface GmailComposeBoxProps { | ||
| 13 | + open: boolean; | ||
| 14 | + onClose: () => void; | ||
| 15 | + onSuccess: () => void; | ||
| 16 | + initialRecipient?: string; | ||
| 17 | + initialSubject?: string; | ||
| 18 | + initialBody?: string; | ||
| 19 | +} | ||
| 20 | + | ||
| 21 | +export function GmailComposeBox(props: GmailComposeBoxProps) { | ||
| 22 | + const t = useT(); | ||
| 23 | + const auth = useAuth(); | ||
| 24 | + const [recipient, setRecipient] = createSignal(""); | ||
| 25 | + const [subject, setSubject] = createSignal(""); | ||
| 26 | + const [body, setBody] = createSignal(""); | ||
| 27 | + const [label, setLabel] = createSignal(""); | ||
| 28 | + const [isMinimized, setIsMinimized] = createSignal(false); | ||
| 29 | + const [pending, setPending] = createSignal(false); | ||
| 30 | + const [error, setError] = createSignal(""); | ||
| 31 | + | ||
| 32 | + createEffect(() => { | ||
| 33 | + if (props.open) { | ||
| 34 | + setRecipient(props.initialRecipient ?? ""); | ||
| 35 | + setSubject(props.initialSubject ?? ""); | ||
| 36 | + setBody(props.initialBody ?? ""); | ||
| 37 | + setLabel(""); | ||
| 38 | + setIsMinimized(false); | ||
| 39 | + setError(""); | ||
| 40 | + } | ||
| 41 | + }); | ||
| 42 | + | ||
| 43 | + const reset = () => { | ||
| 44 | + setRecipient(""); | ||
| 45 | + setSubject(""); | ||
| 46 | + setBody(""); | ||
| 47 | + setLabel(""); | ||
| 48 | + setError(""); | ||
| 49 | + }; | ||
| 50 | + | ||
| 51 | + const handleClose = () => { | ||
| 52 | + reset(); | ||
| 53 | + props.onClose(); | ||
| 54 | + }; | ||
| 55 | + | ||
| 56 | + const handleSend = async (e: SubmitEvent) => { | ||
| 57 | + e.preventDefault(); | ||
| 58 | + if (!recipient()) { | ||
| 59 | + setError(t("messages.selectRecipient")); | ||
| 60 | + return; | ||
| 61 | + } | ||
| 62 | + setError(""); | ||
| 63 | + setPending(true); | ||
| 64 | + | ||
| 65 | + try { | ||
| 66 | + await postMessage({ | ||
| 67 | + recipient_id: recipient(), | ||
| 68 | + subject: subject().trim(), | ||
| 69 | + body: body().trim() || undefined, | ||
| 70 | + label: label().trim() || undefined, | ||
| 71 | + }); | ||
| 72 | + props.onSuccess(); | ||
| 73 | + handleClose(); | ||
| 74 | + } catch (err) { | ||
| 75 | + setError(formatApiError(err)); | ||
| 76 | + } finally { | ||
| 77 | + setPending(false); | ||
| 78 | + } | ||
| 79 | + }; | ||
| 80 | + | ||
| 81 | + return ( | ||
| 82 | + <Show when={props.open}> | ||
| 83 | + <div | ||
| 84 | + class="fixed bottom-0 right-2 sm:right-6 z-50 w-[calc(100vw-1rem)] sm:w-[560px] rounded-t-2xl border border-border/80 bg-card shadow-2xl transition-all duration-200" | ||
| 85 | + style={{ "max-height": isMinimized() ? "44px" : "640px" }} | ||
| 86 | + > | ||
| 87 | + {/* Gmail Header */} | ||
| 88 | + <div class="flex h-11 items-center justify-between border-b bg-muted/80 px-4 rounded-t-2xl"> | ||
| 89 | + <div class="flex items-center gap-2"> | ||
| 90 | + <span class="h-2.5 w-2.5 rounded-full bg-primary" /> | ||
| 91 | + <h3 class="text-xs font-bold text-foreground truncate max-w-[340px]"> | ||
| 92 | + {subject() ? subject() : t("messages.newMessage")} | ||
| 93 | + </h3> | ||
| 94 | + </div> | ||
| 95 | + <div class="flex items-center gap-1"> | ||
| 96 | + <button | ||
| 97 | + type="button" | ||
| 98 | + class="flex h-7 w-7 items-center justify-center rounded-lg text-muted-foreground hover:bg-muted hover:text-foreground" | ||
| 99 | + onClick={() => setIsMinimized(!isMinimized())} | ||
| 100 | + title={isMinimized() ? "Genişlet" : "Simge durumuna küçült"} | ||
| 101 | + > | ||
| 102 | + <span class="text-xs font-bold">{isMinimized() ? "□" : "—"}</span> | ||
| 103 | + </button> | ||
| 104 | + <button | ||
| 105 | + type="button" | ||
| 106 | + class="flex h-7 w-7 items-center justify-center rounded-lg text-muted-foreground hover:bg-destructive/10 hover:text-destructive" | ||
| 107 | + onClick={handleClose} | ||
| 108 | + title={t("common.cancel")} | ||
| 109 | + > | ||
| 110 | + <IconX class="h-4 w-4" /> | ||
| 111 | + </button> | ||
| 112 | + </div> | ||
| 113 | + </div> | ||
| 114 | + | ||
| 115 | + {/* Gmail Form Content */} | ||
| 116 | + <Show when={!isMinimized()}> | ||
| 117 | + <form class="flex flex-col h-[520px]" onSubmit={handleSend}> | ||
| 118 | + {/* Recipient Line */} | ||
| 119 | + <div class="flex items-center border-b px-3 py-1.5 gap-2 text-xs"> | ||
| 120 | + <span class="w-12 font-medium text-muted-foreground shrink-0"> | ||
| 121 | + {t("messages.recipient")}: | ||
| 122 | + </span> | ||
| 123 | + <div class="flex-1 min-w-0"> | ||
| 124 | + <UserSearchSelect | ||
| 125 | + id="gmail-compose-recipient" | ||
| 126 | + value={recipient()} | ||
| 127 | + onChange={setRecipient} | ||
| 128 | + placeholder={t("messages.recipientPlaceholder")} | ||
| 129 | + excludeIds={auth.user()?.id ? [auth.user()!.id] : []} | ||
| 130 | + /> | ||
| 131 | + </div> | ||
| 132 | + </div> | ||
| 133 | + | ||
| 134 | + {/* Subject Line */} | ||
| 135 | + <div class="flex items-center border-b px-3 py-1 gap-2 text-xs"> | ||
| 136 | + <span class="w-12 font-medium text-muted-foreground shrink-0"> | ||
| 137 | + {t("form.title")}: | ||
| 138 | + </span> | ||
| 139 | + <Input | ||
| 140 | + required | ||
| 141 | + maxlength={200} | ||
| 142 | + placeholder="Konu" | ||
| 143 | + class="h-8 border-none bg-transparent shadow-none focus-visible:ring-0 text-xs flex-1" | ||
| 144 | + value={subject()} | ||
| 145 | + onInput={(e) => setSubject(e.currentTarget.value)} | ||
| 146 | + /> | ||
| 147 | + </div> | ||
| 148 | + | ||
| 149 | + {/* Optional Label Tag Line */} | ||
| 150 | + <div class="flex items-center border-b px-3 py-1 gap-2 text-xs"> | ||
| 151 | + <span class="w-12 font-medium text-muted-foreground shrink-0"> | ||
| 152 | + Etiket: | ||
| 153 | + </span> | ||
| 154 | + <Input | ||
| 155 | + maxlength={50} | ||
| 156 | + placeholder="ör. Etüt, Sınav (Opsiyonel)" | ||
| 157 | + class="h-8 border-none bg-transparent shadow-none focus-visible:ring-0 text-xs flex-1" | ||
| 158 | + value={label()} | ||
| 159 | + onInput={(e) => setLabel(e.currentTarget.value)} | ||
| 160 | + /> | ||
| 161 | + </div> | ||
| 162 | + | ||
| 163 | + {/* Gmail Rich Text Editor Area */} | ||
| 164 | + <div class="flex-1 p-2.5 flex flex-col min-h-0"> | ||
| 165 | + <RichTextEditor | ||
| 166 | + value={body()} | ||
| 167 | + onChange={setBody} | ||
| 168 | + placeholder="Mesajınızı buraya yazın..." | ||
| 169 | + class="flex-1 min-h-0" | ||
| 170 | + /> | ||
| 171 | + </div> | ||
| 172 | + | ||
| 173 | + <Show when={error()}> | ||
| 174 | + <p class="px-3 text-xs font-medium text-destructive">{error()}</p> | ||
| 175 | + </Show> | ||
| 176 | + | ||
| 177 | + {/* Gmail Bottom Action Toolbar */} | ||
| 178 | + <div class="flex items-center justify-between border-t bg-muted/30 px-3 py-2.5"> | ||
| 179 | + <Button | ||
| 180 | + type="submit" | ||
| 181 | + size="sm" | ||
| 182 | + class="rounded-xl px-5 h-9 bg-primary font-semibold text-primary-foreground shadow-xs hover:bg-primary/90" | ||
| 183 | + disabled={pending()} | ||
| 184 | + > | ||
| 185 | + <IconSend class="mr-2 h-4 w-4" /> | ||
| 186 | + {t("messages.send")} | ||
| 187 | + </Button> | ||
| 188 | + | ||
| 189 | + <button | ||
| 190 | + type="button" | ||
| 191 | + class="flex h-8 w-8 items-center justify-center rounded-lg text-muted-foreground hover:bg-destructive/10 hover:text-destructive transition-colors" | ||
| 192 | + onClick={handleClose} | ||
| 193 | + title="Taslağı Sil" | ||
| 194 | + > | ||
| 195 | + <IconTrash class="h-4 w-4" /> | ||
| 196 | + </button> | ||
| 197 | + </div> | ||
| 198 | + </form> | ||
| 199 | + </Show> | ||
| 200 | + </div> | ||
| 201 | + </Show> | ||
| 202 | + ); | ||
| 203 | +} | ||
src/components/messages/gmail-mail-detail.tsxadded+317 -0
| @@ -0,0 +1,317 @@ | |||
| 1 | +import { createSignal, Show } from "solid-js"; | ||
| 2 | +import type { Message, MessageFolder } from "@/api/client"; | ||
| 3 | +import { Badge } from "@/components/ui/badge"; | ||
| 4 | +import { Button } from "@/components/ui/button"; | ||
| 5 | +import { RichTextEditor } from "@/components/ui/rich-text-editor"; | ||
| 6 | +import { IconSend, IconTrash, IconMessage, IconArchive, IconChevronLeft } from "@/components/ui/icons"; | ||
| 7 | +import { postMessage } from "@/api/messages"; | ||
| 8 | +import { formatApiError } from "@/api/client"; | ||
| 9 | +import { personLabel } from "@/lib/person"; | ||
| 10 | +import { useT } from "@/stores/preferences-context"; | ||
| 11 | + | ||
| 12 | +interface GmailMailDetailProps { | ||
| 13 | + message: Message; | ||
| 14 | + currentUserId?: string; | ||
| 15 | + folder: string; | ||
| 16 | + onBack: () => void; | ||
| 17 | + onAction: (action: { folder?: MessageFolder; delete?: boolean }) => Promise<void>; | ||
| 18 | + onSuccess: () => void; | ||
| 19 | + setFlash: (text: string) => void; | ||
| 20 | +} | ||
| 21 | + | ||
| 22 | +export function GmailMailDetail(props: GmailMailDetailProps) { | ||
| 23 | + const t = useT(); | ||
| 24 | + const [isReplying, setIsReplying] = createSignal(false); | ||
| 25 | + const [replyBody, setReplyBody] = createSignal(""); | ||
| 26 | + const [sending, setSending] = createSignal(false); | ||
| 27 | + const [error, setError] = createSignal(""); | ||
| 28 | + | ||
| 29 | + const isSent = () => props.folder === "sent" || props.message.sender.id === props.currentUserId; | ||
| 30 | + const peer = () => (isSent() ? props.message.recipient : props.message.sender); | ||
| 31 | + const peerName = () => personLabel(peer()); | ||
| 32 | + const role = () => (isSent() ? props.message.recipient_role : props.message.sender_role); | ||
| 33 | + | ||
| 34 | + const restoreFolder = (): MessageFolder => { | ||
| 35 | + if (props.message.previous_folder && (props.message.previous_folder as string) !== "deleted") { | ||
| 36 | + return props.message.previous_folder as MessageFolder; | ||
| 37 | + } | ||
| 38 | + return isSent() ? "sent" : "inbox"; | ||
| 39 | + }; | ||
| 40 | + | ||
| 41 | + const formattedDate = (ts: number) => { | ||
| 42 | + const date = new Date(ts); | ||
| 43 | + return date.toLocaleString([], { | ||
| 44 | + year: "numeric", | ||
| 45 | + month: "long", | ||
| 46 | + day: "numeric", | ||
| 47 | + hour: "2-digit", | ||
| 48 | + minute: "2-digit", | ||
| 49 | + }); | ||
| 50 | + }; | ||
| 51 | + | ||
| 52 | + const handleStartReply = () => { | ||
| 53 | + setIsReplying(true); | ||
| 54 | + setReplyBody(""); | ||
| 55 | + setError(""); | ||
| 56 | + }; | ||
| 57 | + | ||
| 58 | + const handleSendReply = async (e: Event) => { | ||
| 59 | + e.preventDefault(); | ||
| 60 | + const content = replyBody().trim(); | ||
| 61 | + if (!content || sending()) return; | ||
| 62 | + | ||
| 63 | + setError(""); | ||
| 64 | + setSending(true); | ||
| 65 | + | ||
| 66 | + try { | ||
| 67 | + const replySubject = props.message.subject.startsWith("Re:") | ||
| 68 | + ? props.message.subject | ||
| 69 | + : `Re: ${props.message.subject}`; | ||
| 70 | + | ||
| 71 | + await postMessage({ | ||
| 72 | + recipient_id: peer().id, | ||
| 73 | + subject: replySubject, | ||
| 74 | + body: content, | ||
| 75 | + }); | ||
| 76 | + | ||
| 77 | + props.setFlash(t("messages.sentToast")); | ||
| 78 | + setIsReplying(false); | ||
| 79 | + setReplyBody(""); | ||
| 80 | + props.onSuccess(); | ||
| 81 | + } catch (err: any) { | ||
| 82 | + setError(formatApiError(err)); | ||
| 83 | + } finally { | ||
| 84 | + setSending(false); | ||
| 85 | + } | ||
| 86 | + }; | ||
| 87 | + | ||
| 88 | + return ( | ||
| 89 | + <div class="flex flex-col h-full bg-background overflow-auto"> | ||
| 90 | + {/* Top Gmail Navigation & Action Bar */} | ||
| 91 | + <div class="sticky top-0 z-10 flex items-center justify-between border-b bg-card/90 px-4 py-2.5 backdrop-blur-xs"> | ||
| 92 | + <div class="flex items-center gap-2"> | ||
| 93 | + <Button | ||
| 94 | + variant="ghost" | ||
| 95 | + size="sm" | ||
| 96 | + class="h-8 rounded-lg text-xs" | ||
| 97 | + onClick={props.onBack} | ||
| 98 | + > | ||
| 99 | + <IconChevronLeft class="mr-1 h-4 w-4" /> | ||
| 100 | + Gelen Kutusu | ||
| 101 | + </Button> | ||
| 102 | + | ||
| 103 | + <div class="h-4 w-[1px] bg-border mx-1" /> | ||
| 104 | + | ||
| 105 | + {/* Move to Archive Action */} | ||
| 106 | + <Show when={!isSent() && props.folder !== "archive" && props.folder !== "trash"}> | ||
| 107 | + <Button | ||
| 108 | + variant="ghost" | ||
| 109 | + size="sm" | ||
| 110 | + class="h-8 rounded-lg text-xs" | ||
| 111 | + onClick={() => props.onAction({ folder: "archive" })} | ||
| 112 | + title={t("messages.moveToArchive")} | ||
| 113 | + > | ||
| 114 | + <IconArchive class="mr-1.5 h-3.5 w-3.5" /> | ||
| 115 | + {t("messages.moveToArchive")} | ||
| 116 | + </Button> | ||
| 117 | + </Show> | ||
| 118 | + | ||
| 119 | + {/* Restore out of Archive */} | ||
| 120 | + <Show when={props.folder === "archive"}> | ||
| 121 | + <Button | ||
| 122 | + variant="ghost" | ||
| 123 | + size="sm" | ||
| 124 | + class="h-8 rounded-lg text-xs" | ||
| 125 | + onClick={() => props.onAction({ folder: restoreFolder() })} | ||
| 126 | + title={t("messages.moveOutOfArchive")} | ||
| 127 | + > | ||
| 128 | + <IconArchive class="mr-1.5 h-3.5 w-3.5" /> | ||
| 129 | + {t("messages.moveOutOfArchive")} | ||
| 130 | + </Button> | ||
| 131 | + </Show> | ||
| 132 | + | ||
| 133 | + {/* Restore out of Trash */} | ||
| 134 | + <Show when={props.folder === "trash"}> | ||
| 135 | + <Button | ||
| 136 | + variant="ghost" | ||
| 137 | + size="sm" | ||
| 138 | + class="h-8 rounded-lg text-xs" | ||
| 139 | + onClick={() => props.onAction({ folder: restoreFolder() })} | ||
| 140 | + title="Çöp Kutusundan Çıkar" | ||
| 141 | + > | ||
| 142 | + <IconMessage class="mr-1.5 h-3.5 w-3.5" /> | ||
| 143 | + Çöp Kutusundan Çıkar | ||
| 144 | + </Button> | ||
| 145 | + </Show> | ||
| 146 | + | ||
| 147 | + {/* Move to Trash Action */} | ||
| 148 | + <Show when={props.folder !== "trash"}> | ||
| 149 | + <Button | ||
| 150 | + variant="ghost" | ||
| 151 | + size="sm" | ||
| 152 | + class="h-8 rounded-lg text-xs text-destructive hover:bg-destructive/10" | ||
| 153 | + onClick={() => props.onAction({ folder: "trash" })} | ||
| 154 | + title={t("messages.moveToTrash")} | ||
| 155 | + > | ||
| 156 | + <IconTrash class="mr-1.5 h-3.5 w-3.5" /> | ||
| 157 | + {t("messages.moveToTrash")} | ||
| 158 | + </Button> | ||
| 159 | + </Show> | ||
| 160 | + | ||
| 161 | + {/* Permanent Delete Action */} | ||
| 162 | + <Show when={props.folder === "trash"}> | ||
| 163 | + <Button | ||
| 164 | + variant="ghost" | ||
| 165 | + size="sm" | ||
| 166 | + class="h-8 rounded-lg text-xs text-destructive hover:bg-destructive/10" | ||
| 167 | + onClick={() => props.onAction({ delete: true })} | ||
| 168 | + title={t("messages.deleteForever")} | ||
| 169 | + > | ||
| 170 | + <IconTrash class="mr-1.5 h-3.5 w-3.5" /> | ||
| 171 | + {t("messages.deleteForever")} | ||
| 172 | + </Button> | ||
| 173 | + </Show> | ||
| 174 | + </div> | ||
| 175 | + | ||
| 176 | + <div class="flex items-center gap-2 text-xs text-muted-foreground font-mono"> | ||
| 177 | + <span>{formattedDate(props.message.sent_at)}</span> | ||
| 178 | + </div> | ||
| 179 | + </div> | ||
| 180 | + | ||
| 181 | + {/* Main Mail Content View Container */} | ||
| 182 | + <div class="flex-1 p-4 sm:p-6 max-w-4xl mx-auto w-full space-y-6"> | ||
| 183 | + {/* Email Subject Title Header */} | ||
| 184 | + <div class="flex items-center justify-between gap-3 border-b pb-4"> | ||
| 185 | + <div class="flex items-center gap-3"> | ||
| 186 | + <h1 class="text-xl font-bold tracking-tight text-foreground"> | ||
| 187 | + {props.message.subject} | ||
| 188 | + </h1> | ||
| 189 | + <Show when={props.message.label}> | ||
| 190 | + <Badge variant="secondary" class="text-xs"> | ||
| 191 | + {props.message.label} | ||
| 192 | + </Badge> | ||
| 193 | + </Show> | ||
| 194 | + </div> | ||
| 195 | + </div> | ||
| 196 | + | ||
| 197 | + {/* Sender Info Card */} | ||
| 198 | + <div class="flex items-start justify-between gap-4"> | ||
| 199 | + <div class="flex items-center gap-3 min-w-0"> | ||
| 200 | + <div class="flex h-10 w-10 shrink-0 items-center justify-center rounded-full bg-primary font-bold text-sm text-primary-foreground shadow-xs"> | ||
| 201 | + {peerName().charAt(0).toUpperCase()} | ||
| 202 | + </div> | ||
| 203 | + <div class="min-w-0"> | ||
| 204 | + <div class="flex items-center gap-2"> | ||
| 205 | + <span class="font-bold text-sm text-foreground"> | ||
| 206 | + {peerName()} | ||
| 207 | + </span> | ||
| 208 | + <Show when={role()}> | ||
| 209 | + <Badge variant="outline" class="text-[9px] font-mono uppercase"> | ||
| 210 | + {t(`role.${role()}` as any)} | ||
| 211 | + </Badge> | ||
| 212 | + </Show> | ||
| 213 | + </div> | ||
| 214 | + <p class="text-xs text-muted-foreground"> | ||
| 215 | + {isSent() ? `${t("messages.to")}: ` : `${t("messages.from")}: `} | ||
| 216 | + <span class="font-medium text-foreground">{peerName()}</span> | ||
| 217 | + </p> | ||
| 218 | + </div> | ||
| 219 | + </div> | ||
| 220 | + | ||
| 221 | + <Show when={!isSent()}> | ||
| 222 | + <Button | ||
| 223 | + variant="outline" | ||
| 224 | + size="sm" | ||
| 225 | + class="h-8 rounded-lg text-xs" | ||
| 226 | + onClick={handleStartReply} | ||
| 227 | + > | ||
| 228 | + <IconMessage class="mr-1.5 h-3.5 w-3.5" /> | ||
| 229 | + Yanıtla | ||
| 230 | + </Button> | ||
| 231 | + </Show> | ||
| 232 | + </div> | ||
| 233 | + | ||
| 234 | + {/* Email Body Card */} | ||
| 235 | + <div class="rounded-2xl border border-border/80 bg-card p-6 shadow-xs leading-relaxed text-sm text-foreground/90 whitespace-pre-wrap min-h-[140px]"> | ||
| 236 | + <div innerHTML={props.message.body} /> | ||
| 237 | + </div> | ||
| 238 | + | ||
| 239 | + {/* Gmail Style Inline Reply Area */} | ||
| 240 | + <Show when={!isSent()}> | ||
| 241 | + <div class="pt-4 border-t"> | ||
| 242 | + <Show | ||
| 243 | + when={isReplying()} | ||
| 244 | + fallback={ | ||
| 245 | + /* Gmail Quick Action Pills */ | ||
| 246 | + <div class="flex items-center gap-3"> | ||
| 247 | + <Button | ||
| 248 | + variant="outline" | ||
| 249 | + class="rounded-xl px-5 h-9 text-xs font-semibold hover:bg-accent" | ||
| 250 | + onClick={handleStartReply} | ||
| 251 | + > | ||
| 252 | + <IconMessage class="mr-2 h-4 w-4" /> | ||
| 253 | + Yanıtla | ||
| 254 | + </Button> | ||
| 255 | + </div> | ||
| 256 | + } | ||
| 257 | + > | ||
| 258 | + {/* Gmail Inline Reply Editor */} | ||
| 259 | + <form | ||
| 260 | + onSubmit={handleSendReply} | ||
| 261 | + class="rounded-2xl border border-border bg-card p-4 shadow-sm space-y-3" | ||
| 262 | + > | ||
| 263 | + <div class="flex items-center justify-between text-xs border-b pb-2"> | ||
| 264 | + <div class="flex items-center gap-2"> | ||
| 265 | + <span class="font-bold text-foreground">Yanıtla:</span> | ||
| 266 | + <Badge variant="secondary" class="text-xs font-medium"> | ||
| 267 | + {peerName()} | ||
| 268 | + </Badge> | ||
| 269 | + </div> | ||
| 270 | + <button | ||
| 271 | + type="button" | ||
| 272 | + class="text-xs text-muted-foreground hover:text-foreground" | ||
| 273 | + onClick={() => setIsReplying(false)} | ||
| 274 | + > | ||
| 275 | + Vazgeç | ||
| 276 | + </button> | ||
| 277 | + </div> | ||
| 278 | + | ||
| 279 | + <RichTextEditor | ||
| 280 | + value={replyBody()} | ||
| 281 | + onChange={setReplyBody} | ||
| 282 | + placeholder="Yanıtınızı yazın..." | ||
| 283 | + minHeight="min-h-[120px]" | ||
| 284 | + /> | ||
| 285 | + | ||
| 286 | + <Show when={error()}> | ||
| 287 | + <p class="text-xs font-medium text-destructive">{error()}</p> | ||
| 288 | + </Show> | ||
| 289 | + | ||
| 290 | + <div class="flex items-center justify-between pt-1"> | ||
| 291 | + <Button | ||
| 292 | + type="submit" | ||
| 293 | + size="sm" | ||
| 294 | + class="rounded-xl px-5 h-9 bg-primary font-semibold text-primary-foreground shadow-xs hover:bg-primary/90" | ||
| 295 | + disabled={sending() || !replyBody().trim()} | ||
| 296 | + > | ||
| 297 | + <IconSend class="mr-2 h-4 w-4" /> | ||
| 298 | + Gönder | ||
| 299 | + </Button> | ||
| 300 | + | ||
| 301 | + <button | ||
| 302 | + type="button" | ||
| 303 | + class="flex h-8 w-8 items-center justify-center rounded-lg text-muted-foreground hover:bg-destructive/10 hover:text-destructive" | ||
| 304 | + onClick={() => setIsReplying(false)} | ||
| 305 | + title="Vazgeç" | ||
| 306 | + > | ||
| 307 | + <IconTrash class="h-4 w-4" /> | ||
| 308 | + </button> | ||
| 309 | + </div> | ||
| 310 | + </form> | ||
| 311 | + </Show> | ||
| 312 | + </div> | ||
| 313 | + </Show> | ||
| 314 | + </div> | ||
| 315 | + </div> | ||
| 316 | + ); | ||
| 317 | +} | ||
src/components/messages/gmail-mail-row.tsxadded+145 -0
| @@ -0,0 +1,145 @@ | |||
| 1 | +import { Show } from "solid-js"; | ||
| 2 | +import type { Message } from "@/api/client"; | ||
| 3 | +import { Badge } from "@/components/ui/badge"; | ||
| 4 | +import { IconArchive, IconTrash, IconMessage } from "@/components/ui/icons"; | ||
| 5 | +import { cn } from "@/lib/cn"; | ||
| 6 | +import { personLabel } from "@/lib/person"; | ||
| 7 | +import { useT } from "@/stores/preferences-context"; | ||
| 8 | + | ||
| 9 | +interface GmailMailRowProps { | ||
| 10 | + message: Message; | ||
| 11 | + currentUserId?: string; | ||
| 12 | + folder: string; | ||
| 13 | + isSelected: boolean; | ||
| 14 | + onSelect: () => void; | ||
| 15 | + onArchive?: () => void; | ||
| 16 | + onTrash?: () => void; | ||
| 17 | + onToggleRead?: () => void; | ||
| 18 | +} | ||
| 19 | + | ||
| 20 | +export function GmailMailRow(props: GmailMailRowProps) { | ||
| 21 | + const t = useT(); | ||
| 22 | + | ||
| 23 | + const isSent = () => props.folder === "sent" || props.message.sender.id === props.currentUserId; | ||
| 24 | + const peer = () => (isSent() ? props.message.recipient : props.message.sender); | ||
| 25 | + const peerName = () => personLabel(peer()); | ||
| 26 | + const role = () => (isSent() ? props.message.recipient_role : props.message.sender_role); | ||
| 27 | + const unread = () => !isSent() && !props.message.read; | ||
| 28 | + | ||
| 29 | + const formattedTime = (ts: number) => { | ||
| 30 | + const date = new Date(ts); | ||
| 31 | + const now = new Date(); | ||
| 32 | + const isToday = | ||
| 33 | + date.getDate() === now.getDate() && | ||
| 34 | + date.getMonth() === now.getMonth() && | ||
| 35 | + date.getFullYear() === now.getFullYear(); | ||
| 36 | + | ||
| 37 | + if (isToday) { | ||
| 38 | + return date.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" }); | ||
| 39 | + } | ||
| 40 | + return date.toLocaleDateString([], { month: "short", day: "numeric" }); | ||
| 41 | + }; | ||
| 42 | + | ||
| 43 | + return ( | ||
| 44 | + <div | ||
| 45 | + class={cn( | ||
| 46 | + "group relative flex h-10 items-center gap-3 border-b border-border/60 border-l-4 px-4 py-0 text-xs transition-colors duration-150 cursor-pointer select-none shrink-0", | ||
| 47 | + unread() ? "border-l-primary bg-card font-semibold text-foreground hover:bg-accent/40" : "border-l-transparent bg-background/60 text-muted-foreground hover:bg-muted/50", | ||
| 48 | + props.isSelected && "bg-accent/80 text-foreground" | ||
| 49 | + )} | ||
| 50 | + onClick={props.onSelect} | ||
| 51 | + > | ||
| 52 | + {/* Sender / Peer Name */} | ||
| 53 | + <div class="flex items-center gap-2 w-48 shrink-0 min-w-0"> | ||
| 54 | + <span | ||
| 55 | + class={cn( | ||
| 56 | + "truncate text-xs tracking-tight", | ||
| 57 | + unread() ? "font-bold text-foreground" : "font-medium text-foreground/90" | ||
| 58 | + )} | ||
| 59 | + > | ||
| 60 | + {isSent() ? `${t("messages.to")}${peerName()}` : peerName()} | ||
| 61 | + </span> | ||
| 62 | + <Show when={role()}> | ||
| 63 | + <span class="shrink-0 text-[9px] uppercase font-mono px-1 py-0.2 rounded bg-muted text-muted-foreground border border-border/50"> | ||
| 64 | + {t(`role.${role()}` as any)} | ||
| 65 | + </span> | ||
| 66 | + </Show> | ||
| 67 | + </div> | ||
| 68 | + | ||
| 69 | + {/* Subject + Body Snippet (Gmail Single Line) */} | ||
| 70 | + <div class="min-w-0 flex-1 flex items-center gap-2 truncate"> | ||
| 71 | + <span | ||
| 72 | + class={cn( | ||
| 73 | + "truncate shrink-0 max-w-[40%]", | ||
| 74 | + unread() ? "font-bold text-foreground" : "font-semibold text-foreground/90" | ||
| 75 | + )} | ||
| 76 | + > | ||
| 77 | + {props.message.subject} | ||
| 78 | + </span> | ||
| 79 | + <span class="text-muted-foreground/70 truncate text-[11px]"> | ||
| 80 | + — {props.message.body.replace(/<[^>]*>?/gm, "").trim()} | ||
| 81 | + </span> | ||
| 82 | + </div> | ||
| 83 | + | ||
| 84 | + {/* Optional Tag Label */} | ||
| 85 | + <Show when={props.message.label}> | ||
| 86 | + <Badge variant="outline" class="text-[9px] h-4 px-1.5 py-0 font-medium shrink-0"> | ||
| 87 | + {props.message.label} | ||
| 88 | + </Badge> | ||
| 89 | + </Show> | ||
| 90 | + | ||
| 91 | + {/* Fixed-width & Fixed-height Right Action Area */} | ||
| 92 | + <div class="shrink-0 w-24 h-full flex items-center justify-end"> | ||
| 93 | + {/* Time / Date (Default View) */} | ||
| 94 | + <div class="font-mono text-[11px] text-muted-foreground text-right group-hover:hidden"> | ||
| 95 | + {formattedTime(props.message.sent_at)} | ||
| 96 | + </div> | ||
| 97 | + | ||
| 98 | + {/* Gmail Hover Quick Action Bar (Hover View - Fixed h-6 buttons to fit h-10 row cleanly) */} | ||
| 99 | + <div class="hidden items-center justify-end gap-1 group-hover:flex"> | ||
| 100 | + <Show when={props.onArchive}> | ||
| 101 | + <button | ||
| 102 | + type="button" | ||
| 103 | + class="flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:bg-accent hover:text-foreground transition-colors" | ||
| 104 | + title={props.folder === "archive" ? t("messages.moveOutOfArchive") : t("messages.moveToArchive")} | ||
| 105 | + onClick={(e) => { | ||
| 106 | + e.stopPropagation(); | ||
| 107 | + props.onArchive?.(); | ||
| 108 | + }} | ||
| 109 | + > | ||
| 110 | + <IconArchive class="h-3.5 w-3.5" /> | ||
| 111 | + </button> | ||
| 112 | + </Show> | ||
| 113 | + | ||
| 114 | + <Show when={props.onTrash}> | ||
| 115 | + <button | ||
| 116 | + type="button" | ||
| 117 | + class="flex h-6 w-6 items-center justify-center rounded-lg text-muted-foreground hover:bg-destructive/10 hover:text-destructive transition-colors" | ||
| 118 | + title={props.folder === "trash" ? "Çöp Kutusundan Çıkar" : t("messages.moveToTrash")} | ||
| 119 | + onClick={(e) => { | ||
| 120 | + e.stopPropagation(); | ||
| 121 | + props.onTrash?.(); | ||
| 122 | + }} | ||
| 123 | + > | ||
| 124 | + <IconTrash class="h-3.5 w-3.5" /> | ||
| 125 | + </button> | ||
| 126 | + </Show> | ||
| 127 | + | ||
| 128 | + <Show when={props.onToggleRead}> | ||
| 129 | + <button | ||
| 130 | + type="button" | ||
| 131 | + class="flex h-6 w-6 items-center justify-center rounded-lg text-muted-foreground hover:bg-accent hover:text-foreground transition-colors" | ||
| 132 | + title={unread() ? "Okundu olarak işaretle" : "Okunmadı olarak işaretle"} | ||
| 133 | + onClick={(e) => { | ||
| 134 | + e.stopPropagation(); | ||
| 135 | + props.onToggleRead?.(); | ||
| 136 | + }} | ||
| 137 | + > | ||
| 138 | + <IconMessage class="h-3.5 w-3.5" /> | ||
| 139 | + </button> | ||
| 140 | + </Show> | ||
| 141 | + </div> | ||
| 142 | + </div> | ||
| 143 | + </div> | ||
| 144 | + ); | ||
| 145 | +} | ||
src/components/messages/message-item-card.tsxadded+127 -0
| @@ -0,0 +1,127 @@ | |||
| 1 | +import { Show } from "solid-js"; | ||
| 2 | +import type { Message } from "@/api/client"; | ||
| 3 | +import { Badge } from "@/components/ui/badge"; | ||
| 4 | +import { cn } from "@/lib/cn"; | ||
| 5 | +import { personLabel } from "@/lib/person"; | ||
| 6 | +import { useT } from "@/stores/preferences-context"; | ||
| 7 | + | ||
| 8 | +interface MessageItemCardProps { | ||
| 9 | + message: Message; | ||
| 10 | + currentUserId?: string; | ||
| 11 | + folder: string; | ||
| 12 | + isSelected: boolean; | ||
| 13 | + onSelect: () => void; | ||
| 14 | +} | ||
| 15 | + | ||
| 16 | +export function MessageItemCard(props: MessageItemCardProps) { | ||
| 17 | + const t = useT(); | ||
| 18 | + | ||
| 19 | + const isSent = () => props.folder === "sent" || props.message.sender.id === props.currentUserId; | ||
| 20 | + const peer = () => (isSent() ? props.message.recipient : props.message.sender); | ||
| 21 | + const peerName = () => personLabel(peer()); | ||
| 22 | + const role = () => (isSent() ? props.message.recipient_role : props.message.sender_role); | ||
| 23 | + const unread = () => !isSent() && !props.message.read; | ||
| 24 | + | ||
| 25 | + const initial = () => { | ||
| 26 | + const name = peerName().trim(); | ||
| 27 | + return name.charAt(0).toUpperCase() || "?"; | ||
| 28 | + }; | ||
| 29 | + | ||
| 30 | + const formattedTime = (ts: number) => { | ||
| 31 | + const date = new Date(ts); | ||
| 32 | + const now = new Date(); | ||
| 33 | + const isToday = | ||
| 34 | + date.getDate() === now.getDate() && | ||
| 35 | + date.getMonth() === now.getMonth() && | ||
| 36 | + date.getFullYear() === now.getFullYear(); | ||
| 37 | + | ||
| 38 | + if (isToday) { | ||
| 39 | + return date.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" }); | ||
| 40 | + } | ||
| 41 | + return date.toLocaleDateString([], { month: "short", day: "numeric" }); | ||
| 42 | + }; | ||
| 43 | + | ||
| 44 | + return ( | ||
| 45 | + <button | ||
| 46 | + type="button" | ||
| 47 | + class={cn( | ||
| 48 | + "group relative flex w-full items-start gap-3 rounded-xl border p-3 text-left transition-colors duration-150", | ||
| 49 | + props.isSelected | ||
| 50 | + ? "border-primary/50 bg-accent/60 shadow-xs ring-1 ring-primary/20" | ||
| 51 | + : unread() | ||
| 52 | + ? "border-primary/30 bg-primary/[0.03] hover:border-primary/40 hover:bg-accent/40" | ||
| 53 | + : "border-border/60 bg-card hover:border-border hover:bg-muted/40" | ||
| 54 | + )} | ||
| 55 | + onClick={props.onSelect} | ||
| 56 | + > | ||
| 57 | + {/* Avatar */} | ||
| 58 | + <div class="relative shrink-0"> | ||
| 59 | + <div | ||
| 60 | + class={cn( | ||
| 61 | + "flex h-10 w-10 items-center justify-center rounded-full font-bold text-xs shadow-xs", | ||
| 62 | + unread() | ||
| 63 | + ? "bg-primary text-primary-foreground font-extrabold" | ||
| 64 | + : "bg-muted text-muted-foreground border border-border" | ||
| 65 | + )} | ||
| 66 | + > | ||
| 67 | + {initial()} | ||
| 68 | + </div> | ||
| 69 | + <Show when={unread()}> | ||
| 70 | + <span class="absolute -top-0.5 -right-0.5 h-3 w-3 rounded-full bg-primary ring-2 ring-background" /> | ||
| 71 | + </Show> | ||
| 72 | + </div> | ||
| 73 | + | ||
| 74 | + {/* Message Info */} | ||
| 75 | + <div class="min-w-0 flex-1 space-y-1"> | ||
| 76 | + <div class="flex items-center justify-between gap-2"> | ||
| 77 | + <div class="flex items-center gap-1.5 min-w-0"> | ||
| 78 | + <span | ||
| 79 | + class={cn( | ||
| 80 | + "truncate text-xs font-semibold tracking-tight", | ||
| 81 | + unread() ? "text-foreground font-bold" : "text-foreground/90" | ||
| 82 | + )} | ||
| 83 | + > | ||
| 84 | + {peerName()} | ||
| 85 | + </span> | ||
| 86 | + <Show when={role()}> | ||
| 87 | + <span class="shrink-0 text-[9px] uppercase font-mono px-1 py-0.2 rounded bg-muted text-muted-foreground border border-border/50"> | ||
| 88 | + {t(`role.${role()}` as any)} | ||
| 89 | + </span> | ||
| 90 | + </Show> | ||
| 91 | + </div> | ||
| 92 | + <span class="shrink-0 font-mono text-[10px] text-muted-foreground"> | ||
| 93 | + {formattedTime(props.message.sent_at)} | ||
| 94 | + </span> | ||
| 95 | + </div> | ||
| 96 | + | ||
| 97 | + <div class="flex items-center gap-1.5"> | ||
| 98 | + <Show when={isSent()}> | ||
| 99 | + <span class="text-[10px] font-medium text-muted-foreground shrink-0"> | ||
| 100 | + {t("messages.to")}: | ||
| 101 | + </span> | ||
| 102 | + </Show> | ||
| 103 | + <p | ||
| 104 | + class={cn( | ||
| 105 | + "truncate text-xs tracking-tight", | ||
| 106 | + unread() ? "font-bold text-foreground" : "font-medium text-foreground/80" | ||
| 107 | + )} | ||
| 108 | + > | ||
| 109 | + {props.message.subject} | ||
| 110 | + </p> | ||
| 111 | + </div> | ||
| 112 | + | ||
| 113 | + <p class="line-clamp-2 text-[11px] leading-relaxed text-muted-foreground/90"> | ||
| 114 | + {props.message.body} | ||
| 115 | + </p> | ||
| 116 | + | ||
| 117 | + <Show when={props.message.label}> | ||
| 118 | + <div class="pt-0.5"> | ||
| 119 | + <Badge variant="outline" class="text-[9px] h-4 px-1.5 py-0 font-medium"> | ||
| 120 | + {props.message.label} | ||
| 121 | + </Badge> | ||
| 122 | + </div> | ||
| 123 | + </Show> | ||
| 124 | + </div> | ||
| 125 | + </button> | ||
| 126 | + ); | ||
| 127 | +} | ||
src/components/messages/quick-reply-bar.tsxadded+80 -0
| @@ -0,0 +1,80 @@ | |||
| 1 | +import { createSignal, Show } from "solid-js"; | ||
| 2 | +import { Button } from "@/components/ui/button"; | ||
| 3 | +import { Textarea } from "@/components/ui/textarea"; | ||
| 4 | +import { IconSend } from "@/components/ui/icons"; | ||
| 5 | +import { useT } from "@/stores/preferences-context"; | ||
| 6 | + | ||
| 7 | +interface QuickReplyBarProps { | ||
| 8 | + recipientName: string; | ||
| 9 | + defaultSubject: string; | ||
| 10 | + onSend: (body: string, subject: string) => Promise<void>; | ||
| 11 | + disabled?: boolean; | ||
| 12 | +} | ||
| 13 | + | ||
| 14 | +export function QuickReplyBar(props: QuickReplyBarProps) { | ||
| 15 | + const t = useT(); | ||
| 16 | + const [body, setBody] = createSignal(""); | ||
| 17 | + const [sending, setSending] = createSignal(false); | ||
| 18 | + const [error, setError] = createSignal(""); | ||
| 19 | + | ||
| 20 | + const handleSend = async (e?: Event) => { | ||
| 21 | + if (e) e.preventDefault(); | ||
| 22 | + const content = body().trim(); | ||
| 23 | + if (!content || sending() || props.disabled) return; | ||
| 24 | + | ||
| 25 | + setError(""); | ||
| 26 | + setSending(true); | ||
| 27 | + | ||
| 28 | + try { | ||
| 29 | + const replySubject = props.defaultSubject.startsWith("Re:") | ||
| 30 | + ? props.defaultSubject | ||
| 31 | + : `Re: ${props.defaultSubject}`; | ||
| 32 | + | ||
| 33 | + await props.onSend(content, replySubject); | ||
| 34 | + setBody(""); | ||
| 35 | + } catch (err: any) { | ||
| 36 | + setError(err?.message || "Mesaj gönderilemedi"); | ||
| 37 | + } finally { | ||
| 38 | + setSending(false); | ||
| 39 | + } | ||
| 40 | + }; | ||
| 41 | + | ||
| 42 | + const handleKeyDown = (e: KeyboardEvent) => { | ||
| 43 | + if (e.key === "Enter" && !e.shiftKey) { | ||
| 44 | + e.preventDefault(); | ||
| 45 | + handleSend(); | ||
| 46 | + } | ||
| 47 | + }; | ||
| 48 | + | ||
| 49 | + return ( | ||
| 50 | + <div class="border-t bg-card/80 p-3 backdrop-blur-xs"> | ||
| 51 | + <form onSubmit={handleSend} class="space-y-2"> | ||
| 52 | + <Show when={error()}> | ||
| 53 | + <p class="text-xs font-medium text-destructive px-1">{error()}</p> | ||
| 54 | + </Show> | ||
| 55 | + <div class="flex items-end gap-2"> | ||
| 56 | + <div class="relative flex-1"> | ||
| 57 | + <Textarea | ||
| 58 | + value={body()} | ||
| 59 | + onInput={(e) => setBody(e.currentTarget.value)} | ||
| 60 | + onKeyDown={handleKeyDown} | ||
| 61 | + placeholder={`${props.recipientName} kişisine mesaj yanıtla... (Göndermek için Enter, yeni satır için Shift+Enter)`} | ||
| 62 | + rows={2} | ||
| 63 | + class="min-h-[2.5rem] max-h-32 resize-none rounded-xl bg-background text-sm py-2 px-3 focus-visible:ring-1" | ||
| 64 | + disabled={sending() || props.disabled} | ||
| 65 | + /> | ||
| 66 | + </div> | ||
| 67 | + <Button | ||
| 68 | + type="submit" | ||
| 69 | + size="sm" | ||
| 70 | + class="h-10 w-10 shrink-0 rounded-xl p-0" | ||
| 71 | + disabled={!body().trim() || sending() || props.disabled} | ||
| 72 | + title={t("messages.send")} | ||
| 73 | + > | ||
| 74 | + <IconSend class="h-4 w-4" /> | ||
| 75 | + </Button> | ||
| 76 | + </div> | ||
| 77 | + </form> | ||
| 78 | + </div> | ||
| 79 | + ); | ||
| 80 | +} | ||
src/components/ui/alert.tsxmodified+4 -4
| @@ -10,10 +10,10 @@ export function Alert( | |||
| 10 | <div | 10 | <div |
| 11 | role="alert" | 11 | role="alert" |
| 12 | class={cn( | 12 | class={cn( |
| 13 | - "relative w-full rounded-md border px-4 py-3 text-sm shadow-sm", | 13 | + "relative w-full rounded-lg border px-3.5 py-2.5 text-xs shadow-xs transition-all", |
| 14 | - local.variant === "destructive" && "border-destructive/30 bg-destructive/10 text-destructive", | 14 | + local.variant === "destructive" && "border-destructive/30 bg-destructive/10 text-destructive font-medium", |
| 15 | - local.variant === "success" && "fixed right-4 top-4 z-50 w-[calc(100vw-2rem)] max-w-sm border-emerald-600/30 bg-background text-emerald-800 shadow-lg dark:text-emerald-300 sm:right-6 sm:top-6", | 15 | + local.variant === "success" && "border-emerald-600/30 bg-emerald-500/10 text-emerald-800 dark:text-emerald-300 font-medium", |
| 16 | - (!local.variant || local.variant === "default") && "bg-background text-foreground", | 16 | + (!local.variant || local.variant === "default") && "bg-muted/40 text-foreground border-border/80", |
| 17 | local.class, | 17 | local.class, |
| 18 | )} | 18 | )} |
| 19 | {...rest} | 19 | {...rest} |
src/components/ui/rich-text-editor.tsxadded+143 -0
| @@ -0,0 +1,143 @@ | |||
| 1 | +import { createSignal, createEffect } from "solid-js"; | ||
| 2 | +import { cn } from "@/lib/cn"; | ||
| 3 | + | ||
| 4 | +interface RichTextEditorProps { | ||
| 5 | + value: string; | ||
| 6 | + onChange: (value: string) => void; | ||
| 7 | + placeholder?: string; | ||
| 8 | + class?: string; | ||
| 9 | + minHeight?: string; | ||
| 10 | +} | ||
| 11 | + | ||
| 12 | +export function RichTextEditor(props: RichTextEditorProps) { | ||
| 13 | + let editorRef: HTMLDivElement | undefined; | ||
| 14 | + const [isFocused, setIsFocused] = createSignal(false); | ||
| 15 | + | ||
| 16 | + // Sync value from props into editor when changed externally | ||
| 17 | + createEffect(() => { | ||
| 18 | + if (editorRef && editorRef.innerHTML !== props.value) { | ||
| 19 | + // If props value is empty string, clear innerHTML | ||
| 20 | + if (!props.value) { | ||
| 21 | + editorRef.innerHTML = ""; | ||
| 22 | + } else if (editorRef.innerHTML !== props.value) { | ||
| 23 | + editorRef.innerHTML = props.value; | ||
| 24 | + } | ||
| 25 | + } | ||
| 26 | + }); | ||
| 27 | + | ||
| 28 | + const handleInput = () => { | ||
| 29 | + if (editorRef) { | ||
| 30 | + const html = editorRef.innerHTML; | ||
| 31 | + // If editor contains empty tags like <br> or <p><br></p>, treat as empty | ||
| 32 | + if (html === "<br>" || html === "<p><br></p>" || editorRef.innerText.trim() === "") { | ||
| 33 | + props.onChange(""); | ||
| 34 | + } else { | ||
| 35 | + props.onChange(html); | ||
| 36 | + } | ||
| 37 | + } | ||
| 38 | + }; | ||
| 39 | + | ||
| 40 | + const execCommand = (command: string, value: string | undefined = undefined) => { | ||
| 41 | + if (!editorRef) return; | ||
| 42 | + editorRef.focus(); | ||
| 43 | + document.execCommand(command, false, value); | ||
| 44 | + handleInput(); | ||
| 45 | + }; | ||
| 46 | + | ||
| 47 | + return ( | ||
| 48 | + <div | ||
| 49 | + class={cn( | ||
| 50 | + "flex flex-col rounded-xl border border-border/80 bg-background overflow-hidden transition-all", | ||
| 51 | + isFocused() && "ring-1 ring-primary border-primary/60", | ||
| 52 | + props.class | ||
| 53 | + )} | ||
| 54 | + > | ||
| 55 | + {/* Gmail Style Rich Formatting Toolbar */} | ||
| 56 | + <div class="flex flex-wrap items-center gap-1 border-b bg-muted/40 px-2 py-1.5 text-xs select-none"> | ||
| 57 | + <button | ||
| 58 | + type="button" | ||
| 59 | + class="flex h-7 w-7 items-center justify-center rounded font-bold text-xs hover:bg-muted text-foreground" | ||
| 60 | + onClick={() => execCommand("bold")} | ||
| 61 | + title="Kalın (Ctrl+B)" | ||
| 62 | + > | ||
| 63 | + B | ||
| 64 | + </button> | ||
| 65 | + <button | ||
| 66 | + type="button" | ||
| 67 | + class="flex h-7 w-7 items-center justify-center rounded italic text-xs hover:bg-muted text-foreground" | ||
| 68 | + onClick={() => execCommand("italic")} | ||
| 69 | + title="İtalik (Ctrl+I)" | ||
| 70 | + > | ||
| 71 | + I | ||
| 72 | + </button> | ||
| 73 | + <button | ||
| 74 | + type="button" | ||
| 75 | + class="flex h-7 w-7 items-center justify-center rounded underline text-xs hover:bg-muted text-foreground" | ||
| 76 | + onClick={() => execCommand("underline")} | ||
| 77 | + title="Altı Çizili (Ctrl+U)" | ||
| 78 | + > | ||
| 79 | + U | ||
| 80 | + </button> | ||
| 81 | + <button | ||
| 82 | + type="button" | ||
| 83 | + class="flex h-7 w-7 items-center justify-center rounded line-through text-xs hover:bg-muted text-foreground" | ||
| 84 | + onClick={() => execCommand("strikeThrough")} | ||
| 85 | + title="Üstü Çizili" | ||
| 86 | + > | ||
| 87 | + S | ||
| 88 | + </button> | ||
| 89 | + | ||
| 90 | + <div class="mx-1 h-4 w-[1px] bg-border" /> | ||
| 91 | + | ||
| 92 | + <button | ||
| 93 | + type="button" | ||
| 94 | + class="flex h-7 px-2 items-center justify-center rounded text-xs font-mono hover:bg-muted text-foreground" | ||
| 95 | + onClick={() => execCommand("insertUnorderedList")} | ||
| 96 | + title="Madde İşaretli Liste" | ||
| 97 | + > | ||
| 98 | + • Liste | ||
| 99 | + </button> | ||
| 100 | + <button | ||
| 101 | + type="button" | ||
| 102 | + class="flex h-7 px-2 items-center justify-center rounded text-xs font-mono hover:bg-muted text-foreground" | ||
| 103 | + onClick={() => execCommand("insertOrderedList")} | ||
| 104 | + title="Numaralı Liste" | ||
| 105 | + > | ||
| 106 | + 1. Liste | ||
| 107 | + </button> | ||
| 108 | + | ||
| 109 | + <div class="mx-1 h-4 w-[1px] bg-border" /> | ||
| 110 | + | ||
| 111 | + <button | ||
| 112 | + type="button" | ||
| 113 | + class="flex h-7 px-2 items-center justify-center rounded text-xs hover:bg-muted text-muted-foreground" | ||
| 114 | + onClick={() => execCommand("removeFormat")} | ||
| 115 | + title="Biçimlendirmeyi Temizle" | ||
| 116 | + > | ||
| 117 | + Biçimi Temizle | ||
| 118 | + </button> | ||
| 119 | + </div> | ||
| 120 | + | ||
| 121 | + {/* Contenteditable Editor Area */} | ||
| 122 | + <div class="relative flex-1 p-3 min-h-0"> | ||
| 123 | + <div | ||
| 124 | + ref={editorRef} | ||
| 125 | + contentEditable | ||
| 126 | + class={cn( | ||
| 127 | + "w-full h-full min-h-[140px] outline-none text-xs leading-relaxed text-foreground whitespace-pre-wrap overflow-auto", | ||
| 128 | + props.minHeight ? props.minHeight : "min-h-[140px]" | ||
| 129 | + )} | ||
| 130 | + onInput={handleInput} | ||
| 131 | + onFocus={() => setIsFocused(true)} | ||
| 132 | + onBlur={() => setIsFocused(false)} | ||
| 133 | + /> | ||
| 134 | + {/* Placeholder overlay */} | ||
| 135 | + {!props.value && !isFocused() && ( | ||
| 136 | + <div class="pointer-events-none absolute left-3 top-3 text-xs text-muted-foreground/60 select-none"> | ||
| 137 | + {props.placeholder || "Mesajınızı buraya yazın..."} | ||
| 138 | + </div> | ||
| 139 | + )} | ||
| 140 | + </div> | ||
| 141 | + </div> | ||
| 142 | + ); | ||
| 143 | +} | ||
src/components/ui/toast.tsxmodified+4 -4
| @@ -27,14 +27,14 @@ export function Toaster() { | |||
| 27 | <div class="pointer-events-none fixed inset-x-3 top-4 z-[80] flex flex-col items-end gap-2 sm:inset-x-auto sm:right-5 sm:w-96"> | 27 | <div class="pointer-events-none fixed inset-x-3 top-4 z-[80] flex flex-col items-end gap-2 sm:inset-x-auto sm:right-5 sm:w-96"> |
| 28 | <For each={toasts()}> | 28 | <For each={toasts()}> |
| 29 | {(toast) => ( | 29 | {(toast) => ( |
| 30 | - <div class="pointer-events-auto flex w-full items-start gap-3 rounded-2xl border border-black/[0.08] bg-card/95 px-3 py-3 text-card-foreground shadow-apple backdrop-blur-xl dark:border-white/[0.12]"> | 30 | + <div class="pointer-events-auto flex w-full items-center gap-3 rounded-xl border border-black/[0.08] bg-card/95 px-3.5 py-2.5 text-card-foreground shadow-apple backdrop-blur-xl dark:border-white/[0.12]"> |
| 31 | - <span class="mt-0.5 flex h-5 w-5 shrink-0 items-center justify-center rounded-full bg-emerald-500/10 text-emerald-700 dark:text-emerald-300"> | 31 | + <span class="flex h-5 w-5 shrink-0 items-center justify-center rounded-full bg-emerald-500/10 text-emerald-700 dark:text-emerald-300"> |
| 32 | <IconCheck class="h-3.5 w-3.5" /> | 32 | <IconCheck class="h-3.5 w-3.5" /> |
| 33 | </span> | 33 | </span> |
| 34 | - <p class="min-w-0 flex-1 text-sm font-medium leading-5">{toast.title}</p> | 34 | + <p class="min-w-0 flex-1 text-xs font-medium leading-relaxed">{toast.title}</p> |
| 35 | <button | 35 | <button |
| 36 | type="button" | 36 | type="button" |
| 37 | - class={cn("inline-flex h-9 w-9 items-center justify-center rounded-xl text-muted-foreground transition-all hover:bg-muted hover:text-foreground active:scale-[0.96] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring")} | 37 | + class={cn("inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-md text-muted-foreground transition-all hover:bg-muted hover:text-foreground active:scale-[0.96] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring")} |
| 38 | aria-label="Dismiss" | 38 | aria-label="Dismiss" |
| 39 | onClick={() => dismissToast(toast.id)} | 39 | onClick={() => dismissToast(toast.id)} |
| 40 | > | 40 | > |
src/pages/messages-page.tsxmodified+337 -406
| @@ -1,18 +1,33 @@ | |||
| 1 | -import { For, Show, createMemo, createResource, createSignal, Suspense, createEffect, useTransition } from "solid-js"; | 1 | +import { |
| 2 | + For, | ||
| 3 | + Show, | ||
| 4 | + createMemo, | ||
| 5 | + createResource, | ||
| 6 | + createSignal, | ||
| 7 | + Suspense, | ||
| 8 | + useTransition, | ||
| 9 | +} from "solid-js"; | ||
| 2 | import { RouteGuard } from "@/components/layout/route-guard"; | 10 | import { RouteGuard } from "@/components/layout/route-guard"; |
| 3 | import { PaginationControls } from "@/components/ui/pagination-controls"; | 11 | import { PaginationControls } from "@/components/ui/pagination-controls"; |
| 4 | -import { Badge } from "@/components/ui/badge"; | ||
| 5 | import { Button } from "@/components/ui/button"; | 12 | import { Button } from "@/components/ui/button"; |
| 6 | -import { IconArchive, IconMessage, IconSearch, IconSend, IconTrash, IconPlus } from "@/components/ui/icons"; | 13 | +import { |
| 14 | + IconArchive, | ||
| 15 | + IconMessage, | ||
| 16 | + IconSearch, | ||
| 17 | + IconSend, | ||
| 18 | + IconTrash, | ||
| 19 | + IconPlus, | ||
| 20 | +} from "@/components/ui/icons"; | ||
| 7 | import { Input } from "@/components/ui/input"; | 21 | import { Input } from "@/components/ui/input"; |
| 8 | -import { Label } from "@/components/ui/label"; | 22 | +import { GmailMailRow } from "@/components/messages/gmail-mail-row"; |
| 9 | -import { Textarea } from "@/components/ui/textarea"; | 23 | +import { GmailMailDetail } from "@/components/messages/gmail-mail-detail"; |
| 10 | -import { UserSearchSelect } from "@/components/users/user-search-select"; | 24 | +import { GmailComposeBox } from "@/components/messages/gmail-compose-box"; |
| 11 | import { cn } from "@/lib/cn"; | 25 | import { cn } from "@/lib/cn"; |
| 12 | -import { getMessages } from "@/api/messages"; | 26 | +import { |
| 13 | -import { patchMessageById } from "@/api/messages"; | 27 | + getMessages, |
| 14 | -import { postMessage } from "@/api/messages"; | 28 | + patchMessageById, |
| 15 | -import { deleteMessageById } from "@/api/messages"; | 29 | + deleteMessageById, |
| 30 | +} from "@/api/messages"; | ||
| 16 | import type { Message, MessageFolder } from "@/api/client"; | 31 | import type { Message, MessageFolder } from "@/api/client"; |
| 17 | import { formatApiError } from "@/api/client"; | 32 | import { formatApiError } from "@/api/client"; |
| 18 | import { useAuth } from "@/stores/auth-context"; | 33 | import { useAuth } from "@/stores/auth-context"; |
| @@ -23,460 +38,376 @@ import { createFlash } from "@/lib/flash"; | |||
| 23 | export default function MessagesPage() { | 38 | export default function MessagesPage() { |
| 24 | const t = useT(); | 39 | const t = useT(); |
| 25 | const auth = useAuth(); | 40 | const auth = useAuth(); |
| 26 | - const [sidebarWidth, setSidebarWidth] = createSignal(208); | ||
| 27 | - const [listWidth, setListWidth] = createSignal(448); | ||
| 28 | const [folder, setFolder] = createSignal<MessageFolder>("inbox"); | 41 | const [folder, setFolder] = createSignal<MessageFolder>("inbox"); |
| 29 | const [page, setPage] = createSignal(1); | 42 | const [page, setPage] = createSignal(1); |
| 30 | const limit = 30; | 43 | const limit = 30; |
| 31 | const [selectedId, setSelectedId] = createSignal<string>(""); | 44 | const [selectedId, setSelectedId] = createSignal<string>(""); |
| 32 | const [query, setQuery] = createSignal(""); | 45 | const [query, setQuery] = createSignal(""); |
| 33 | const [composeOpen, setComposeOpen] = createSignal(false); | 46 | const [composeOpen, setComposeOpen] = createSignal(false); |
| 34 | - const [replyData, setReplyData] = createSignal<{ recipient: string; subject: string; body: string } | null>(null); | 47 | + const [replyData, setReplyData] = createSignal<{ |
| 48 | + recipient: string; | ||
| 49 | + subject: string; | ||
| 50 | + body: string; | ||
| 51 | + } | null>(null); | ||
| 35 | const [isPending, startTransition] = useTransition(); | 52 | const [isPending, startTransition] = useTransition(); |
| 36 | const [, setFlash] = createFlash(); | 53 | const [, setFlash] = createFlash(); |
| 37 | 54 | ||
| 38 | const [messagePage, { refetch }] = createResource( | 55 | const [messagePage, { refetch }] = createResource( |
| 39 | () => ({ f: folder(), p: page() }), | 56 | () => ({ f: folder(), p: page() }), |
| 40 | - async (args) => await getMessages(args.f, { limit, offset: (args.p - 1) * limit }), | 57 | + async (args) => await getMessages(args.f, { limit, offset: (args.p - 1) * limit }) |
| 41 | ); | 58 | ); |
| 42 | - | 59 | + |
| 43 | const [unreadCount, { refetch: refetchUnread }] = createResource( | 60 | const [unreadCount, { refetch: refetchUnread }] = createResource( |
| 44 | async () => (await getMessages("inbox", { read: false, limit: 1 })).total | 61 | async () => (await getMessages("inbox", { read: false, limit: 1 })).total |
| 45 | ); | 62 | ); |
| 46 | 63 | ||
| 47 | - const messages = createMemo(() => messagePage()?.items ?? []); | 64 | + const rawMessages = createMemo(() => messagePage()?.items ?? []); |
| 48 | - | 65 | + |
| 66 | + // En yeni mesaj en üstte sıralama | ||
| 67 | + const messages = createMemo(() => | ||
| 68 | + rawMessages().slice().sort((a, b) => b.sent_at - a.sent_at) | ||
| 69 | + ); | ||
| 70 | + | ||
| 49 | const filtered = createMemo(() => { | 71 | const filtered = createMemo(() => { |
| 50 | const q = query().trim().toLocaleLowerCase(); | 72 | const q = query().trim().toLocaleLowerCase(); |
| 51 | if (!q) return messages(); | 73 | if (!q) return messages(); |
| 52 | return messages().filter((m) => { | 74 | return messages().filter((m) => { |
| 53 | - const other = folder() === "sent" ? personLabel(m.recipient) : personLabel(m.sender); | 75 | + const isSent = folder() === "sent" || m.sender.id === auth.user()?.id; |
| 54 | - return [other, m.subject, m.body, m.label].join(" ").toLocaleLowerCase().includes(q); | 76 | + const peer = isSent ? m.recipient : m.sender; |
| 77 | + const other = personLabel(peer); | ||
| 78 | + return [other, m.subject, m.body, m.label || ""].join(" ").toLocaleLowerCase().includes(q); | ||
| 55 | }); | 79 | }); |
| 56 | }); | 80 | }); |
| 57 | 81 | ||
| 58 | const selected = createMemo(() => messages().find((m) => m.id === selectedId()) ?? null); | 82 | const selected = createMemo(() => messages().find((m) => m.id === selectedId()) ?? null); |
| 59 | const isOwnSentMessage = (msg: Message) => msg.sender.id === auth.user()?.id; | 83 | const isOwnSentMessage = (msg: Message) => msg.sender.id === auth.user()?.id; |
| 60 | - const restoreFolder = (msg: Message): MessageFolder => isOwnSentMessage(msg) ? "sent" : "inbox"; | ||
| 61 | - const gridTemplate = () => `${sidebarWidth()}px 0.375rem ${listWidth()}px 0.375rem minmax(0,1fr)`; | ||
| 62 | 84 | ||
| 63 | - const startResize = (target: "sidebar" | "list", event: PointerEvent) => { | 85 | + const restoreFolder = (msg: Message): MessageFolder => { |
| 64 | - event.preventDefault(); | 86 | + if (msg.previous_folder && (msg.previous_folder as string) !== "deleted") { |
| 65 | - const startX = event.clientX; | 87 | + return msg.previous_folder as MessageFolder; |
| 66 | - const startSidebar = sidebarWidth(); | ||
| 67 | - const startList = listWidth(); | ||
| 68 | - const clamp = (value: number, min: number, max: number) => Math.min(max, Math.max(min, value)); | ||
| 69 | - const move = (next: PointerEvent) => { | ||
| 70 | - const delta = next.clientX - startX; | ||
| 71 | - if (target === "sidebar") setSidebarWidth(clamp(startSidebar + delta, 176, 320)); | ||
| 72 | - else setListWidth(clamp(startList + delta, 320, 640)); | ||
| 73 | - }; | ||
| 74 | - const up = () => { | ||
| 75 | - window.removeEventListener("pointermove", move); | ||
| 76 | - window.removeEventListener("pointerup", up); | ||
| 77 | - }; | ||
| 78 | - window.addEventListener("pointermove", move); | ||
| 79 | - window.addEventListener("pointerup", up); | ||
| 80 | - }; | ||
| 81 | - | ||
| 82 | - // Mark as read when selected | ||
| 83 | - createEffect(() => { | ||
| 84 | - const msg = selected(); | ||
| 85 | - if (msg && !msg.read && msg.folder === "inbox") { | ||
| 86 | - patchMessageById(msg.id, { read: true }) | ||
| 87 | - .then(() => { | ||
| 88 | - refetch(); | ||
| 89 | - refetchUnread(); | ||
| 90 | - }) | ||
| 91 | - .catch(console.error); | ||
| 92 | } | 88 | } |
| 93 | - }); | 89 | + return isOwnSentMessage(msg) ? "sent" : "inbox"; |
| 90 | + }; | ||
| 94 | 91 | ||
| 95 | - const handleAction = async (msg: Message, action: { folder?: MessageFolder, delete?: boolean }) => { | 92 | + const handleAction = async ( |
| 93 | + msg: Message, | ||
| 94 | + action: { folder?: MessageFolder; delete?: boolean; read?: boolean } | ||
| 95 | + ) => { | ||
| 96 | try { | 96 | try { |
| 97 | if (action.delete) { | 97 | if (action.delete) { |
| 98 | + if (msg.folder !== "trash") { | ||
| 99 | + setFlash("Kalıcı silme işlemi sadece Çöp Kutusu'ndaki mesajlar için geçerlidir"); | ||
| 100 | + return; | ||
| 101 | + } | ||
| 98 | await deleteMessageById(msg.id); | 102 | await deleteMessageById(msg.id); |
| 103 | + setFlash(t("messages.deletedToast")); | ||
| 99 | } else if (action.folder) { | 104 | } else if (action.folder) { |
| 105 | + if (action.folder === "archive" && isOwnSentMessage(msg)) { | ||
| 106 | + setFlash("Gönderilen mesajlar arşive taşınamaz"); | ||
| 107 | + return; | ||
| 108 | + } | ||
| 100 | await patchMessageById(msg.id, { folder: action.folder }); | 109 | await patchMessageById(msg.id, { folder: action.folder }); |
| 110 | + setFlash(t("messages.movedToast")); | ||
| 111 | + } else if (action.read !== undefined) { | ||
| 112 | + if (isOwnSentMessage(msg)) { | ||
| 113 | + setFlash("Sadece alınan mesajların okundu durumu değiştirilebilir"); | ||
| 114 | + return; | ||
| 115 | + } | ||
| 116 | + await patchMessageById(msg.id, { read: action.read }); | ||
| 117 | + } | ||
| 118 | + | ||
| 119 | + if (selectedId() === msg.id && (action.folder || action.delete)) { | ||
| 120 | + setSelectedId(""); | ||
| 101 | } | 121 | } |
| 102 | - if (selectedId() === msg.id) setSelectedId(""); | ||
| 103 | await refetch(); | 122 | await refetch(); |
| 104 | - if (action.folder === "inbox" || msg.folder === "inbox") await refetchUnread(); | 123 | + if (action.folder === "inbox" || msg.folder === "inbox" || action.read !== undefined) { |
| 105 | - setFlash(action.delete ? t("messages.deletedToast") : t("messages.movedToast")); | 124 | + await refetchUnread(); |
| 106 | - } catch (err) { | 125 | + } |
| 107 | - console.error(err); | 126 | + } catch (err: any) { |
| 127 | + console.error("Message action error:", err); | ||
| 128 | + setFlash(formatApiError(err)); | ||
| 108 | } | 129 | } |
| 109 | }; | 130 | }; |
| 110 | 131 | ||
| 111 | - const timeLabel = (ts: number) => { | 132 | + const handleEmptyTrash = async () => { |
| 112 | - const d = new Date(ts); | 133 | + const trashItems = messages(); |
| 113 | - return `${d.getHours().toString().padStart(2, "0")}:${d.getMinutes().toString().padStart(2, "0")}`; | 134 | + if (trashItems.length === 0) return; |
| 135 | + try { | ||
| 136 | + await Promise.all(trashItems.map((m) => deleteMessageById(m.id))); | ||
| 137 | + setFlash("Çöp kutusu boşaltıldı"); | ||
| 138 | + setSelectedId(""); | ||
| 139 | + refetch(); | ||
| 140 | + } catch (err: any) { | ||
| 141 | + console.error("Empty trash error:", err); | ||
| 142 | + setFlash(formatApiError(err)); | ||
| 143 | + } | ||
| 114 | }; | 144 | }; |
| 115 | 145 | ||
| 116 | return ( | 146 | return ( |
| 117 | <RouteGuard> | 147 | <RouteGuard> |
| 118 | - <div> | 148 | + <div class="min-h-[calc(100vh-7rem)] bg-background"> |
| 119 | - <section class="data-shell overflow-hidden p-0"> | 149 | + <section class="data-shell overflow-hidden p-0 border-none"> |
| 120 | - <div class="grid min-h-[calc(100vh-7rem)] lg:[grid-template-columns:var(--messages-cols)]" style={{ "--messages-cols": gridTemplate() }}> | 150 | + <div class="flex flex-col md:flex-row min-h-[calc(100vh-7rem)]"> |
| 121 | - <aside class="border-b border-border/80 bg-card/70 p-3 lg:border-b-0 backdrop-blur-xl"> | 151 | + {/* Gmail Left Sidebar */} |
| 122 | - <div class="space-y-3"> | 152 | + <aside class="w-full md:w-60 border-r bg-card/60 p-4 shrink-0 space-y-6"> |
| 123 | - <Button class="w-full rounded-xl shadow-sm" onClick={() => { setSelectedId(""); setComposeOpen(true); }}> | 153 | + {/* Gmail Compose Button */} |
| 124 | - <IconPlus class="h-4 w-4" /> | 154 | + <button |
| 125 | - {t("messages.newMessage")} | 155 | + type="button" |
| 126 | - </Button> | 156 | + class="flex h-12 px-6 items-center gap-3 rounded-2xl bg-card border border-border/80 shadow-md hover:shadow-lg hover:bg-accent text-foreground font-bold text-xs tracking-tight transition-all duration-200" |
| 127 | - <div class="space-y-1.5"> | 157 | + onClick={() => { |
| 128 | - <Button | 158 | + setReplyData(null); |
| 129 | - variant="ghost" | 159 | + setComposeOpen(true); |
| 130 | - class={cn( | 160 | + }} |
| 131 | - "group/btn h-11 w-full justify-start gap-3 rounded-xl px-3.5 text-sm font-semibold transition-all duration-200 ease-out hover:scale-[1.01] active:scale-[0.98]", | 161 | + > |
| 132 | - folder() === "inbox" | 162 | + <IconPlus class="h-5 w-5 text-primary" /> |
| 133 | - ? "border border-violet-500/50 bg-card text-foreground ring-1 ring-violet-500/30 shadow-sm" | 163 | + <span>{t("messages.newMessage")}</span> |
| 134 | - : "text-muted-foreground hover:bg-muted/40 hover:text-foreground" | 164 | + </button> |
| 135 | - )} | 165 | + |
| 136 | - onClick={() => startTransition(() => { setFolder("inbox"); setPage(1); setSelectedId(""); })} | 166 | + {/* Gmail Folder Navigation List */} |
| 137 | - > | 167 | + <nav class="space-y-1"> |
| 138 | - <IconMessage class={cn("h-4 w-4 transition-colors duration-200", folder() === "inbox" ? "text-violet-400" : "text-muted-foreground group-hover/btn:text-violet-400")} /> | 168 | + <button |
| 169 | + type="button" | ||
| 170 | + class={cn( | ||
| 171 | + "flex h-9 w-full items-center justify-between rounded-r-full px-4 text-xs font-semibold transition-colors", | ||
| 172 | + folder() === "inbox" | ||
| 173 | + ? "bg-primary/10 text-primary font-bold" | ||
| 174 | + : "text-muted-foreground hover:bg-muted/40 hover:text-foreground" | ||
| 175 | + )} | ||
| 176 | + onClick={() => | ||
| 177 | + startTransition(() => { | ||
| 178 | + setFolder("inbox"); | ||
| 179 | + setPage(1); | ||
| 180 | + setSelectedId(""); | ||
| 181 | + }) | ||
| 182 | + } | ||
| 183 | + > | ||
| 184 | + <div class="flex items-center gap-3"> | ||
| 185 | + <IconMessage class="h-4 w-4" /> | ||
| 139 | <span>{t("messages.inbox")}</span> | 186 | <span>{t("messages.inbox")}</span> |
| 140 | - <Show when={unreadCount() ? unreadCount()! > 0 : false}> | 187 | + </div> |
| 141 | - <Badge variant="default" class="ml-auto h-5 min-w-5 justify-center rounded-full bg-violet-500 px-1.5 text-[10px] font-bold text-white shadow-[0_0_10px_rgba(139,92,246,0.4)]">{unreadCount()}</Badge> | 188 | + <Show when={unreadCount() ? unreadCount()! > 0 : false}> |
| 142 | - </Show> | 189 | + <span class="rounded-full bg-primary px-2 py-0.5 text-[10px] font-bold text-primary-foreground"> |
| 143 | - </Button> | 190 | + {unreadCount()} |
| 144 | - <Button | 191 | + </span> |
| 145 | - variant="ghost" | 192 | + </Show> |
| 146 | - class={cn( | 193 | + </button> |
| 147 | - "group/btn h-11 w-full justify-start gap-3 rounded-xl px-3.5 text-sm font-semibold transition-all duration-200 ease-out hover:scale-[1.01] active:scale-[0.98]", | 194 | + |
| 148 | - folder() === "sent" | 195 | + <button |
| 149 | - ? "border border-cyan-500/50 bg-card text-foreground ring-1 ring-cyan-500/30 shadow-sm" | 196 | + type="button" |
| 150 | - : "text-muted-foreground hover:bg-muted/40 hover:text-foreground" | 197 | + class={cn( |
| 151 | - )} | 198 | + "flex h-9 w-full items-center justify-between rounded-r-full px-4 text-xs font-semibold transition-colors", |
| 152 | - onClick={() => startTransition(() => { setFolder("sent"); setPage(1); setSelectedId(""); })} | 199 | + folder() === "sent" |
| 153 | - > | 200 | + ? "bg-primary/10 text-primary font-bold" |
| 154 | - <IconSend class={cn("h-4 w-4 transition-colors duration-200", folder() === "sent" ? "text-cyan-400" : "text-muted-foreground group-hover/btn:text-cyan-400")} /> | 201 | + : "text-muted-foreground hover:bg-muted/40 hover:text-foreground" |
| 202 | + )} | ||
| 203 | + onClick={() => | ||
| 204 | + startTransition(() => { | ||
| 205 | + setFolder("sent"); | ||
| 206 | + setPage(1); | ||
| 207 | + setSelectedId(""); | ||
| 208 | + }) | ||
| 209 | + } | ||
| 210 | + > | ||
| 211 | + <div class="flex items-center gap-3"> | ||
| 212 | + <IconSend class="h-4 w-4" /> | ||
| 155 | <span>{t("messages.sent")}</span> | 213 | <span>{t("messages.sent")}</span> |
| 156 | - </Button> | 214 | + </div> |
| 157 | - <Button | 215 | + </button> |
| 158 | - variant="ghost" | 216 | + |
| 159 | - class={cn( | 217 | + <button |
| 160 | - "group/btn h-11 w-full justify-start gap-3 rounded-xl px-3.5 text-sm font-semibold transition-all duration-200 ease-out hover:scale-[1.01] active:scale-[0.98]", | 218 | + type="button" |
| 161 | - folder() === "archive" | 219 | + class={cn( |
| 162 | - ? "border border-amber-500/50 bg-card text-foreground ring-1 ring-amber-500/30 shadow-sm" | 220 | + "flex h-9 w-full items-center justify-between rounded-r-full px-4 text-xs font-semibold transition-colors", |
| 163 | - : "text-muted-foreground hover:bg-muted/40 hover:text-foreground" | 221 | + folder() === "archive" |
| 164 | - )} | 222 | + ? "bg-primary/10 text-primary font-bold" |
| 165 | - onClick={() => startTransition(() => { setFolder("archive"); setPage(1); setSelectedId(""); })} | 223 | + : "text-muted-foreground hover:bg-muted/40 hover:text-foreground" |
| 166 | - > | 224 | + )} |
| 167 | - <IconArchive class={cn("h-4 w-4 transition-colors duration-200", folder() === "archive" ? "text-amber-400" : "text-muted-foreground group-hover/btn:text-amber-400")} /> | 225 | + onClick={() => |
| 226 | + startTransition(() => { | ||
| 227 | + setFolder("archive"); | ||
| 228 | + setPage(1); | ||
| 229 | + setSelectedId(""); | ||
| 230 | + }) | ||
| 231 | + } | ||
| 232 | + > | ||
| 233 | + <div class="flex items-center gap-3"> | ||
| 234 | + <IconArchive class="h-4 w-4" /> | ||
| 168 | <span>{t("messages.archive")}</span> | 235 | <span>{t("messages.archive")}</span> |
| 169 | - </Button> | 236 | + </div> |
| 170 | - <Button | 237 | + </button> |
| 171 | - variant="ghost" | 238 | + |
| 172 | - class={cn( | 239 | + <button |
| 173 | - "group/btn h-11 w-full justify-start gap-3 rounded-xl px-3.5 text-sm font-semibold transition-all duration-200 ease-out hover:scale-[1.01] active:scale-[0.98]", | 240 | + type="button" |
| 174 | - folder() === "trash" | 241 | + class={cn( |
| 175 | - ? "border border-rose-500/50 bg-card text-foreground ring-1 ring-rose-500/30 shadow-sm" | 242 | + "flex h-9 w-full items-center justify-between rounded-r-full px-4 text-xs font-semibold transition-colors", |
| 176 | - : "text-muted-foreground hover:bg-muted/40 hover:text-foreground" | 243 | + folder() === "trash" |
| 177 | - )} | 244 | + ? "bg-destructive/10 text-destructive font-bold" |
| 178 | - onClick={() => startTransition(() => { setFolder("trash"); setPage(1); setSelectedId(""); })} | 245 | + : "text-muted-foreground hover:bg-muted/40 hover:text-foreground" |
| 179 | - > | 246 | + )} |
| 180 | - <IconTrash class={cn("h-4 w-4 transition-colors duration-200", folder() === "trash" ? "text-rose-400" : "text-muted-foreground group-hover/btn:text-rose-400")} /> | 247 | + onClick={() => |
| 248 | + startTransition(() => { | ||
| 249 | + setFolder("trash"); | ||
| 250 | + setPage(1); | ||
| 251 | + setSelectedId(""); | ||
| 252 | + }) | ||
| 253 | + } | ||
| 254 | + > | ||
| 255 | + <div class="flex items-center gap-3"> | ||
| 256 | + <IconTrash class="h-4 w-4" /> | ||
| 181 | <span>{t("messages.trash")}</span> | 257 | <span>{t("messages.trash")}</span> |
| 182 | - </Button> | 258 | + </div> |
| 183 | - </div> | 259 | + </button> |
| 184 | - </div> | 260 | + </nav> |
| 185 | </aside> | 261 | </aside> |
| 186 | 262 | ||
| 187 | - <div | 263 | + {/* Gmail Main Content Area */} |
| 188 | - role="separator" | 264 | + <main class="flex-1 flex flex-col min-w-0 bg-background"> |
| 189 | - aria-orientation="vertical" | 265 | + {/* Top Header Toolbar */} |
| 190 | - class="hidden cursor-col-resize bg-border/60 transition-colors duration-200 hover:bg-violet-500/60 lg:block" | 266 | + <Show when={!selected()}> |
| 191 | - onPointerDown={(event) => startResize("sidebar", event)} | 267 | + <div class="flex items-center justify-between border-b px-4 py-3 bg-card/40"> |
| 192 | - /> | 268 | + <div class="flex items-center gap-3 w-full max-w-xl"> |
| 269 | + <div class="relative w-full"> | ||
| 270 | + <IconSearch class="pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" /> | ||
| 271 | + <Input | ||
| 272 | + class="h-10 rounded-full bg-muted/40 pl-9 pr-4 text-xs border-none focus-visible:ring-1" | ||
| 273 | + placeholder={t("messages.search")} | ||
| 274 | + value={query()} | ||
| 275 | + onInput={(event) => setQuery(event.currentTarget.value)} | ||
| 276 | + /> | ||
| 277 | + </div> | ||
| 278 | + </div> | ||
| 193 | 279 | ||
| 194 | - <div class="flex min-w-0 flex-col border-b lg:border-b-0"> | 280 | + <div class="flex items-center gap-3"> |
| 195 | - <div class="border-b p-3"> | 281 | + <Show when={folder() === "trash" && messages().length > 0}> |
| 196 | - <div class="relative"> | 282 | + <Button |
| 197 | - <IconSearch class="pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" /> | 283 | + variant="outline" |
| 198 | - <Input class="h-11 rounded-xl pl-8" placeholder={t("messages.search")} value={query()} onInput={(event) => setQuery(event.currentTarget.value)} /> | 284 | + size="sm" |
| 199 | - </div> | 285 | + class="h-8 rounded-lg text-xs text-destructive hover:bg-destructive/10" |
| 200 | - </div> | 286 | + onClick={handleEmptyTrash} |
| 201 | - <div class={cn("flex-1 space-y-2 overflow-auto p-3 transition-opacity duration-200", isPending() && "opacity-50 pointer-events-none")}> | 287 | + > |
| 202 | - <Suspense fallback={<div class="p-4 text-center text-sm text-muted-foreground">{t("common.loading")}</div>}> | 288 | + <IconTrash class="mr-1.5 h-3.5 w-3.5" /> |
| 203 | - <Show when={filtered().length > 0} fallback={<div class="p-4 text-center text-sm text-muted-foreground">{t("messages.noMessages")}</div>}> | 289 | + Çöp Kutusunu Boşalt |
| 204 | - <For each={filtered()}> | 290 | + </Button> |
| 205 | - {(message) => { | 291 | + </Show> |
| 206 | - const isSent = folder() === "sent" || isOwnSentMessage(message); | 292 | + |
| 207 | - const peerName = isSent ? personLabel(message.recipient) : personLabel(message.sender); | 293 | + <Show when={messagePage()}> |
| 208 | - const role = isSent ? message.recipient_role : message.sender_role; | 294 | + <span class="font-mono text-xs text-muted-foreground shrink-0"> |
| 209 | - const unread = !isSent && !message.read; | 295 | + {messagePage()!.total > 0 |
| 210 | - | 296 | + ? `${(page() - 1) * limit + 1}-${Math.min(page() * limit, messagePage()!.total)} / ${messagePage()!.total}` |
| 211 | - return ( | 297 | + : "0 / 0"} |
| 212 | - <button | 298 | + </span> |
| 213 | - type="button" | 299 | + </Show> |
| 214 | - class={cn( | 300 | + </div> |
| 215 | - "group/card w-full rounded-2xl border bg-card p-3 text-left shadow-sm transition-all duration-200 ease-out hover:-translate-y-0.5 active:translate-y-0", | ||
| 216 | - selected()?.id === message.id ? "border-violet-500/60 ring-1 ring-violet-500/30 bg-card shadow-md" : "border-border/80 hover:border-violet-500/40 hover:bg-muted/30 hover:shadow-md", | ||
| 217 | - unread && selected()?.id !== message.id && "border-violet-500/30 bg-muted/20" | ||
| 218 | - )} | ||
| 219 | - onClick={() => { setComposeOpen(false); setSelectedId(message.id); }} | ||
| 220 | - > | ||
| 221 | - <div class="flex items-start justify-between gap-2"> | ||
| 222 | - <span class={cn("truncate text-xs font-semibold uppercase tracking-wider text-muted-foreground")}>{peerName}</span> | ||
| 223 | - <span class={cn("mono shrink-0 text-[10px]", unread ? "font-medium text-foreground" : "text-muted-foreground")}>{timeLabel(message.sent_at)}</span> | ||
| 224 | - </div> | ||
| 225 | - <div class="mt-1 flex items-center gap-2"> | ||
| 226 | - <Show when={unread}> | ||
| 227 | - <span class="h-2 w-2 shrink-0 rounded-full bg-violet-500 shadow-[0_0_0_3px_rgba(139,92,246,0.2)]" /> | ||
| 228 | - </Show> | ||
| 229 | - <span class={cn("truncate text-sm", unread ? "font-bold text-foreground" : "font-medium text-foreground/90")}>{message.subject}</span> | ||
| 230 | - </div> | ||
| 231 | - <p class={cn("mt-1.5 line-clamp-3 text-xs leading-relaxed", unread ? "text-foreground/80" : "text-muted-foreground")}>{message.body}</p> | ||
| 232 | - <Show when={message.label || role}> | ||
| 233 | - <div class="mt-3 flex items-center gap-2"> | ||
| 234 | - <Show when={message.label}> | ||
| 235 | - <Badge variant={unread ? "default" : "secondary"} class="text-[10px]">{message.label}</Badge> | ||
| 236 | - </Show> | ||
| 237 | - <Show when={role}> | ||
| 238 | - <span class="text-[10px] uppercase tracking-widest text-muted-foreground">{t(`role.${role}` as any)}</span> | ||
| 239 | - </Show> | ||
| 240 | - </div> | ||
| 241 | - </Show> | ||
| 242 | - </button> | ||
| 243 | - ); | ||
| 244 | - }} | ||
| 245 | - </For> | ||
| 246 | - </Show> | ||
| 247 | - </Suspense> | ||
| 248 | - </div> | ||
| 249 | - <Show when={messagePage() && messagePage()!.total > limit}> | ||
| 250 | - <div class="border-t p-3"> | ||
| 251 | - <PaginationControls | ||
| 252 | - page={page()} | ||
| 253 | - onPageChange={setPage} | ||
| 254 | - totalPages={Math.ceil((messagePage()?.total ?? 0) / limit)} | ||
| 255 | - /> | ||
| 256 | </div> | 301 | </div> |
| 257 | </Show> | 302 | </Show> |
| 258 | - </div> | ||
| 259 | 303 | ||
| 260 | - <div | 304 | + {/* Gmail Content View: List or Detail */} |
| 261 | - role="separator" | 305 | + <div class="flex-1 overflow-auto"> |
| 262 | - aria-orientation="vertical" | 306 | + <Show |
| 263 | - class="hidden cursor-col-resize bg-border/60 transition-colors hover:bg-primary/50 lg:block" | 307 | + when={selected()} |
| 264 | - onPointerDown={(event) => startResize("list", event)} | 308 | + fallback={ |
| 265 | - /> | 309 | + /* Gmail Dense List View */ |
| 266 | - | 310 | + <div |
| 267 | - <Show | 311 | + class={cn( |
| 268 | - when={!composeOpen()} | 312 | + "transition-opacity duration-200", |
| 269 | - fallback={ | 313 | + isPending() && "opacity-50 pointer-events-none" |
| 270 | - <div class="h-full overflow-auto p-5"> | 314 | + )} |
| 271 | - <ComposePanel | 315 | + > |
| 272 | - open={composeOpen()} | 316 | + <Suspense |
| 273 | - onOpenChange={(open) => { | 317 | + fallback={ |
| 274 | - if (!open) setReplyData(null); | 318 | + <div class="p-6 text-center text-xs text-muted-foreground"> |
| 275 | - setComposeOpen(open); | 319 | + {t("common.loading")} |
| 276 | - }} | ||
| 277 | - onSuccess={() => { | ||
| 278 | - if (folder() === "sent") refetch(); | ||
| 279 | - setFlash(t("messages.sentToast")); | ||
| 280 | - }} | ||
| 281 | - initialRecipient={replyData()?.recipient} | ||
| 282 | - initialSubject={replyData()?.subject} | ||
| 283 | - initialBody={replyData()?.body} | ||
| 284 | - /> | ||
| 285 | - </div> | ||
| 286 | - } | ||
| 287 | - > | ||
| 288 | - <Show when={selected()} fallback={<div class="flex h-full flex-col items-center justify-center gap-3 p-8 text-center text-sm text-muted-foreground"><span class="flex h-14 w-14 items-center justify-center rounded-2xl border border-violet-500/50 ring-1 ring-violet-500/30 bg-muted/40 text-foreground"><IconMessage class="h-7 w-7" /></span><p>{t("messages.noSelection")}</p><Button type="button" size="sm" class="rounded-xl" onClick={() => setComposeOpen(true)}><IconPlus class="h-4 w-4" />{t("messages.newMessage")}</Button></div>}> | ||
| 289 | - {(message) => { | ||
| 290 | - const isSent = folder() === "sent" || isOwnSentMessage(message()); | ||
| 291 | - const peerName = isSent ? personLabel(message().recipient) : personLabel(message().sender); | ||
| 292 | - const role = isSent ? message().recipient_role : message().sender_role; | ||
| 293 | - | ||
| 294 | - return ( | ||
| 295 | - <article class="flex h-full flex-col"> | ||
| 296 | - <div class="flex flex-wrap items-center gap-2 border-b bg-muted/20 p-3"> | ||
| 297 | - <Show when={!isSent}> | ||
| 298 | - <Button | ||
| 299 | - variant="outline" | ||
| 300 | - size="sm" | ||
| 301 | - class="rounded-xl" | ||
| 302 | - onClick={() => { | ||
| 303 | - setReplyData({ | ||
| 304 | - recipient: message().sender.id, | ||
| 305 | - subject: message().subject.startsWith("Re:") ? message().subject : `Re: ${message().subject}`, | ||
| 306 | - body: `\n\n--- Önceki Mesaj ---\n${message().body}`, | ||
| 307 | - }); | ||
| 308 | - setSelectedId(""); | ||
| 309 | - setComposeOpen(true); | ||
| 310 | - }} | ||
| 311 | - > | ||
| 312 | - <IconMessage class="mr-2 h-4 w-4" /> | ||
| 313 | - {t("messages.reply")} | ||
| 314 | - </Button> | ||
| 315 | - <div class="mx-1 h-4 w-[1px] bg-border" /> | ||
| 316 | - </Show> | ||
| 317 | - <Show when={folder() !== "archive"}> | ||
| 318 | - <Button variant="ghost" size="sm" class="h-10 rounded-xl" onClick={() => handleAction(message(), { folder: "archive" })} title={t("messages.moveToArchive")}> | ||
| 319 | - <IconArchive class="h-4 w-4" /> | ||
| 320 | - {t("messages.moveToArchive")} | ||
| 321 | - </Button> | ||
| 322 | - </Show> | ||
| 323 | - <Show when={folder() === "archive"}> | ||
| 324 | - <Button variant="ghost" size="sm" class="h-10 rounded-xl" onClick={() => handleAction(message(), { folder: restoreFolder(message()) })} title={t("messages.moveOutOfArchive")}> | ||
| 325 | - <IconMessage class="mr-2 h-4 w-4" /> | ||
| 326 | - {t("messages.moveOutOfArchive")} | ||
| 327 | - </Button> | ||
| 328 | - </Show> | ||
| 329 | - <Show when={folder() !== "trash"}> | ||
| 330 | - <Button variant="ghost" size="sm" class="h-10 rounded-xl text-destructive" onClick={() => handleAction(message(), { folder: "trash" })} title={t("messages.moveToTrash")}> | ||
| 331 | - <IconTrash class="h-4 w-4" /> | ||
| 332 | - {t("messages.moveToTrash")} | ||
| 333 | - </Button> | ||
| 334 | - </Show> | ||
| 335 | - <Show when={folder() === "trash"}> | ||
| 336 | - <Button variant="ghost" size="sm" class="h-10 rounded-xl text-destructive" onClick={() => handleAction(message(), { delete: true })} title={t("messages.deleteForever")}> | ||
| 337 | - <IconTrash class="h-4 w-4" /> | ||
| 338 | - {t("messages.deleteForever")} | ||
| 339 | - </Button> | ||
| 340 | - </Show> | ||
| 341 | - </div> | ||
| 342 | - <div class="border-b p-5"> | ||
| 343 | - <div class="flex items-start gap-4"> | ||
| 344 | - <div class="flex h-12 w-12 shrink-0 items-center justify-center rounded-2xl border border-violet-500/50 ring-1 ring-violet-500/30 bg-muted/40 text-lg font-bold uppercase text-foreground"> | ||
| 345 | - {peerName.charAt(0)} | ||
| 346 | - </div> | ||
| 347 | - <div class="min-w-0 flex-1"> | ||
| 348 | - <h2 class="font-display text-2xl font-semibold tracking-tight">{message().subject}</h2> | ||
| 349 | - <div class="mt-2 flex flex-wrap items-center gap-2 text-sm text-muted-foreground"> | ||
| 350 | - <span>{isSent ? t("messages.to") : t("messages.from")}</span> | ||
| 351 | - <span class="font-medium text-foreground">{peerName}</span> | ||
| 352 | - <Show when={role}> | ||
| 353 | - <Badge variant="outline" class="ml-1 px-1.5 py-0 text-[10px] uppercase tracking-wider">{t(`role.${role}` as any)}</Badge> | ||
| 354 | - </Show> | ||
| 355 | </div> | 320 | </div> |
| 321 | + } | ||
| 322 | + > | ||
| 323 | + <Show | ||
| 324 | + when={filtered().length > 0} | ||
| 325 | + fallback={ | ||
| 326 | + <div class="p-12 text-center text-xs text-muted-foreground"> | ||
| 327 | + {t("messages.noMessages")} | ||
| 328 | + </div> | ||
| 329 | + } | ||
| 330 | + > | ||
| 331 | + <For each={filtered()}> | ||
| 332 | + {(message) => ( | ||
| 333 | + <GmailMailRow | ||
| 334 | + message={message} | ||
| 335 | + currentUserId={auth.user()?.id} | ||
| 336 | + folder={folder()} | ||
| 337 | + isSelected={selectedId() === message.id} | ||
| 338 | + onSelect={() => setSelectedId(message.id)} | ||
| 339 | + onArchive={ | ||
| 340 | + folder() === "archive" | ||
| 341 | + ? () => handleAction(message, { folder: restoreFolder(message) }) | ||
| 342 | + : !isOwnSentMessage(message) | ||
| 343 | + ? () => handleAction(message, { folder: "archive" }) | ||
| 344 | + : undefined | ||
| 345 | + } | ||
| 346 | + onTrash={ | ||
| 347 | + folder() === "trash" | ||
| 348 | + ? () => handleAction(message, { folder: restoreFolder(message) }) | ||
| 349 | + : () => handleAction(message, { folder: "trash" }) | ||
| 350 | + } | ||
| 351 | + onToggleRead={ | ||
| 352 | + !isOwnSentMessage(message) | ||
| 353 | + ? () => handleAction(message, { read: !message.read }) | ||
| 354 | + : undefined | ||
| 355 | + } | ||
| 356 | + /> | ||
| 357 | + )} | ||
| 358 | + </For> | ||
| 359 | + </Show> | ||
| 360 | + </Suspense> | ||
| 361 | + | ||
| 362 | + <Show when={messagePage() && messagePage()!.total > limit}> | ||
| 363 | + <div class="p-4 border-t"> | ||
| 364 | + <PaginationControls | ||
| 365 | + page={page()} | ||
| 366 | + onPageChange={setPage} | ||
| 367 | + totalPages={Math.ceil((messagePage()?.total ?? 0) / limit)} | ||
| 368 | + /> | ||
| 356 | </div> | 369 | </div> |
| 357 | - <span class="mono shrink-0 rounded-full border border-border/70 bg-muted/50 px-2 py-1 text-xs text-muted-foreground">{timeLabel(message().sent_at)}</span> | 370 | + </Show> |
| 358 | - </div> | ||
| 359 | - </div> | ||
| 360 | - <div class="flex-1 overflow-auto p-5"> | ||
| 361 | - <div class="rounded-xl border bg-card p-5 text-sm leading-7 text-foreground/90 shadow-sm"> | ||
| 362 | - <p class="whitespace-pre-wrap">{message().body}</p> | ||
| 363 | - </div> | ||
| 364 | </div> | 371 | </div> |
| 365 | - </article> | 372 | + } |
| 366 | - ); | 373 | + > |
| 367 | - }} | 374 | + {/* Gmail Mail Detail View with Inline Gmail Reply Editor */} |
| 368 | - </Show> | 375 | + {(message) => ( |
| 369 | - </Show> | 376 | + <GmailMailDetail |
| 377 | + message={message()} | ||
| 378 | + currentUserId={auth.user()?.id} | ||
| 379 | + folder={folder()} | ||
| 380 | + onBack={() => setSelectedId("")} | ||
| 381 | + onAction={(action) => handleAction(message(), action)} | ||
| 382 | + onSuccess={() => { | ||
| 383 | + refetch(); | ||
| 384 | + if (folder() === "inbox") refetchUnread(); | ||
| 385 | + }} | ||
| 386 | + setFlash={setFlash} | ||
| 387 | + /> | ||
| 388 | + )} | ||
| 389 | + </Show> | ||
| 390 | + </div> | ||
| 391 | + </main> | ||
| 370 | </div> | 392 | </div> |
| 371 | </section> | 393 | </section> |
| 394 | + | ||
| 395 | + {/* Gmail Floating Compose Box at Bottom Right */} | ||
| 396 | + <GmailComposeBox | ||
| 397 | + open={composeOpen()} | ||
| 398 | + onClose={() => { | ||
| 399 | + setComposeOpen(false); | ||
| 400 | + setReplyData(null); | ||
| 401 | + }} | ||
| 402 | + onSuccess={() => { | ||
| 403 | + if (folder() === "sent") refetch(); | ||
| 404 | + setFlash(t("messages.sentToast")); | ||
| 405 | + }} | ||
| 406 | + initialRecipient={replyData()?.recipient} | ||
| 407 | + initialSubject={replyData()?.subject} | ||
| 408 | + initialBody={replyData()?.body} | ||
| 409 | + /> | ||
| 372 | </div> | 410 | </div> |
| 373 | </RouteGuard> | 411 | </RouteGuard> |
| 374 | ); | 412 | ); |
| 375 | } | 413 | } |
| 376 | - | ||
| 377 | -function ComposePanel(props: { | ||
| 378 | - open: boolean; | ||
| 379 | - onOpenChange: (open: boolean) => void; | ||
| 380 | - onSuccess: () => void; | ||
| 381 | - initialRecipient?: string; | ||
| 382 | - initialSubject?: string; | ||
| 383 | - initialBody?: string; | ||
| 384 | -}) { | ||
| 385 | - const t = useT(); | ||
| 386 | - const auth = useAuth(); | ||
| 387 | - const [recipient, setRecipient] = createSignal(""); | ||
| 388 | - const [subject, setSubject] = createSignal(""); | ||
| 389 | - const [body, setBody] = createSignal(""); | ||
| 390 | - const [pending, setPending] = createSignal(false); | ||
| 391 | - const [error, setError] = createSignal(""); | ||
| 392 | - | ||
| 393 | - createEffect(() => { | ||
| 394 | - if (props.open) { | ||
| 395 | - setRecipient(props.initialRecipient ?? ""); | ||
| 396 | - setSubject(props.initialSubject ?? ""); | ||
| 397 | - setBody(props.initialBody ?? ""); | ||
| 398 | - } | ||
| 399 | - }); | ||
| 400 | - | ||
| 401 | - const reset = () => { | ||
| 402 | - setRecipient(""); | ||
| 403 | - setSubject(""); | ||
| 404 | - setBody(""); | ||
| 405 | - setError(""); | ||
| 406 | - }; | ||
| 407 | - | ||
| 408 | - const handleSend = async (e: SubmitEvent) => { | ||
| 409 | - e.preventDefault(); | ||
| 410 | - if (!recipient()) { | ||
| 411 | - setError(t("messages.selectRecipient")); | ||
| 412 | - return; | ||
| 413 | - } | ||
| 414 | - setError(""); | ||
| 415 | - setPending(true); | ||
| 416 | - try { | ||
| 417 | - await postMessage({ | ||
| 418 | - recipient_id: recipient(), | ||
| 419 | - subject: subject().trim(), | ||
| 420 | - body: body().trim() || undefined, | ||
| 421 | - }); | ||
| 422 | - props.onSuccess(); | ||
| 423 | - props.onOpenChange(false); | ||
| 424 | - reset(); | ||
| 425 | - } catch (err) { | ||
| 426 | - setError(formatApiError(err)); | ||
| 427 | - } finally { | ||
| 428 | - setPending(false); | ||
| 429 | - } | ||
| 430 | - }; | ||
| 431 | - | ||
| 432 | - return ( | ||
| 433 | - <div class="mx-auto max-w-3xl rounded-xl border bg-card p-5 shadow-sm"> | ||
| 434 | - <form class="space-y-5" onSubmit={handleSend}> | ||
| 435 | - <div class="space-y-1"> | ||
| 436 | - <h2 class="font-display text-2xl font-semibold tracking-tight">{t("messages.newMessage")}</h2> | ||
| 437 | - <p class="text-sm text-muted-foreground">{t("nav.messages")}</p> | ||
| 438 | - </div> | ||
| 439 | - <div class="space-y-1.5 rounded-2xl border border-border/80 bg-card p-4 dark:border-white/[0.08]"> | ||
| 440 | - <Label for="msg-recipient">{t("messages.recipient")}</Label> | ||
| 441 | - <UserSearchSelect | ||
| 442 | - id="msg-recipient" | ||
| 443 | - value={recipient()} | ||
| 444 | - onChange={setRecipient} | ||
| 445 | - placeholder={t("messages.recipientPlaceholder")} | ||
| 446 | - excludeIds={auth.user()?.id ? [auth.user()!.id] : []} | ||
| 447 | - /> | ||
| 448 | - </div> | ||
| 449 | - <div class="space-y-1.5 rounded-2xl border border-border/80 bg-card p-4 dark:border-white/[0.08]"> | ||
| 450 | - <Label for="msg-subject">{t("form.title")}</Label> | ||
| 451 | - <Input | ||
| 452 | - id="msg-subject" | ||
| 453 | - required | ||
| 454 | - maxlength={200} | ||
| 455 | - value={subject()} | ||
| 456 | - onInput={(e) => setSubject(e.currentTarget.value)} | ||
| 457 | - /> | ||
| 458 | - </div> | ||
| 459 | - <div class="space-y-1.5 rounded-2xl border border-border/80 bg-card p-4 dark:border-white/[0.08]"> | ||
| 460 | - <Label for="msg-body">{t("form.description")}</Label> | ||
| 461 | - <Textarea | ||
| 462 | - id="msg-body" | ||
| 463 | - rows={12} | ||
| 464 | - class="min-h-[18rem] resize-y" | ||
| 465 | - value={body()} | ||
| 466 | - onInput={(e) => setBody(e.currentTarget.value)} | ||
| 467 | - /> | ||
| 468 | - </div> | ||
| 469 | - {error() && <p class="text-sm text-destructive">{error()}</p>} | ||
| 470 | - <div class="flex flex-wrap gap-2"> | ||
| 471 | - <Button type="submit" class="rounded-xl" disabled={pending()}> | ||
| 472 | - <IconSend class="mr-2 h-4 w-4" /> | ||
| 473 | - {t("messages.send")} | ||
| 474 | - </Button> | ||
| 475 | - <Button type="button" variant="outline" class="rounded-xl" onClick={() => props.onOpenChange(false)}> | ||
| 476 | - {t("common.cancel")} | ||
| 477 | - </Button> | ||
| 478 | - </div> | ||
| 479 | - </form> | ||
| 480 | - </div> | ||
| 481 | - ); | ||
| 482 | -} | ||