1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
use dioxus::prelude::*;
use dioxus_icons::lucide::{Check, ChevronDown};
use dioxus_primitives::select as primitive_select;
use dioxus_primitives::toast::{use_toast, ToastOptions};
use std::rc::Rc;
use crate::components::avatar::{AvatarImageSize, AvatarShape, ImageAvatar};
use crate::components::badge::{Badge, BadgeVariant};
use crate::components::button::{Button, ButtonVariant};
use crate::components::card::{Card, CardContent, CardDescription, CardHeader, CardTitle};
use crate::components::textarea::Textarea;
use crate::components::toolbar::component::{
Toolbar, ToolbarButton, ToolbarGroup, ToolbarSeparator,
};
use crate::dashboard::common::{
lookup_message, IconKind, LucideIcon, MessageState, MessageStateStoreExt, MessageTag,
AVATAR_PROFILE_OPTIONS, LOREM_IPSUM,
};
use super::avatars::avatar_profile_for_key;
use super::state::{EmailClientState, EmailClientStateStoreExt, EmailClientStateStoreImplExt};
#[css_module("/src/components/select/style.css")]
struct SelectStyles;
#[component]
pub(super) fn ReadPane(
mut state: Store<EmailClientState>,
selected_uid: ReadSignal<Option<String>>,
total_count: ReadSignal<usize>,
selected_index: ReadSignal<usize>,
) -> Element {
let toasts = use_toast();
let mut reply_draft = use_signal(String::new);
let mut reply_box_ref: Signal<Option<Rc<MountedData>>> = use_signal(|| None);
let Some(selected_uid_value) = selected_uid.read().clone() else {
return rsx! {};
};
let Some(selected) = state.messages().get(selected_uid_value.clone()) else {
return rsx! {};
};
let selected: Store<MessageState> = selected.into();
let selected_static = lookup_message(selected.source_index().cloned());
let selected_tags = selected.tags().cloned();
let selected_starred = selected.starred().cloned();
let selected_flagged = selected.flagged().cloned();
let counter = format!("{} of {}", selected_index.read(), total_count.read());
use_effect(move || {
let is_open = state.read_open().cloned();
let selected_uid = selected_uid.read().clone();
if !is_open || selected_uid.is_none() {
return;
}
if let Some(reply_box) = reply_box_ref() {
spawn(async move {
let _ = reply_box.set_focus(true).await;
});
}
});
let archive_uid = selected_uid_value.clone();
let archive_selected = move |_| {
state.archive_message(archive_uid.clone());
};
let snooze_uid = selected_uid_value.clone();
let snooze_selected = move |_| {
state.snooze_message(snooze_uid.clone());
};
let delete_uid = selected_uid_value.clone();
let delete_selected = move |_| {
state.delete_message(delete_uid.clone());
};
let flag_uid = selected_uid_value.clone();
let toggle_flag_selected = move |_| {
state.toggle_message_flag(flag_uid.clone());
};
let star_uid = selected_uid_value.clone();
let toggle_star_selected = move |_| {
state.toggle_message_star(star_uid.clone());
};
let tag_edit_uid = selected_uid_value.clone();
let reply_recipient = selected_static.sender.name.to_string();
let send_reply = move |_| {
if reply_draft.read().trim().is_empty() {
return;
}
reply_draft.set(String::new());
state.close_read_pane();
toasts.info(
"Reply sent".to_string(),
ToastOptions::new().description(format!("Added to {reply_recipient}.")),
);
};
rsx! {
section { class: "ec-read-pane",
Toolbar { class: "ec-read-toolbar", aria_label: "Message actions",
ToolbarGroup {
ToolbarButton {
index: 0usize,
on_click: move |_| state.close_read_pane(),
LucideIcon { kind: IconKind::ArrowLeft }
}
}
ToolbarSeparator { class: "ec-read-toolbar-separator" }
ToolbarGroup {
ToolbarButton { index: 1usize, on_click: archive_selected,
LucideIcon { kind: IconKind::Archive }
" Archive"
}
ToolbarButton { index: 2usize, on_click: snooze_selected,
LucideIcon { kind: IconKind::Snooze }
" Snooze"
}
ToolbarButton { index: 3usize, on_click: delete_selected,
LucideIcon { kind: IconKind::Trash }
" Delete"
}
}
ToolbarSeparator { class: "ec-read-toolbar-separator" }
ToolbarGroup {
ToolbarButton { index: 4usize, on_click: toggle_flag_selected,
if selected_flagged {
LucideIcon { kind: IconKind::Flag }
" Flagged"
} else {
LucideIcon { kind: IconKind::Flag }
" Flag"
}
}
ToolbarButton { index: 5usize, on_click: toggle_star_selected,
if selected_starred {
LucideIcon { kind: IconKind::StarFilled }
" Starred"
} else {
LucideIcon { kind: IconKind::StarOutline }
" Star"
}
}
}
div { class: "ec-toolbar-end",
span { class: "ec-muted", {counter} }
}
}
article { class: "ec-read-body ec-thread",
Card { class: "ec-thread-hero",
CardHeader {
div { class: "ec-thread-hero-main",
div {
CardTitle { "{selected_static.subject}" }
CardDescription {
div { class: "ec-thread-hero-meta",
span {
"{selected_static.thread_count} message{(selected_static.thread_count > 1).then(|| \"s\").unwrap_or(\"\")} in this thread"
}
primitive_select::SelectMulti::<MessageTag> {
class: SelectStyles::dx_select,
values: Some(selected_tags.clone()),
default_values: selected_tags.clone(),
on_values_change: move |values: Vec<MessageTag>| {
state.set_message_tags(tag_edit_uid.clone(), values);
},
primitive_select::SelectTrigger {
class: format!("{} ec-tag-edit-trigger", SelectStyles::dx_select_trigger),
aria_label: "Add tag",
"+ Tag"
ChevronDown {
class: "dx-select-expand-icon",
size: "20px",
stroke: "var(--primary-color-7)",
}
}
primitive_select::SelectList {
class: format!("{} ec-filter-list", SelectStyles::dx_select_list),
aria_label: "Edit tags",
primitive_select::SelectGroup {
primitive_select::SelectGroupLabel { class: SelectStyles::dx_select_group_label, "Tags" }
for (index, tag) in MessageTag::ALL.iter().enumerate() {
primitive_select::SelectOption::<MessageTag> {
class: SelectStyles::dx_select_option,
key: "{tag.label()}",
index,
value: *tag,
text_value: "{tag.label()}",
{tag.label()}
primitive_select::SelectItemIndicator {
Check {
size: "1rem",
stroke: "var(--secondary-color-5)",
}
}
}
}
}
}
}
for tag in selected_tags.iter() {
Button {
variant: ButtonVariant::Ghost,
key: "{tag.label()}",
r#type: "button",
class: "ec-tag-remove",
"aria-label": "Remove tag {tag.label()}",
onclick: {
let tag = *tag;
let uid = selected_uid_value.clone();
move |_| {
state.remove_message_tag(uid.clone(), tag);
}
},
Badge { variant: BadgeVariant::Secondary,
"{tag.label()} ×"
}
}
}
}
}
}
}
}
}
Card { class: if selected_static.thread_count > 1 { "ec-thread-msg" } else { "ec-thread-msg ec-thread-msg-current" },
CardContent { class: "ec-thread-msg-content",
div { class: "ec-thread-msg-head",
ImageAvatar {
size: AvatarImageSize::Small,
shape: AvatarShape::Circle,
src: "{avatar_profile_for_key(selected_static.sender.addr).src}",
alt: "{selected_static.sender.name}",
{selected_static.sender.initials}
}
div { class: "ec-thread-msg-meta",
div { class: "ec-thread-msg-sender",
span { class: "ec-thread-msg-name", {selected_static.sender.name} }
span { class: "ec-thread-msg-addr", {selected_static.sender.addr} }
}
span { class: "ec-thread-msg-time", "{selected_static.full_time}" }
}
}
div { class: "ec-thread-msg-body",
p { {LOREM_IPSUM} }
}
}
}
if selected_static.thread_count > 1 {
Card { class: "ec-thread-msg ec-thread-msg-current",
CardContent { class: "ec-thread-msg-content",
div { class: "ec-thread-msg-head",
ImageAvatar {
size: AvatarImageSize::Small,
shape: AvatarShape::Circle,
src: "{AVATAR_PROFILE_OPTIONS[0].src}",
alt: "You",
"Y"
}
div { class: "ec-thread-msg-meta",
div { class: "ec-thread-msg-sender",
span { class: "ec-thread-msg-name", "You" }
span { class: "ec-thread-msg-addr",
"to {selected_static.sender.name}"
}
}
span { class: "ec-thread-msg-time", "earlier today" }
}
}
div { class: "ec-thread-msg-body",
p { {LOREM_IPSUM} }
}
}
}
}
Card { class: "ec-thread-compose",
CardContent { class: "ec-thread-compose-content",
div { class: "ec-thread-compose-row",
ImageAvatar {
size: AvatarImageSize::Small,
shape: AvatarShape::Circle,
src: "{AVATAR_PROFILE_OPTIONS[0].src}",
alt: "You",
"Y"
}
Textarea {
key: "{selected_uid_value}-reply",
placeholder: format!("Reply to {}…", selected_static.sender.name),
rows: "2",
value: "{reply_draft}",
onmounted: move |event: MountedEvent| reply_box_ref.set(Some(event.data())),
oninput: move |event: FormEvent| reply_draft.set(event.value()),
}
div { class: "ec-thread-compose-actions",
Button {
variant: ButtonVariant::Primary,
r#type: "button",
disabled: reply_draft.read().trim().is_empty(),
onclick: send_reply,
LucideIcon { kind: IconKind::Send, size: 14 }
"Send"
}
}
}
}
}
}
}
}
}