rebreak-monorepo/apps/rebreak-native/components/mail/MailBlockedByDayChart.tsx
chahinebrini 1dfb0c647c feat(mail-page): polish v3 + shared HalfDonut + status-dot heartbeat-aware
User-Feedback nach Live-Test:

Frontend (mail page):
- HalfDonut als shared component in components/common/HalfDonut.tsx
  extrahiert (vorher local in ProtectionDetailsSheet). Mail-Page nutzt
  jetzt dieselbe SVG-Math, Animation und Stroke-Style wie der
  Blocker-Schutz-Details-Sheet — visuelle Konsistenz auf einen Blick.
  Mail-Donut: width=168 (kompakter als die 220 in Blocker, weil Legend
  rechts daneben sitzt).
- Donut zeigt Total in der Mitte mit kompaktem Format:
  < 1000 → "999", >=1000 → "1.2k+" / "12k+" / "27k+"
  Headline-Zahl oben links entfällt — Total ist im Donut-Center.
- "Mehr Infos" + "Kürzlich blockiert" zu EINER Top-Level-Collapsible
  zusammengefasst. Beim Aufklappen: Bar-Chart direkt sichtbar, nested
  Collapsible "Kürzlich blockiert" darunter (default zu).
- Account-Card Expanded: per-Connection-Bar-Chart mit adaptive
  Granularität nach Connection-Age:
  · <24h → Empty-State "Daten werden gesammelt, Auswertung nach 24h"
  · 1-14d → Day-Buckets (echte Daten via /api/mail/stats/blocked-by-day
    ?connectionId=)
  · 15-90d → Week-Buckets (client-aggregiert)
  · >90d → Month-Buckets (client-aggregiert)
- Settings-Sheet komplett refactored: State-Machine `mode: 'list' |
  'edit-title' | 'edit-email' | 'edit-password'` mit Back-Pfeil. Inline-
  Edit im selben Sheet statt Sub-Sheet öffnen (FormSheet-Pattern).
  Email-Edit-Row vorbereitet (Backend-PATCH-Endpoint kommt separat).
- Pen-Icons app-weit entfernt: SheetFieldStack-Row, alle Settings-Rows
  auf chevron-forward (Memory-Konvention).

Frontend (MailAccountCard status fix):
- resolveStatusDot nutzt jetzt heartbeat-as-fallback. Vorher: "waiting"
  wenn lastScannedAt=null, egal ob Daemon längst connected war. Jetzt:
  "waiting" nur wenn weder lebendiger Heartbeat noch vergangener Scan
  existiert → frisch verbundene Connections (z.B. OAuth-Outlook 5s nach
  Connect) zeigen direkt "live".
- Behebt User-Beobachtung: "wartet auf erste verbindung" bei Outlook
  obwohl Daemon-Log "connected, auth=xoauth2" zeigt.

Backend (imap-idle daemon):
- getMailboxLock("INBOX") jetzt mit 30s Promise.race-Timeout gewrappt.
- Outlook/XOAUTH2 hat den Edge-Case, dass der Mailbox-Lock lautlos
  hängt nach erfolgreichem connect — die Session bleibt offen ohne
  Fortschritt bis der Renew-Timer (10min) ein imap.close() schickt.
  Mit Timeout wird das Failure-Mode explizit → Auth-Retry-Loop greift
  sauber + last_connect_error mit klarem Text (statt stiller Hänger).
- Root-Cause "warum hängt es" noch nicht behoben — Diagnose nach
  Deploy in Logs (mo).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-13 23:23:45 +02:00

156 lines
4.6 KiB
TypeScript

import { useMemo } from 'react';
import { Text, View } from 'react-native';
import { useTranslation } from 'react-i18next';
import { useColors } from '../../lib/theme';
import type { BlockedByDayEntry } from '../../hooks/useMailStats';
type Props = {
data: BlockedByDayEntry[];
granularity?: 'day' | 'week' | 'month';
};
const BAR_AREA_HEIGHT = 64;
const MIN_BAR_HEIGHT = 3;
function formatAxisLabel(dateStr: string): string {
const d = new Date(dateStr + 'T00:00:00');
return `${d.getDate()}.${d.getMonth() + 1}.`;
}
function headingKey(granularity: 'day' | 'week' | 'month'): string {
if (granularity === 'week') return 'mail.stats.blocked_per_week_heading';
if (granularity === 'month') return 'mail.stats.blocked_per_month_heading';
return 'mail.stats.blocked_per_day_heading';
}
export function MailBlockedByDayChart({ data, granularity = 'day' }: Props) {
const { t } = useTranslation();
const colors = useColors();
const allZero = data.every((d) => d.count === 0);
const total = data.reduce((s, d) => s + d.count, 0);
const weekAvg = data.length >= 7
? Math.round(data.slice(-7).reduce((s, d) => s + d.count, 0))
: total;
const maxCount = useMemo(() => Math.max(...data.map((d) => d.count), 1), [data]);
const axisIndices = useMemo(() => {
if (data.length === 0) return [];
const step = Math.floor(data.length / 4);
return [0, step, step * 2, step * 3, data.length - 1].filter(
(v, i, arr) => arr.indexOf(v) === i,
);
}, [data]);
return (
<View
style={{
backgroundColor: colors.surface,
borderRadius: 16,
borderWidth: 1,
borderColor: colors.border,
paddingHorizontal: 16,
paddingTop: 14,
paddingBottom: 14,
}}
>
<Text
style={{
fontSize: 11,
fontFamily: 'Nunito_700Bold',
color: colors.textMuted,
textTransform: 'uppercase',
letterSpacing: 0.7,
marginBottom: 10,
}}
>
{t(headingKey(granularity))}
</Text>
{allZero ? (
<View style={{ paddingVertical: 20, alignItems: 'center' }}>
<Text
style={{
fontSize: 13,
fontFamily: 'Nunito_600SemiBold',
color: colors.textMuted,
textAlign: 'center',
}}
>
{t('mail.stats.empty_title')}
</Text>
<Text
style={{
fontSize: 12,
fontFamily: 'Nunito_400Regular',
color: colors.textMuted,
textAlign: 'center',
marginTop: 4,
}}
>
{t('mail.stats.empty_body')}
</Text>
</View>
) : (
<>
{/* Bar chart */}
<View style={{ flexDirection: 'row', alignItems: 'flex-end', height: BAR_AREA_HEIGHT, gap: 2 }}>
{data.map((entry) => {
const barH =
entry.count > 0
? Math.max(MIN_BAR_HEIGHT, Math.round((entry.count / maxCount) * BAR_AREA_HEIGHT))
: MIN_BAR_HEIGHT;
return (
<View
key={entry.date}
style={{
flex: 1,
height: barH,
borderRadius: 2,
backgroundColor: entry.count > 0 ? colors.error : colors.border,
}}
/>
);
})}
</View>
{/* Axis labels */}
<View style={{ flexDirection: 'row', marginTop: 4, position: 'relative', height: 14 }}>
{axisIndices.map((idx) => {
const pct = data.length > 1 ? idx / (data.length - 1) : 0;
return (
<Text
key={idx}
style={{
position: 'absolute',
left: `${pct * 100}%` as any,
fontSize: 9,
fontFamily: 'Nunito_400Regular',
color: colors.textMuted,
transform: [{ translateX: idx === 0 ? 0 : idx === data.length - 1 ? -24 : -12 }],
}}
>
{formatAxisLabel(data[idx].date)}
</Text>
);
})}
</View>
{/* Summary line */}
<Text
style={{
fontSize: 12,
fontFamily: 'Nunito_400Regular',
color: colors.textMuted,
marginTop: 10,
}}
>
{t('mail.stats.blocked_per_day_sublabel', { total, avg: weekAvg })}
</Text>
</>
)}
</View>
);
}