11// @flow
22import React from 'react'
33import { Text , ScrollView , StyleSheet , Share } from 'react-native'
4- import moment from 'moment-timezone'
54import { fastGetTrimmedText } from '../../lib/html'
65import { Cell , Section , TableView } from 'react-native-tableview-simple'
76import type { EventType } from './types'
@@ -15,52 +14,52 @@ const styles = StyleSheet.create({
1514} )
1615
1716const shareItem = ( event : EventType ) => {
18- Share . share ( {
19- message : `${ event . summary } : ${ event . startTime . toString ( ) } – ${ event . endTime . toString ( ) } ` ,
20- } )
17+ const message = `${ event . summary } : ${ event . startTime . toString ( ) } – ${ event . endTime . toString ( ) } `
18+ Share . share ( { message} )
2119 . then ( result => console . log ( result ) )
2220 . catch ( error => console . log ( error . message ) )
2321}
2422
25- function display ( title : string , data : string ) {
26- return data . trim ( )
27- ? < Section header = { title } >
23+ function MaybeSection ( { header , content } : { header : string , content : string } ) {
24+ return content . trim ( )
25+ ? < Section header = { header } >
2826 < Cell
29- cellContentView = {
27+ title = {
3028 < Text selectable = { true } style = { styles . chunk } >
31- { data }
29+ { content }
3230 </ Text >
3331 }
3432 />
3533 </ Section >
3634 : null
3735}
3836
39- function displayTimes ( title : string , event : EventType ) {
37+ function getTimes ( event : EventType ) {
4038 const { allDay, start, end} = times ( event )
4139
4240 if ( allDay ) {
43- return display ( title , 'All-Day' )
41+ return 'All-Day'
4442 }
4543
46- return display ( title , start + ' — ' + end )
44+ return ` ${ start } — ${ end } `
4745}
4846
4947export function EventDetail ( props : {
5048 navigation : { state : { params : { event : EventType } } } ,
5149} ) {
5250 const { event} = props . navigation . state . params
53- let title = fastGetTrimmedText ( event . summary || '' )
54- let summary = fastGetTrimmedText ( event . extra . data . description || '' )
55- let location = fastGetTrimmedText ( event . location || '' )
51+ const title = fastGetTrimmedText ( event . summary || '' )
52+ const summary = fastGetTrimmedText ( event . extra . data . description || '' )
53+ const location = fastGetTrimmedText ( event . location || '' )
54+ const times = getTimes ( event )
5655
5756 return (
5857 < ScrollView >
5958 < TableView >
60- { display ( ' EVENT' , title ) }
61- { displayTimes ( ' TIME' , event ) }
62- { display ( ' LOCATION' , location ) }
63- { display ( ' DESCRIPTION' , summary ) }
59+ < MaybeSection header = " EVENT" content = { title } />
60+ < MaybeSection header = " TIME" content = { times } />
61+ < MaybeSection header = " LOCATION" content = { location } />
62+ < MaybeSection header = " DESCRIPTION" content = { summary } />
6463 </ TableView >
6564 </ ScrollView >
6665 )
0 commit comments