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'
87import { ShareButton } from '../components/nav-buttons'
8+ import { times } from './times'
99
1010const styles = StyleSheet . create ( {
1111 chunk : {
@@ -14,73 +14,52 @@ const styles = StyleSheet.create({
1414} )
1515
1616const shareItem = ( event : EventType ) => {
17- Share . share ( {
18- message : `${ event . summary } : ${ event . startTime . toString ( ) } – ${ event . endTime . toString ( ) } ` ,
19- } )
17+ const message = `${ event . summary } : ${ event . startTime . toString ( ) } – ${ event . endTime . toString ( ) } `
18+ Share . share ( { message} )
2019 . then ( result => console . log ( result ) )
2120 . catch ( error => console . log ( error . message ) )
2221}
2322
24- function display ( title : string , data : string ) {
25- return data . trim ( )
26- ? < Section header = { title } >
23+ function MaybeSection ( { header , content } : { header : string , content : string } ) {
24+ return content . trim ( )
25+ ? < Section header = { header } >
2726 < Cell
28- cellContentView = {
27+ title = {
2928 < Text selectable = { true } style = { styles . chunk } >
30- { data }
29+ { content }
3130 </ Text >
3231 }
3332 />
3433 </ Section >
3534 : null
3635}
3736
38- function displayTimes ( title : string , event : EventType ) {
39- const eventLength = moment
40- . duration ( event . endTime . diff ( event . startTime ) )
41- . asHours ( )
42-
43- const allDay = eventLength === 24
44- const multiDay = event . startTime . dayOfYear ( ) !== event . endTime . dayOfYear ( )
45- const sillyZeroLength = event . startTime . isSame ( event . endTime , 'minute' )
37+ function getTimes ( event : EventType ) {
38+ const { allDay, start, end} = times ( event )
4639
4740 if ( allDay ) {
48- return display ( title , 'All-Day' )
49- }
50-
51- let start , end
52- if ( event . isOngoing ) {
53- start = event . startTime . format ( 'MMM. D' )
54- end = event . endTime . format ( 'MMM. D' )
55- } else if ( multiDay ) {
56- start = event . startTime . format ( 'h:mm A' )
57- end = `${ event . endTime . format ( 'MMM. D h:mm A' ) } `
58- } else if ( sillyZeroLength ) {
59- start = event . startTime . format ( 'h:mm A' )
60- end = '???'
61- } else {
62- start = event . startTime . format ( 'h:mm A' )
63- end = event . endTime . format ( 'h:mm A' )
41+ return 'All-Day'
6442 }
6543
66- return display ( title , start + ' — ' + end )
44+ return ` ${ start } — ${ end } `
6745}
6846
6947export function EventDetail ( props : {
7048 navigation : { state : { params : { event : EventType } } } ,
7149} ) {
7250 const { event} = props . navigation . state . params
73- let title = fastGetTrimmedText ( event . summary || '' )
74- let summary = fastGetTrimmedText ( event . extra . data . description || '' )
75- 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 )
7655
7756 return (
7857 < ScrollView >
7958 < TableView >
80- { display ( ' EVENT' , title ) }
81- { displayTimes ( ' TIME' , event ) }
82- { display ( ' LOCATION' , location ) }
83- { 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 } />
8463 </ TableView >
8564 </ ScrollView >
8665 )
0 commit comments