Repository Public
1// SP Mail Next — inscription du module « contacts » dans la coquille : écran /contacts, entrée de barre latérale, raccourci « g c », palette (« @ » et commandes), fiche de l'expéditeur dans le lecteur.2import { lazy } from "react"3import { t } from "../../i18n"4import { CU, resetContacts, suggestContacts } from "../../next/contacts"5import type { Setup } from "../../next/features"6import { nextHref } from "../../next/nav"7import { registerMainPane, registerPaletteProvider, registerReaderPanel, registerShortcut, registerSidebarEntry } from "../../state/registry"8import { navigate } from "../../state/session"9import { registerCommand } from "../commands"10import "./contacts.css"1112const ContactsScreen = lazy(() => import("./ContactsScreen"))13const SenderButton = lazy(() => import("./SenderPopover"))1415const goContacts = () => navigate(nextHref("contacts"))1617export const setupContacts: Setup = () => {18 const undo = [19 registerMainPane({ id: "contacts", when: (s) => s.route.name === "next" && s.route.page === "contacts", component: ContactsScreen }),20 registerSidebarEntry({ id: "contacts", slot: "primary", order: 20, icon: "users", label: () => t("nx.contacts.title"), href: nextHref("contacts"), active: (s) => s.route.name === "next" && s.route.page === "contacts" }),21 registerShortcut({ id: "contacts.go", keys: "g c", label: () => t("nx.contacts.go"), run: goContacts, order: 20 }),22 registerCommand(() => ({ id: "go.contacts", section: "go", title: t("nx.contacts.go"), icon: "users", keys: "g c", keywords: ["contacts", "carnet", "address book"], run: goContacts })),23 registerCommand(() => ({24 id: "contacts.new", section: "actions", title: t("nx.contacts.new"), icon: "userPlus", keywords: ["contact"],25 run: () => {26 goContacts()27 CU.set({ dialog: { type: "edit", contact: null } })28 },29 })),30 // « @ » : les correspondants classés par le serveur ; choisir ouvre la fiche (d'où l'on écrit, cherche, modifie)31 registerPaletteProvider("@", async (query, signal) =>32 (await suggestContacts(query, signal, 12)).map((s) => ({33 id: `contact.${s.contact_id}.${s.email}`, title: s.name || s.email, subtitle: s.name ? s.email : undefined, icon: s.favorite ? ("star" as const) : ("user" as const),34 run: () => navigate(nextHref("contacts", s.contact_id)),35 })),36 ),37 registerReaderPanel({ id: "contacts.sender", slot: "sender", component: SenderButton, order: 10 }),38 ]39 return () => {40 undo.splice(0).forEach((off) => off())41 resetContacts()42 }43}44