import { useEffect, useState, useCallback } from "react"; import { View, Text, TouchableOpacity, Alert, ScrollView } from "react-native"; import { SafeAreaView } from "react-native-safe-area-context"; import { router, useFocusEffect } from "expo-router"; import { MaterialIcons } from "@expo/vector-icons"; import { loadCodexAuth, clearCodexAuth, loadClaudeSessionKey, clearClaudeSessionKey, } from "@/lib/storage"; import { resetOnboarding } from "@/lib/setupState"; import type { CodexAuth } from "@/types/codex"; import Constants from "expo-constants"; function SettingRow({ icon, label, value, onPress, destructive, disabled, }: { icon: React.ComponentProps["name"]; label: string; value?: string; onPress?: () => void; destructive?: boolean; disabled?: boolean; }) { return ( {label} {value && ( {value} )} {onPress && !disabled && ( )} ); } function SectionHeader({ title }: { title: string }) { return ( {title} ); } function SectionCard({ children }: { children: React.ReactNode }) { return ( {children} ); } function Divider() { return ( ); } export default function SettingsTab() { const [codexAuth, setCodexAuth] = useState(null); const [claudeKey, setClaudeKey] = useState(null); const reload = useCallback(() => { Promise.all([loadCodexAuth(), loadClaudeSessionKey()]).then( ([codex, claude]) => { setCodexAuth(codex); setClaudeKey(claude); } ); }, []); useEffect(() => { reload(); }, [reload]); useFocusEffect(useCallback(() => { reload(); }, [reload])); const handleClearCodex = () => { Alert.alert( "Clear Codex credentials", "This will remove your stored auth.json data. You can re-import it anytime.", [ { text: "Cancel", style: "cancel" }, { text: "Clear", style: "destructive", onPress: async () => { await clearCodexAuth(); setCodexAuth(null); }, }, ] ); }; const handleClearClaude = () => { Alert.alert( "Clear Claude session key", "Your session key will be removed. You can re-enter it anytime.", [ { text: "Cancel", style: "cancel" }, { text: "Clear", style: "destructive", onPress: async () => { await clearClaudeSessionKey(); setClaudeKey(null); }, }, ] ); }; const handleResetSetup = () => { Alert.alert( "Re-run Setup Wizard", "This will clear all credentials and restart the setup flow.", [ { text: "Cancel", style: "cancel" }, { text: "Reset & Re-run", style: "destructive", onPress: async () => { await Promise.all([ clearCodexAuth(), clearClaudeSessionKey(), resetOnboarding(), ]); router.replace("/onboarding"); }, }, ] ); }; const appVersion = Constants.expoConfig?.version ?? "1.0.0"; return ( {/* Header */} Settings {/* Codex CLI section */} {codexAuth ? ( <> ) : ( router.navigate("/(tabs)/codex")} /> )} {/* Claude.ai section */} {claudeKey ? ( <> ) : ( router.navigate("/(tabs)/claude")} /> )} {/* App section */} ); }