forge
Explore
Log in

Don't you dare go Hollow

hezarfen_frontend

Clone
★ 0

0 watching0 forksTypeScript5.5 MiBdcf123aBurak Boduroğlu2 months ago674 commits

gmail-mail-row.tsx172 lines, 7.0 KiBHistoryRawDownload
1import { Show } from "solid-js";
2import type { Message } from "@/api/client";
3import { Badge } from "@/components/ui/badge";
4import { IconArchive, IconTrash, IconMessage } from "@/components/ui/icons";
5import { cn } from "@/lib/cn";
6import { personLabel } from "@/lib/person";
7import { useT } from "@/stores/preferences-context";
8
9interface GmailMailRowProps {
10 message: Message;
11 currentUserId?: string;
12 folder: string;
13 isSelected: boolean;
14 onSelect: () => void;
15 onArchive?: () => void;
16 onTrash?: () => void;
17 onDeleteForever?: () => void;
18 onToggleRead?: () => void;
19}
20
21export function GmailMailRow(props: GmailMailRowProps) {
22 const t = useT();
23
24 const isSent = () => props.folder === "sent" || props.message.sender.id === props.currentUserId;
25 const peer = () => (isSent() ? props.message.recipient : props.message.sender);
26 const peerName = () => personLabel(peer());
27 const role = () => (isSent() ? props.message.recipient_role : props.message.sender_role);
28 const unread = () => !isSent() && !props.message.read;
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 <div
46 class={cn(
47 // A phone cannot fit sender, subject, snippet, date and actions on one
48 // 40px line, so below sm: the row stacks and grows to a thumb-sized
49 // target; from sm: up it stays the dense single line it always was.
50 "group relative flex shrink-0 cursor-pointer select-none flex-col gap-0.5 border-b border-l-4 border-border-hairline px-3 py-2.5 text-xs transition-colors duration-150",
51 "sm:h-10 sm:flex-row sm:items-center sm:gap-3 sm:px-4 sm:py-0",
52 unread() ? "border-l-primary bg-surface-base font-semibold text-foreground hover:bg-accent/40" : "border-l-transparent bg-surface-overlay text-muted-foreground hover:bg-muted/50",
53 props.isSelected && "bg-accent/80 text-foreground"
54 )}
55 onClick={props.onSelect}
56 >
57 {/* Sender / Peer Name — carries the date too while stacked, so the first
58 line reads like a message list entry on a phone. */}
59 <div class="flex w-full min-w-0 items-center gap-2 sm:w-48 sm:shrink-0">
60 <span
61 class={cn(
62 "truncate text-xs tracking-tight",
63 unread() ? "font-bold text-foreground" : "font-medium text-foreground/90"
64 )}
65 >
66 {isSent() ? `${t("messages.to")}${peerName()}` : peerName()}
67 </span>
68 <Show when={role()}>
69 <span class="shrink-0 text-[11px] uppercase font-mono px-1 py-0.2 rounded bg-muted text-muted-foreground border border-border-hairline">
70 {t(`role.${role()}` as any)}
71 </span>
72 </Show>
73 <span class="ml-auto shrink-0 font-mono text-[11px] text-muted-foreground/80 sm:hidden">
74 {formattedTime(props.message.sent_at)}
75 </span>
76 </div>
77
78 {/* Subject + Body Snippet — a line each while stacked, joined by a dash on
79 the single-line desktop row. */}
80 <div class="flex min-w-0 flex-1 flex-col sm:flex-row sm:items-center sm:gap-2 sm:truncate">
81 <span
82 class={cn(
83 "truncate sm:max-w-[40%] sm:shrink-0",
84 unread() ? "font-bold text-foreground" : "font-semibold text-foreground/90"
85 )}
86 >
87 {props.message.subject}
88 </span>
89 <span class="truncate text-[11px] text-muted-foreground/70">
90 <span class="hidden sm:inline">— </span>
91 {props.message.body.replace(/<[^>]*>?/gm, "").trim()}
92 </span>
93 </div>
94
95 {/* Optional Tag Label */}
96 <Show when={props.message.label}>
97 <Badge variant="outline" class="hidden h-4 shrink-0 px-1.5 py-0 text-[11px] font-medium sm:inline-flex">
98 {props.message.label}
99 </Badge>
100 </Show>
101
102 {/* Right Action & Date Area — desktop only: on a phone the date moved to
103 the first line, and these hover actions live in the opened message
104 rather than as 24px targets crowding a list row. */}
105 <div class="hidden min-w-fit shrink-0 items-center justify-end gap-2 sm:flex">
106 {/* Time / Date */}
107 <span class="font-mono text-[11px] text-muted-foreground/80 shrink-0">
108 {formattedTime(props.message.sent_at)}
109 </span>
110
111 {/* Quick Actions (Always visible with opacity on mobile, group-hover visible on desktop) */}
112 <div class="flex items-center justify-end gap-1 opacity-0 transition-opacity group-hover:opacity-100">
113 <Show when={props.onArchive}>
114 <button
115 type="button"
116 class="flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:bg-accent hover:text-foreground transition-colors"
117 title={props.folder === "archive" ? t("messages.moveOutOfArchive") : t("messages.moveToArchive")}
118 onClick={(e) => {
119 e.stopPropagation();
120 props.onArchive?.();
121 }}
122 >
123 <IconArchive class="h-3.5 w-3.5" />
124 </button>
125 </Show>
126
127 <Show when={props.onTrash}>
128 <button
129 type="button"
130 class="flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:bg-destructive/10 hover:text-destructive-text transition-colors"
131 title={props.folder === "trash" ? t("messages.restoreFromTrash") : t("messages.moveToTrash")}
132 onClick={(e) => {
133 e.stopPropagation();
134 props.onTrash?.();
135 }}
136 >
137 <IconTrash class="h-3.5 w-3.5" />
138 </button>
139 </Show>
140
141 <Show when={props.onDeleteForever}>
142 <button
143 type="button"
144 class="flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:bg-destructive/10 hover:text-destructive-text transition-colors"
145 title={t("messages.deleteForever")}
146 onClick={(e) => {
147 e.stopPropagation();
148 props.onDeleteForever?.();
149 }}
150 >
151 <IconTrash class="h-3.5 w-3.5 text-destructive-text" />
152 </button>
153 </Show>
154
155 <Show when={props.onToggleRead}>
156 <button
157 type="button"
158 class="flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:bg-accent hover:text-foreground transition-colors"
159 title={unread() ? t("messages.markAsRead") : t("messages.markAsUnread")}
160 onClick={(e) => {
161 e.stopPropagation();
162 props.onToggleRead?.();
163 }}
164 >
165 <IconMessage class="h-3.5 w-3.5" />
166 </button>
167 </Show>
168 </div>
169 </div>
170 </div>
171 );
172}