chahinebrini e76be7ee78 feat(profile): Profile-Page komplett + Header-Dropdown + UI-Pattern-Fixes
Profile (3 Iterationen):
- app/profile/index.tsx + components/profile/* (Header, StatsBar, Approved,
  Streak, UrgeStats, Demographics, DigaMissionBanner)
- echte Live-Daten via useMe-Hook (Avatar/Nickname/Plan/Email/Provider-Pill)
- Demographics mit echten Inputs (TextInput + Bottom-Sheet-Selects),
  debounced auto-save, Pro-Trial-Reward-Banner, Mikro-Why-Texte
- Approved Domains als plain integer (KEIN Plan-Slot/Cap)
- Friendly Hint-Text statt Progress-Bar (alignSelf:'stretch' Pattern)
- StatsBar zentriert mit 3 prominenten Cards (vertikale Dividers)
- Cooldown-Timeline als Liste mit 1px-Rail
- ApprovedDomainsList: Collapse-Chevron rechts in Title-Row (Pattern-Fix)
- Eigene vs fremde Profile-Ansicht streng getrennt (DSGVO/Anonymität)

Header-Dropdown (kein 3-Punkte-Icon):
- Avatar als Trigger im AppHeader (User-Wunsch)
- Custom-Modal beide Plattformen, Card-Style
- SOS prominent oben (nur Wort 'SOS' rot, Tagline 'wir sind für dich da' klein darunter)
- Profile/Settings/Games/Debug(__DEV__)/Logout
- Logout neutral (nicht rot — Recovery-tonal)
- AppHeader: neue showBack + title Props für Sub-Routes

Routes (Stub bis Phase C):
- app/profile/[userId].tsx — anonym (nur public-Stats)
- app/settings.tsx — Coming-Soon-Skeleton
- app/games.tsx — Standalone Games-Page mit GameCard-Grid
- app/debug.tsx — __DEV__-only

Game-Picker (Migration aus Nuxt):
- components/games/{GameCard, StarRating, GameRatingStars}
- 2x2 Grid, 56pt SVG-Icons (inline aus components/urge/gameSvgs.ts)
- Live-Backend /api/games/ratings (silent-fail)
- Re-use UrgeGames.tsx ohne TTS/Cooldown-Loop

UI-Pattern-Fixes (alle aus screenshot-User-Feedback 2026-05-07):
- Snake-Bug (food-pellet React-18-StrictMode-Reducer-double-call) gefixt
- Snake-Buttons platform-native (iOS-blue / Android-ripple)
- Tetris-Margins (16px paddingHorizontal)
- PostCard-Buttons Apple-44pt-Hit-Area (Image-Select, Image-Remove,
  Cancel, Share-Pill — via hitSlop)
- ProfileHeader Demographics-Hint: alignSelf:'stretch' Pattern
- ApprovedDomainsList Collapse: Title flex:1 + Chevron rechts
- ProtectionDetailsSheet FAQ-Items: alignSelf:'stretch' defensive
- AppHeader Back-Button: neue showBack-Prop + chevron-back

Memory + Plan-Docs:
- 17 Memory-Files dokumentieren System-Wissen + Patterns
- ops/{CUTOVER, UI_MIGRATION, PROFILE_PAGE, WEBHOOK, GAMES_1V1,
  RELEASE_READINESS, TESTING_STATE, MAESTRO_HOSTING}_*.md

Backend bleibt unverändert (Tier-LLM + Nickname + sort:latency
sind seit gestern deployed).
2026-05-07 18:22:58 +02:00

241 lines
7.3 KiB
TypeScript

import { useEffect, useState } from 'react';
import { View, Text, Pressable, ScrollView } from 'react-native';
import { SafeAreaView } from 'react-native-safe-area-context';
import { useRouter } from 'expo-router';
import { Ionicons } from '@expo/vector-icons';
import { useTranslation } from 'react-i18next';
import {
GAME_META,
type GameType,
MemoryGame,
TicTacToeGame,
SnakeGame,
TetrisGame,
} from '../components/urge/UrgeGames';
import { GameCard } from '../components/games/GameCard';
import { colors } from '../lib/theme';
import { apiFetch } from '../lib/api';
type GameStat = { avgStars: number; count: number };
type GameStats = Record<GameType, GameStat>;
const EMPTY_STATS: GameStats = {
memory: { avgStars: 0, count: 0 },
tictactoe: { avgStars: 0, count: 0 },
snake: { avgStars: 0, count: 0 },
tetris: { avgStars: 0, count: 0 },
};
type LastScore = { game: GameType; score: number } | null;
export default function GamesScreen() {
const router = useRouter();
const { t } = useTranslation();
const [active, setActive] = useState<GameType | null>(null);
const [lastScore, setLastScore] = useState<LastScore>(null);
const [gameStats, setGameStats] = useState<GameStats>(EMPTY_STATS);
useEffect(() => {
let cancelled = false;
(async () => {
try {
// Backend response: { ratings, stats: [{ gameName, avgStars, count }] }
const data = await apiFetch<{
stats: Array<{ gameName: string; avgStars: number; count: number }>;
}>('/api/games/ratings');
if (cancelled) return;
const next: GameStats = { ...EMPTY_STATS };
for (const s of data.stats ?? []) {
const key = s.gameName.toLowerCase() as GameType;
if (key in next) {
next[key] = { avgStars: s.avgStars ?? 0, count: s.count ?? 0 };
}
}
setGameStats(next);
} catch {
// Silent fail — UI shows 0 stars/count, kein Crash
}
})();
return () => {
cancelled = true;
};
}, []);
function exit(score?: number) {
if (typeof score === 'number' && active) {
setLastScore({ game: active, score });
}
setActive(null);
}
if (active) {
return (
<SafeAreaView style={{ flex: 1, backgroundColor: '#ffffff' }} edges={['top']}>
<View
style={{
paddingHorizontal: 12,
paddingVertical: 8,
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-between',
borderBottomWidth: 1,
borderBottomColor: 'rgba(0,0,0,0.06)',
}}
>
<Pressable
onPress={() => exit()}
hitSlop={10}
style={({ pressed }) => ({
flexDirection: 'row',
alignItems: 'center',
gap: 4,
paddingHorizontal: 6,
paddingVertical: 6,
opacity: pressed ? 0.6 : 1,
})}
>
<Ionicons name="chevron-back" size={22} color={colors.text} />
<Text style={{ fontSize: 15, fontFamily: 'Nunito_600SemiBold', color: colors.text }}>
{t('games.back_to_picker')}
</Text>
</Pressable>
<Text style={{ fontSize: 14, fontFamily: 'Nunito_700Bold', color: '#0a0a0a' }}>
{t(GAME_META.find((g) => g.id === active)!.titleKey)}
</Text>
<View style={{ width: 60 }} />
</View>
<View style={{ flex: 1 }}>
{active === 'memory' ? (
<MemoryGame onComplete={(s) => exit(s)} onAbandon={() => exit()} />
) : null}
{active === 'tictactoe' ? (
<TicTacToeGame onComplete={(s) => exit(s)} onAbandon={() => exit()} />
) : null}
{active === 'snake' ? (
<SnakeGame onComplete={(s) => exit(s)} onAbandon={() => exit()} />
) : null}
{active === 'tetris' ? (
<TetrisGame onComplete={(s) => exit(s)} onAbandon={() => exit()} />
) : null}
</View>
</SafeAreaView>
);
}
return (
<SafeAreaView style={{ flex: 1, backgroundColor: '#ffffff' }} edges={['top']}>
<View
style={{
paddingHorizontal: 12,
paddingTop: 4,
paddingBottom: 12,
flexDirection: 'row',
alignItems: 'center',
gap: 8,
borderBottomWidth: 1,
borderBottomColor: 'rgba(0,0,0,0.06)',
}}
>
<Pressable
onPress={() => router.back()}
hitSlop={8}
style={({ pressed }) => ({
width: 40,
height: 40,
alignItems: 'center',
justifyContent: 'center',
opacity: pressed ? 0.6 : 1,
})}
>
<Ionicons name="chevron-back" size={26} color={colors.text} />
</Pressable>
<Text style={{ fontSize: 20, color: '#0a0a0a', fontFamily: 'Nunito_700Bold' }}>
{t('games.title')}
</Text>
</View>
<ScrollView
style={{ flex: 1 }}
contentContainerStyle={{ paddingHorizontal: 16, paddingTop: 16, paddingBottom: 60 }}
showsVerticalScrollIndicator={false}
>
<Text
style={{
fontSize: 13,
color: '#737373',
fontFamily: 'Nunito_400Regular',
lineHeight: 19,
marginBottom: 18,
paddingHorizontal: 4,
}}
>
{t('games.subtitle')}
</Text>
<View
style={{
flexDirection: 'row',
flexWrap: 'wrap',
gap: 12,
justifyContent: 'space-between',
}}
>
{GAME_META.map((game) => {
const stat = gameStats[game.id] ?? { avgStars: 0, count: 0 };
const recent = lastScore?.game === game.id ? lastScore.score : null;
return (
<View key={game.id} style={{ width: '47.5%' }}>
<GameCard
id={game.id}
svg={game.svg}
titleKey={game.titleKey}
descKey={game.descKey}
avgStars={stat.avgStars}
count={stat.count}
onPress={(id) => setActive(id)}
/>
{recent !== null ? (
<View
style={{
marginTop: 6,
paddingHorizontal: 8,
paddingVertical: 3,
borderRadius: 10,
backgroundColor: colors.brandOrange + '18',
alignSelf: 'center',
}}
>
<Text
style={{
fontSize: 11,
fontFamily: 'Nunito_700Bold',
color: colors.brandOrange,
}}
>
{t('games.last_score', { score: recent })}
</Text>
</View>
) : null}
</View>
);
})}
</View>
<Text
style={{
textAlign: 'center',
fontSize: 11,
color: '#a3a3a3',
fontFamily: 'Nunito_400Regular',
marginTop: 24,
opacity: 0.7,
}}
>
{t('games.skeleton_footer')}
</Text>
</ScrollView>
</SafeAreaView>
);
}