-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathViewProject.tsx
More file actions
123 lines (105 loc) · 3.43 KB
/
Copy pathViewProject.tsx
File metadata and controls
123 lines (105 loc) · 3.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import React, { useState, useEffect } from 'react';
import {
View,
Text,
FlatList,
TouchableOpacity,
ActivityIndicator,
} from 'react-native';
import {
getProjectUnits,
getChapterAssignmentsWithBooks,
} from '../../db/queries';
import { logger } from '../../utils/logger';
import { ChapterListItem } from '../../types/db/types';
import { StackNavigationProp } from '@react-navigation/stack';
import { Ionicons } from '@react-native-vector-icons/ionicons';
import { appStyles as styles } from '../appStyles';
import { RootStackParamList } from '../../types/navigation/types';
import { useNavigation, useRoute, RouteProp } from '@react-navigation/native';
const log = logger.create('ViewProject');
type Nav = StackNavigationProp<RootStackParamList, 'Chapters'>;
type Route = RouteProp<RootStackParamList, 'Chapters'>;
export default function ViewProject() {
const navigation = useNavigation<Nav>();
const { projectId, projectName, language } = useRoute<Route>().params;
const [chapters, setChapters] = useState<ChapterListItem[]>([]);
const [loading, setLoading] = useState(true);
useEffect(() => {
const loadChapters = async () => {
try {
const units = await getProjectUnits(projectId);
if (!units || units.length === 0) {
setChapters([]);
return;
}
const rawId = units[0].id;
if (rawId === null || rawId === undefined) {
log.error('Invalid projectUnitId');
setChapters([]);
return;
}
const projectUnitId = Number(rawId);
const chaptersData = await getChapterAssignmentsWithBooks(
projectUnitId,
);
setChapters(chaptersData);
} catch (error) {
log.error('Error loading chapters:', { error });
} finally {
setLoading(false);
}
};
loadChapters();
}, [projectId]);
if (loading) {
return (
<View style={[styles.container, styles.centered]}>
<ActivityIndicator size="large" color="#1a6ef5" />
</View>
);
}
return (
<View style={styles.container}>
<TouchableOpacity
onPress={() => navigation.goBack()}
style={styles.backBtn}
activeOpacity={0.7}
>
<Ionicons name="chevron-back" size={28} color="#000" />
<View>
<Text style={styles.titleLg}>{projectName}</Text>
<Text style={styles.subtitle}>{language}</Text>
</View>
</TouchableOpacity>
<FlatList
data={chapters}
keyExtractor={item => item.id.toString()}
contentContainerStyle={styles.listContent}
renderItem={({ item }) => (
<TouchableOpacity
style={styles.cardRow}
activeOpacity={0.7}
onPress={() =>
navigation.navigate('VerseDetail', {
chapterId: item.id,
chapterName: `${item.book_name} ${item.chapter_number}`,
projectName,
language,
})
}
>
<Ionicons name="folder-outline" size={24} color="#000" />
<View style={styles.cardText}>
<Text style={styles.cardTitle}>
{item.book_name} {item.chapter_number}
</Text>
<Text style={styles.cardSubtitle}>{item.status}</Text>
</View>
<Ionicons name="chevron-forward" size={20} color="#000" />
</TouchableOpacity>
)}
/>
</View>
);
}