Skip to content

Conversation UI #81

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions commons/src/methods/contact_strings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import type { Participant, Account } from "@commons/types/Nylas";

export function getNameInitials(name: string): string {
const nameParts = name.split(" ");
return nameParts
.map((n, i) => (i === 0 || i === nameParts.length - 1 ? n[0] : ""))
.join("");
}

export function getContactInitialForAvatar(
contact: Participant | Partial<Account>,
): string {
const participant = <Participant>contact;
const account = <Partial<Account>>contact;

// if participant type
if (participant.email) {
if (participant.name) {
return getNameInitials(participant.name);
}
return participant.email[0];
}

// else account type
// since this is partial, need to check every attr and have a fallback
if (account.name) {
return getNameInitials(account.name);
} else if (account.email_address) {
return account.email_address[0];
} else {
return "?";
}
}
51 changes: 51 additions & 0 deletions commons/src/methods/datetime.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
export function getTimeString(date: Date): string {
// 11:11am
return date
.toLocaleTimeString([], { timeStyle: "short" })
.replaceAll(/\./g, "");
Comment on lines +4 to +5
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix for above is to upgrade typescript microsoft/TypeScript#38266 (comment)

}

export function getYearString(date: Date): string {
// Jul 5th 2020
const suffixMapper = (num: number): string => {
if ([31, 21, 1].includes(num)) return "st ";
if ([22, 2].includes(num)) return "nd ";
if ([23, 3].includes(num)) return "rd ";
return "th ";
};
return date
.toLocaleDateString(undefined, {
year: "numeric",
month: "short",
day: "numeric",
})
.replaceAll(/, /g, suffixMapper(date.getDate()))
.replaceAll(/[.]/g, "");
}

export function getDateString(date: Date): string {
// Sep 22
return date
.toLocaleDateString(undefined, { month: "short", day: "numeric" })
.replaceAll(/[.]/g, "");
}

// Date logic: https://www.figma.com/file/oiCKNsHDfAo9KnH1Sbs8Xj/Email-%26-Mailbox-Component?node-id=128%3A51
export function getDate(date: Date): string {
const today = new Date();
if (today.toDateString() === date.toDateString()) {
return getTimeString(date);
}

const diff_years = today.getFullYear() - date.getFullYear();
if (diff_years !== 0) {
return getYearString(date);
}

const yesterday = new Date(today.getDate() - 1);
if (yesterday.toDateString() === date.toDateString()) {
return "Yesterday";
}

return getDateString(date);
}
4 changes: 2 additions & 2 deletions commons/src/store/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ function initializeEvents() {
return await eventsMap[queryKey];
}
},
createEvent: (event: Event, query: EventQuery) => {
createEvent: async (event: Event, query: EventQuery) => {
const queryKey = JSON.stringify(query);
if (eventsMap[queryKey]) {
if (await eventsMap[queryKey]) {
eventsMap[queryKey] = Promise.all([
eventsMap[queryKey],
createEvent(event, query),
Expand Down
Loading