@@ -5,43 +5,87 @@ import {
55 Text ,
66} from 'react-native'
77
8+ import moment from 'moment-timezone'
89import * as c from '../components/colors'
910import { getText , parseHtml } from '../../lib/html'
1011
1112let styles = StyleSheet . create ( {
1213 container : {
13- paddingTop : 10 ,
14- paddingBottom : 6 ,
14+ paddingVertical : 2 ,
15+ // paddingLeft: 10,
16+ flexDirection : 'row' ,
17+ } ,
18+ rowIllusion : {
19+ paddingVertical : 4 ,
20+ } ,
21+ times : {
22+ width : 70 ,
23+ flexDirection : 'column' ,
24+ justifyContent : 'space-between' ,
25+ paddingRight : 12 ,
26+ paddingLeft : 4 ,
27+ } ,
28+ timeText : {
29+ textAlign : 'right' ,
30+ fontSize : 10 ,
31+ } ,
32+ startTime : {
33+ // marginTop: 3,
34+ color : 'black' ,
35+ } ,
36+ endTime : {
37+ color : c . iosText ,
38+ } ,
39+ texts : {
1540 paddingLeft : 10 ,
41+ flex : 1 ,
42+ borderLeftWidth : 2 ,
43+ borderLeftColor : c . iosGray ,
1644 } ,
17- itemTitle : {
45+ title : {
1846 color : c . black ,
19- paddingBottom : 3 ,
20- fontSize : 16 ,
2147 fontWeight : '500' ,
48+ paddingBottom : 3 ,
49+ fontSize : 14 ,
2250 } ,
23- itemPreview : {
51+ location : {
2452 color : c . iosText ,
25- fontSize : 13 ,
53+ fontSize : 10 ,
2654 } ,
2755} )
2856
2957// PROPS: eventTitle, location, startTime, endTime
3058export default function EventView ( props : { eventTitle : string , location : string , startTime ?: Object , endTime ?: Object , style ?: any } ) {
3159 let title = getText ( parseHtml ( props . eventTitle ) )
3260
33- let showTimes = props . startTime && props . endTime
34- let showLocation = Boolean ( props . location )
61+ let eventLength = moment . duration ( props . endTime . diff ( props . startTime ) ) . asHours ( )
62+ let allDay = eventLength === 24
63+ let multiDay = eventLength > 24
64+
65+ let times = null
66+ if ( allDay ) {
67+ times = < Text style = { [ styles . timeText , styles . startTime ] } > all-day</ Text >
68+ } else if ( multiDay ) {
69+ times = [
70+ < Text key = { 0 } style = { [ styles . timeText , styles . startTime ] } > { props . startTime . format ( 'h:mma' ) } </ Text > ,
71+ < Text key = { 1 } style = { [ styles . timeText , styles . endTime ] } > to { props . endTime . format ( 'MMM. D h:mma' ) } </ Text > ,
72+ ]
73+ } else {
74+ times = [
75+ < Text key = { 0 } style = { [ styles . timeText , styles . startTime ] } > { props . startTime . format ( 'h:mma' ) } </ Text > ,
76+ < Text key = { 1 } style = { [ styles . timeText , styles . endTime ] } > { props . endTime . format ( 'h:mma' ) } </ Text > ,
77+ ]
78+ }
3579
3680 return (
3781 < View style = { [ styles . container , props . style ] } >
38- < Text style = { styles . itemTitle } > { title } </ Text >
39- { showTimes ? < Text style = { styles . itemPreview } >
40- { props . startTime . format ( 'M/D h:mma' ) } — { props . endTime . format ( 'M/D h:mma' ) }
41- </ Text > : null }
42- { showLocation ? < Text style = { styles . itemPreview } >
43- { props . location }
44- </ Text > : null }
82+ < View style = { [ styles . rowIllusion , styles . times ] } >
83+ { times }
84+ </ View >
85+ < View style = { [ styles . rowIllusion , styles . texts ] } >
86+ < Text style = { styles . title } > { title } </ Text >
87+ < Text style = { styles . location } > { props . location } </ Text >
88+ </ View >
4589 </ View >
4690 )
4791}
0 commit comments