-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathChapterScreen.js
58 lines (50 loc) · 1.14 KB
/
ChapterScreen.js
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
import React from 'react'
import { View, Text, FlatList } from 'react-native'
import { gql, useQuery } from '@apollo/client'
import styles from './styles'
import Loading from './Loading'
const SECTIONS_QUERY = gql`
query Sections($id: Int!) {
chapter(id: $id) {
sections {
number
title
}
}
}
`
const SectionItem = ({ section, chapter }) => (
<View style={styles.item}>
<Text style={styles.header}>
{chapter.number}.{section.number}: {section.title}
</Text>
</View>
)
export default ({ route }) => {
const { data, loading } = useQuery(SECTIONS_QUERY, {
variables: { id: route.params.chapter.id },
})
if (loading) {
return <Loading />
}
const {
chapter: { sections },
} = data
if (sections.length === 1) {
return (
<View style={styles.centered}>
<Text>No sections</Text>
</View>
)
}
return (
<FlatList
data={sections}
renderItem={({ item }) => (
<SectionItem section={item} chapter={route.params.chapter} />
)}
keyExtractor={(section) => section.number.toString()}
initialNumToRender={15}
/>
)
}