1- import React , { useState } from 'react'
1+ import React from 'react'
22import { connect } from 'react-redux'
3- import { StyleSheet , View , ViewStyle , TextStyle } from 'react-native'
3+ import { View , ViewStyle , SectionList , TouchableOpacity } from 'react-native'
44
5- import { translate } from '@src/i18n'
65import { useTheme , SylCommon } from '@src/theme'
76import { IState , ITheme , V2exObject } from '@src/types'
8- import * as CompS from '.. /components'
9- import { Text , Spinner } from '@src/components '
10- import { NodeScreenProps as ScreenProps } from '@src/navigation/routes '
7+ import { Text } from '@src /components'
8+ import { NodeScreenProps as ScreenProps , NavigationService } from '@src/navigation '
9+ import { TabNodes , nodeChildren } from '@src/helper/node '
1110
12- const Node = ( { route, navigation, loading } : ScreenProps ) => {
11+ const Node = ( { route, navigation } : ScreenProps ) => {
1312 const { theme } = useTheme ( )
13+
14+ const Item = ( { node } : { node : V2exObject . Node } ) => (
15+ < TouchableOpacity
16+ style = { styles . item ( theme ) }
17+ onPress = { ( ) => {
18+ NavigationService . goNodeTopics ( node . name , node . title )
19+ } } >
20+ < Text style = { SylCommon . Node . nodeTitle ( theme ) } > { node . title } </ Text >
21+ </ TouchableOpacity >
22+ )
23+
24+ const sectionData = ( ) => {
25+ return TabNodes . map ( ( node ) => ( {
26+ title : node . title ,
27+ data : nodeChildren ( node ) ,
28+ key : node . title
29+ } ) )
30+ }
31+
32+ const renderContent = ( ) => {
33+ return (
34+ < View style = { styles . container ( theme ) } >
35+ < SectionList
36+ sections = { sectionData ( ) }
37+ contentContainerStyle = { styles . listContainer ( theme ) }
38+ keyExtractor = { ( item , index ) => item . name + index }
39+ renderItem = { ( { item } ) => < Item node = { item } /> }
40+ stickySectionHeadersEnabled = { false }
41+ renderSectionHeader = { ( { section : { title } } ) => (
42+ < View style = { styles . section ( theme ) } >
43+ < Text style = { SylCommon . Node . sectionTitle ( theme ) } > { title } </ Text >
44+ </ View >
45+ ) }
46+ />
47+ </ View >
48+ )
49+ }
1450 return (
15- < View style = { [ SylCommon . Layout . fill , SylCommon . View . background ( theme ) ] } >
16- < Text > Hello, Node. </ Text >
51+ < View style = { [ SylCommon . Layout . fill , SylCommon . View . background ( theme ) , { alignItems : 'center' } ] } >
52+ { renderContent ( ) }
1753 </ View >
1854 )
1955}
@@ -23,20 +59,23 @@ const Node = ({ route, navigation, loading }: ScreenProps) => {
2359 */
2460const styles = {
2561 container : ( theme : ITheme ) : ViewStyle => ( {
62+ width : theme . dimens . WINDOW_WIDTH - 40 ,
2663 flex : 1
64+ } ) ,
65+ section : ( theme : ITheme ) => ( {
66+ width : styles . container ( theme ) . width ,
67+ paddingVertical : theme . spacing . medium
68+ } ) ,
69+ listContainer : ( theme : ITheme ) : ViewStyle => ( {
70+ flexDirection : 'row' ,
71+ flexWrap : 'wrap' ,
72+ justifyContent : 'flex-start'
73+ } ) ,
74+ item : ( theme : ITheme ) : ViewStyle => ( {
75+ width : 'auto' ,
76+ marginRight : theme . spacing . small ,
77+ marginVertical : theme . spacing . tiny
2778 } )
2879}
2980
30- /**
31- * default props
32- */
33- Node . defaultProps = {
34- loading : false
35- }
36-
37- const mapStateToProps = ( { ui : { login } } : { ui : IState . UIState } ) => {
38- const { error, success, loading } = login
39- return { error, success, loading }
40- }
41-
42- export default connect ( mapStateToProps ) ( Node )
81+ export default Node
0 commit comments