ui improvements
This commit is contained in:
parent
cce9a8c9ba
commit
78aac5a925
7 changed files with 769 additions and 138 deletions
89
frontend/src/utils/inboxSignals.js
Normal file
89
frontend/src/utils/inboxSignals.js
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
const CATEGORY_ORDER = ["Primary", "Updates", "Promotions", "Social", "Finance"];
|
||||
|
||||
export function emailSearchText(email) {
|
||||
const sender = typeof email.sender === "string"
|
||||
? email.sender
|
||||
: email.sender?.name || email.sender?.email || email.sender?.address || "";
|
||||
return [
|
||||
sender,
|
||||
email.subject,
|
||||
email.snippet,
|
||||
email.preview,
|
||||
email.body_text,
|
||||
].filter(Boolean).join(" ").toLowerCase();
|
||||
}
|
||||
|
||||
export function emailCategory(email) {
|
||||
const text = emailSearchText(email);
|
||||
if (/invoice|bill|payment|receipt|finance|bank|transfer|otp|wallet/.test(text)) return "Finance";
|
||||
if (/linkedin|twitter|facebook|instagram|connection request|social/.test(text)) return "Social";
|
||||
if (/unsubscribe|promo|offer|sale|newsletter|deal|discount/.test(text)) return "Promotions";
|
||||
if (/notification|update|alert|noreply|no-reply|provisioned|activated|console|security/.test(text)) return "Updates";
|
||||
return "Primary";
|
||||
}
|
||||
|
||||
export function emailLabels(email) {
|
||||
const text = emailSearchText(email);
|
||||
const labels = [];
|
||||
if (email.is_starred || /urgent|important|asap|priority/.test(text)) {
|
||||
labels.push({ name: "Important", tone: "rose" });
|
||||
}
|
||||
if (/project|proposal|website|development|sow|contract/.test(text)) {
|
||||
labels.push({ name: "Projects", tone: "violet" });
|
||||
}
|
||||
if (/client|customer|internship|candidate/.test(text)) {
|
||||
labels.push({ name: "Clients", tone: "blue" });
|
||||
}
|
||||
if (/invoice|bill|payment|finance|receipt/.test(text)) {
|
||||
labels.push({ name: "Finance", tone: "amber" });
|
||||
}
|
||||
if (/personal|family/.test(text)) {
|
||||
labels.push({ name: "Personal", tone: "green" });
|
||||
}
|
||||
return labels.slice(0, 2);
|
||||
}
|
||||
|
||||
export function matchesLens(email, lens) {
|
||||
if (!lens || lens === "all") return true;
|
||||
if (lens === "starred") return email.is_starred === true;
|
||||
return emailLabels(email).some((label) => label.name === lens);
|
||||
}
|
||||
|
||||
export function categoryCounts(emails) {
|
||||
const counts = Object.fromEntries(CATEGORY_ORDER.map((name) => [name, 0]));
|
||||
emails.forEach((email) => {
|
||||
if (email.is_read === false) counts[emailCategory(email)] += 1;
|
||||
});
|
||||
return counts;
|
||||
}
|
||||
|
||||
export function inboxIntelligence(emails) {
|
||||
const unread = emails.filter((email) => email.is_read === false);
|
||||
const important = emails.filter((email) =>
|
||||
email.is_starred || emailLabels(email).some((label) => label.name === "Important") || email.is_read === false,
|
||||
);
|
||||
const actionItems = emails.filter((email) =>
|
||||
/please|action|reply|review|attached|confirm|need/.test(emailSearchText(email)),
|
||||
);
|
||||
const meetings = emails.filter((email) =>
|
||||
/meet|meeting|calendar|schedule|call|zoom|interview/.test(emailSearchText(email)),
|
||||
);
|
||||
const invoices = emails.filter((email) =>
|
||||
/invoice|bill|payment|receipt/.test(emailSearchText(email)),
|
||||
);
|
||||
return {
|
||||
unread: unread.length,
|
||||
important: important.length,
|
||||
actionItems: actionItems.length,
|
||||
meetings: meetings.length,
|
||||
invoices: invoices.length,
|
||||
importantFromClients: important.filter((email) =>
|
||||
emailLabels(email).some((label) => label.name === "Clients"),
|
||||
).length,
|
||||
};
|
||||
}
|
||||
|
||||
export function attachmentCount(email) {
|
||||
if (Array.isArray(email.attachments)) return email.attachments.length;
|
||||
return Number(email.attachment_count || 0);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue