fix(webmail): corrige os contadores das pastas e as ações do leitor

Todos estes foram reproduzidos na interface real, com a conta em
mail.lucasrguerra.dev.br, e não em teste.

Contadores das pastas. O badge caía para o total sempre que não havia
nada por ler, no mesmo lugar e no mesmo estilo do contador de não
lidas: uma caixa de entrada com catorze mensagens lidas mostrava "14",
e ler mais uma nunca movia o número - ele nunca esteve contando o que
o leitor pensava. Os dois números agora são visualmente distintos e o
de não lidas só aparece quando existe mensagem por ler.

Em Rascunhos o badge e o total são o mesmo número por definição, então
o sidebar imprimia-o duas vezes: "Rascunhos 1 1". A regra passou para
folderBadge, onde é testada, e o tamanho da pasta é renderizado num
único sítio.

Ações do leitor. Todas as mensagens ofereciam os mesmos quatro botões,
onde a pasta devia decidir. Um e-mail que o próprio utilizador enviou
oferecia "marcar como não lida" - uma flag que nada lê numa pasta onde
nada é entregue - e um rascunho por acabar oferecia Responder e
Encaminhar, mas nenhuma forma de o terminar. Abrir um rascunho agora
abre o compositor com o que estava escrito e adota o seu UID, para que
continuar a escrever substitua esse rascunho em vez de deixar o antigo
para trás. Em Lixeira o botão de apagar diz que apaga em definitivo,
porque é o que faz.

Anexos. t("mail.attachments") era chamado sem o parâmetro que a string
declara, e a interface mostrava literalmente "Anexos ({count})" nos
três idiomas. Na lista, que sabe que há anexos mas não quantos, passa a
nomear o facto em vez de imprimir uma contagem que não tem.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Lucas RayanandClaude Opus 5 committed 2026-08-22 10:18:45 -03:00
1 parent 1dc87a06c8
commit 203316f2c3
9 files changed
+320 -46

No files matched your search

+25 -16
View File
@@ -24,7 +24,7 @@ import { useTranslations } from "../../../i18n/provider";
import { LanguageSwitcher } from "../../../i18n/LanguageSwitcher";
import { useAccount, isAdminRole } from "../../../lib/useAccount";
import { useFolders } from "../../../lib/useFolders";
import { badgeCount, folderMetrics } from "../../../lib/mailCounts";
import { folderBadge } from "../../../lib/mailCounts";
import { initialsFor } from "../../../lib/initials";
export default function UserWebmailLayout({ children }: { children: React.ReactNode }) {
@@ -88,10 +88,11 @@ export default function UserWebmailLayout({ children }: { children: React.ReactN
{navItems.map((item) => {
const Icon = item.icon;
const isActive = pathname === item.href || (item.role === "inbox" && pathname === "/user/mail");
// Drafts counts what is waiting rather than what is unread; see
// badgeCount, which is where that rule is tested.
const badge = badgeCount(folders, item.role);
const { total } = folderMetrics(folders, item.role);
// Both numbers plus which one to emphasise; see folderBadge, where
// that rule is tested. It used to fall back to printing the total in
// the unread badge's place, so an inbox of read mail showed "14" and
// reading another message never moved it.
const badge = folderBadge(folders, item.role);
return (
<Link
@@ -99,7 +100,7 @@ export default function UserWebmailLayout({ children }: { children: React.ReactN
href={item.href}
onClick={() => setMobileOpen(false)}
data-active={isActive}
title={total > 0 ? t("mail.messagesInFolder", { count: total }) : item.label}
title={badge.total > 0 ? t("mail.messagesInFolder", { count: badge.total }) : item.label}
className="lm-nav"
>
<span className="lm-nav-mark" />
@@ -109,19 +110,27 @@ export default function UserWebmailLayout({ children }: { children: React.ReactN
{/* The folder's size, shown quietly beside the badge: the
sidebar reported unread only, so there was nowhere in the
interface that said how much mail a folder holds. */}
{total > 0 && badge > 0 && (
<span className="text-[10.5px] tabular-nums text-slate-500">{total}</span>
)}
{badge > 0 ? (
{/* The folder size, always in the same quiet style, so it
can never be mistaken for an unread count. */}
{badge.total > 0 && (
<span
className={`text-[11.5px] tabular-nums ${isActive ? "text-indigo-300" : "text-slate-400"}`}
className="text-[11.5px] tabular-nums text-slate-500"
title={t("mail.messagesInFolder", { count: badge.total })}
>
{badge}
{badge.total}
</span>
)}
{/* The unread count, only when there is unread mail, and
visibly distinct from the size beside it. */}
{badge.showsUnread && (
<span
className={`rounded-full px-1.5 py-px text-[11px] font-medium tabular-nums ${
isActive ? "bg-indigo-500/25 text-indigo-200" : "bg-indigo-500/20 text-indigo-300"
}`}
title={t("mail.unreadCount", { count: badge.unread })}
>
{badge.unread}
</span>
) : (
total > 0 && (
<span className="text-[11.5px] tabular-nums text-slate-500">{total}</span>
)
)}
</span>
</Link>