SPB Git

Repository Public

attachments.setup.tsx 3.3 KB 62 lines tsx

1// SP Mail Next — inscription du module « pièces jointes » dans la coquille : galerie /attachments, entrée de barre latérale, raccourci « g f », aperçu commun (galerie et lecteur).2import { lazy, Suspense } from "react"3import { t } from "../../i18n"4import { PV, isInlineSafe, openPreview, previewMode, resetGallery, closePreview, type PreviewItem } from "../../next/attachments"5import type { Setup } from "../../next/features"6import { nextHref } from "../../next/nav"7import { safeFileName } from "../../mail/attachments"8import { clientFor } from "../../state/mail"9import { registerMainPane, registerOverlay, registerShortcut, registerSidebarEntry, setAttachmentPreviewer, type AttachmentPreviewer } from "../../state/registry"10import { navigate } from "../../state/session"11import { useStore } from "../../state/store"12import { registerCommand } from "../commands"13import "./attachments.css"1415const GalleryScreen = lazy(() => import("./GalleryScreen"))16const PreviewDialog = lazy(() => import("./PreviewDialog"))1718const goGallery = () => navigate(nextHref("attachments"))1920/** Monté à la racine ; le dialogue (et son lot) n'est chargé qu'à la première ouverture. */21function PreviewHost() {22  const open = useStore(PV, (s) => s.open)23  if (!open) return null24  return (25    <Suspense fallback={null}>26      <PreviewDialog />27    </Suspense>28  )29}3031/** Pièces jointes du message affiché par le lecteur → même dialogue que la galerie (adresses de la passerelle de la boîte). */32const fromReader: AttachmentPreviewer = ({ mailboxId, email, part, parts }) => {33  const client = clientFor(mailboxId)34  const list = parts.filter((p) => p.blobId)35  const items: PreviewItem[] = list.map((p) => {36    const name = safeFileName(p.name, t("reader.unnamed"))37    const type = (p.type || "application/octet-stream").toLowerCase()38    return {39      key: `${mailboxId}:${email.id}:${p.blobId}`, name, type, size: p.size, mailboxId, emailId: email.id, threadId: null, blobId: p.blobId!,40      downloadUrl: client.downloadUrl(p.blobId!, name, type), inlineUrl: isInlineSafe(type) ? client.downloadUrl(p.blobId!, name, type, true) : null, mode: previewMode(type, name),41    }42  })43  openPreview(items, Math.max(0, list.indexOf(part)))44}4546export const setupAttachments: Setup = () => {47  setAttachmentPreviewer(fromReader)48  const undo = [49    registerMainPane({ id: "attachments", when: (s) => s.route.name === "next" && s.route.page === "attachments", component: GalleryScreen }),50    registerSidebarEntry({ id: "attachments", slot: "primary", order: 30, icon: "attach", label: () => t("nx.attachments.title"), href: nextHref("attachments"), active: (s) => s.route.name === "next" && s.route.page === "attachments" }),51    registerShortcut({ id: "attachments.go", keys: "g f", label: () => t("nx.attachments.go"), run: goGallery, order: 30 }),52    registerCommand(() => ({ id: "go.attachments", section: "go", title: t("nx.attachments.go"), icon: "attach", keys: "g f", keywords: ["pièces jointes", "fichiers", "attachments", "files", "galerie", "gallery"], run: goGallery })),53    registerOverlay({ id: "attachments.preview", when: (s) => s.phase === "ready", component: PreviewHost }),54  ]55  return () => {56    undo.splice(0).forEach((off) => off())57    setAttachmentPreviewer(null)58    closePreview()59    resetGallery()60  }61}62
Files main
Menu

Theme