POWR/app/(tabs)/profile/settings.tsx
DocNR 755e86e30b fix(profile): standardize login experience across profile screens
- Create reusable NostrProfileLogin component for consistent UI across all screens
- Fix profile feed error when not authenticated by conditionally calling useSocialFeed
- Resolve hook ordering inconsistencies to prevent React errors
- Improve feed loading state management during authentication transitions
- Update all profile screens (overview, activity, progress, settings) to use shared component
- Add proper error handling for profile data loading when not authenticated

This change resolves the console error that appeared when accessing the profile tab
while not logged in, while also providing a better user experience through
consistent styling and messaging across all profile screens.
2025-04-01 21:28:50 -04:00

132 lines
4.9 KiB
TypeScript

// app/(tabs)/profile/settings.tsx
import React, { useState } from 'react';
import { View, ScrollView, Switch, TouchableOpacity } from 'react-native';
import { Text } from '@/components/ui/text';
import { Button } from '@/components/ui/button';
import { Card, CardContent } from '@/components/ui/card';
import { useNDKCurrentUser, useNDKAuth } from '@/lib/hooks/useNDK';
import { ActivityIndicator } from 'react-native';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import NostrLoginSheet from '@/components/sheets/NostrLoginSheet';
import NostrProfileLogin from '@/components/social/NostrProfileLogin';
import TermsOfServiceModal from '@/components/TermsOfServiceModal';
import { useTheme } from '@react-navigation/native';
import type { CustomTheme } from '@/lib/theme';
import { useColorScheme } from '@/lib/theme/useColorScheme';
import { ChevronRight } from 'lucide-react-native';
export default function SettingsScreen() {
const insets = useSafeAreaInsets();
const theme = useTheme() as CustomTheme;
const { colorScheme, toggleColorScheme } = useColorScheme();
const { currentUser, isAuthenticated } = useNDKCurrentUser();
const { logout } = useNDKAuth();
const [isLoginSheetOpen, setIsLoginSheetOpen] = useState(false);
const [isTermsModalVisible, setIsTermsModalVisible] = useState(false);
// Show different UI when not authenticated
if (!isAuthenticated) {
return <NostrProfileLogin message="Login with your Nostr private key to access settings." />;
}
return (
<ScrollView
className="flex-1"
contentContainerStyle={{
paddingBottom: insets.bottom + 20
}}
>
{/* Account Settings */}
<Card className="mx-4 mt-4 mb-4">
<CardContent className="p-4">
<Text className="text-lg font-semibold mb-4">Account Settings</Text>
<View className="flex-row justify-between items-center py-2 border-b border-border">
<Text>Nostr Publishing</Text>
<Text className="text-muted-foreground">Public</Text>
</View>
<View className="flex-row justify-between items-center py-2 border-b border-border">
<Text>Local Storage</Text>
<Text className="text-muted-foreground">Enabled</Text>
</View>
<View className="flex-row justify-between items-center py-2">
<Text>Connected Relays</Text>
<Text className="text-muted-foreground">5</Text>
</View>
</CardContent>
</Card>
{/* App Settings */}
<Card className="mx-4 mb-4">
<CardContent className="p-4">
<Text className="text-lg font-semibold mb-4">App Settings</Text>
<View className="flex-row justify-between items-center py-2 border-b border-border">
<Text>Dark Mode</Text>
<Switch
value={colorScheme === 'dark'}
onValueChange={toggleColorScheme}
trackColor={{ false: '#767577', true: theme.colors.primary }}
/>
</View>
<View className="flex-row justify-between items-center py-2 border-b border-border">
<Text>Notifications</Text>
<Switch
value={true}
trackColor={{ false: '#767577', true: theme.colors.primary }}
/>
</View>
<View className="flex-row justify-between items-center py-2">
<Text>Units</Text>
<Text className="text-muted-foreground">Metric (kg)</Text>
</View>
</CardContent>
</Card>
{/* About */}
<Card className="mx-4 mb-4">
<CardContent className="p-4">
<Text className="text-lg font-semibold mb-4">About</Text>
<View className="flex-row justify-between items-center py-2 border-b border-border">
<Text>Version</Text>
<Text className="text-muted-foreground">1.0.0</Text>
</View>
<TouchableOpacity
className="flex-row justify-between items-center py-2"
onPress={() => setIsTermsModalVisible(true)}
>
<Text>Terms of Service</Text>
<View className="flex-row items-center">
<Text className="text-primary mr-1">View</Text>
<ChevronRight size={16} color={theme.colors.primary} />
</View>
</TouchableOpacity>
</CardContent>
</Card>
{/* Terms of Service Modal */}
<TermsOfServiceModal
visible={isTermsModalVisible}
onClose={() => setIsTermsModalVisible(false)}
/>
{/* Logout Button */}
<View className="mx-4 mt-4">
<Button
variant="destructive"
onPress={logout}
className="w-full"
>
<Text className="text-white">Logout</Text>
</Button>
</View>
</ScrollView>
);
}