|
| 1 | +import React, { useState, useEffect } from 'react'; |
| 2 | +import { |
| 3 | + View, |
| 4 | + Text, |
| 5 | + FlatList, |
| 6 | + TouchableOpacity, |
| 7 | + StyleSheet, |
| 8 | + ActivityIndicator, |
| 9 | +} from 'react-native'; |
| 10 | +import { logger } from '../../utils/logger'; |
| 11 | +import { Project } from '../../types/dbTypes'; |
| 12 | +import { getProjects } from '../../db/queries'; |
| 13 | +import { useNavigation } from '@react-navigation/native'; |
| 14 | +import FluentLogo from '../../assets/icons/fluent-logo.svg'; |
| 15 | +import { RootStackParamList } from '../../navigation/types'; |
| 16 | +import { StackNavigationProp } from '@react-navigation/stack'; |
| 17 | +import { Ionicons } from '@react-native-vector-icons/ionicons'; |
| 18 | + |
| 19 | +const log = logger.create('ProjectListScreen'); |
| 20 | +type Nav = StackNavigationProp<RootStackParamList, 'Projects'>; |
| 21 | + |
| 22 | +export default function ProjectsScreen() { |
| 23 | + const navigation = useNavigation<Nav>(); |
| 24 | + const [projects, setProjects] = useState<Project[]>([]); |
| 25 | + const [loading, setLoading] = useState(true); |
| 26 | + |
| 27 | + useEffect(() => { |
| 28 | + loadProjects(); |
| 29 | + }, []); |
| 30 | + |
| 31 | + const loadProjects = async () => { |
| 32 | + try { |
| 33 | + const data = await getProjects(); |
| 34 | + setProjects(data); |
| 35 | + } catch (error) { |
| 36 | + log.error('Error loading projects:', { error }); |
| 37 | + } finally { |
| 38 | + setLoading(false); |
| 39 | + } |
| 40 | + }; |
| 41 | + |
| 42 | + if (loading) { |
| 43 | + return ( |
| 44 | + <View style={[styles.container, styles.centered]}> |
| 45 | + <ActivityIndicator size="large" color="#1a6ef5" /> |
| 46 | + </View> |
| 47 | + ); |
| 48 | + } |
| 49 | + |
| 50 | + return ( |
| 51 | + <View style={styles.container}> |
| 52 | + <View style={styles.logoContainer}> |
| 53 | + <FluentLogo width={160} height={54} /> |
| 54 | + </View> |
| 55 | + |
| 56 | + <View style={styles.sectionHeader}> |
| 57 | + <Ionicons name="folder-outline" size={24} color="#000" /> |
| 58 | + <Text style={styles.sectionHeaderText}>Projects</Text> |
| 59 | + </View> |
| 60 | + |
| 61 | + <FlatList |
| 62 | + data={projects} |
| 63 | + keyExtractor={item => item.id.toString()} |
| 64 | + contentContainerStyle={styles.listContent} |
| 65 | + renderItem={({ item }) => ( |
| 66 | + <TouchableOpacity |
| 67 | + style={styles.card} |
| 68 | + activeOpacity={0.7} |
| 69 | + onPress={() => |
| 70 | + navigation.navigate('Chapters', { |
| 71 | + projectId: item.id, |
| 72 | + projectName: item.name, |
| 73 | + language: item.target_language_name, |
| 74 | + }) |
| 75 | + } |
| 76 | + > |
| 77 | + <Ionicons name="folder-outline" size={24} color="#000" /> |
| 78 | + <View style={styles.cardText}> |
| 79 | + <Text style={styles.cardTitle}>{item.name}</Text> |
| 80 | + <Text style={styles.cardSubtitle}> |
| 81 | + {item.target_language_name} |
| 82 | + </Text> |
| 83 | + </View> |
| 84 | + <Ionicons name="chevron-forward" size={20} color="#000" /> |
| 85 | + </TouchableOpacity> |
| 86 | + )} |
| 87 | + /> |
| 88 | + </View> |
| 89 | + ); |
| 90 | +} |
| 91 | + |
| 92 | +const styles = StyleSheet.create({ |
| 93 | + container: { |
| 94 | + flex: 1, |
| 95 | + paddingHorizontal: 16, |
| 96 | + }, |
| 97 | + logoContainer: { |
| 98 | + alignItems: 'center', |
| 99 | + paddingVertical: 28, |
| 100 | + }, |
| 101 | + sectionHeader: { |
| 102 | + flexDirection: 'row', |
| 103 | + alignItems: 'center', |
| 104 | + justifyContent: 'center', |
| 105 | + gap: 10, |
| 106 | + borderWidth: 1, |
| 107 | + borderColor: '#d1d1d6', |
| 108 | + borderRadius: 12, |
| 109 | + padding: 14, |
| 110 | + marginBottom: 12, |
| 111 | + }, |
| 112 | + sectionHeaderText: { |
| 113 | + fontSize: 16, |
| 114 | + fontWeight: '500', |
| 115 | + }, |
| 116 | + listContent: { |
| 117 | + gap: 12, |
| 118 | + }, |
| 119 | + card: { |
| 120 | + flexDirection: 'row', |
| 121 | + alignItems: 'center', |
| 122 | + borderRadius: 12, |
| 123 | + borderWidth: 1, |
| 124 | + borderColor: '#d1d1d6', |
| 125 | + padding: 16, |
| 126 | + gap: 12, |
| 127 | + }, |
| 128 | + cardText: { |
| 129 | + flex: 1, |
| 130 | + }, |
| 131 | + cardTitle: { |
| 132 | + fontSize: 16, |
| 133 | + fontWeight: '600', |
| 134 | + }, |
| 135 | + cardSubtitle: { |
| 136 | + fontSize: 14, |
| 137 | + marginTop: 3, |
| 138 | + }, |
| 139 | + centered: { |
| 140 | + justifyContent: 'center', |
| 141 | + }, |
| 142 | +}); |
0 commit comments