Add contacts by right-clicking anyone named in a message

Right-clicking a sender, or any address in the message details, opens a menu
offering to add that person to the address book - plus edit them when they are
already known, write to them, or copy the address.

"Add to contacts" opens the contact editor prefilled rather than saving
silently, so the address book gets a real card that the user can complete,
not a bare email address. contactFromAddress splits the display name into
JSContact name components: "Ada Lovelace" into given and surname, "Lovelace,
Ada" unpicked, a single word as the given name, and a name that is really
just an address left off entirely.

Addresses in the details block were joined into one string, so they are now
rendered per address to be individually targetable.

ContactEditor previously ignored a prefilled name on an unsaved card - it read
name components only when the card had an id - so it now reads them either
way.
This commit is contained in:
2026-08-23 14:46:38 -07:00
parent 40f0ad5fdb
commit d143e711d4
7 changed files with 179 additions and 10 deletions
+2 -1
View File
@@ -26,7 +26,8 @@ type AddrRow = { key: string; ctx: string; street: string; city: string; region:
export function ContactEditor({ card, defaultBookId, onClose, onSaved }: Props) {
const contacts = useContacts();
const isNew = !card.id;
const np = card.id ? nameParts(card as ContactCard) : { given: "", surname: "", middle: "", prefix: "", suffix: "" };
// Read from the card whether it is saved or seeded (e.g. from a message header).
const np = nameParts(card as ContactCard);
const [kind, setKind] = useState<"individual" | "group" | "org">((card.kind as "individual" | "group" | "org") ?? "individual");
const [given, setGiven] = useState(np.given);
const [surname, setSurname] = useState(np.surname);