|
| 1 | +// @flow |
| 2 | +import React from 'react' |
| 3 | +import {Text, ScrollView, StyleSheet, Share} from 'react-native' |
| 4 | +import type {EventType} from './types' |
| 5 | +import {ShareButton} from '../components/nav-buttons' |
| 6 | +import openUrl from '../components/open-url' |
| 7 | +import {Card} from '../components/card' |
| 8 | +import {cleanEvent, getTimes, getLinksFromEvent} from './clean-event' |
| 9 | +import * as c from '../components/colors' |
| 10 | + |
| 11 | +const styles = StyleSheet.create({ |
| 12 | + name: { |
| 13 | + textAlign: 'center', |
| 14 | + marginTop: 20, |
| 15 | + marginBottom: 15, |
| 16 | + paddingHorizontal: 5, |
| 17 | + color: c.black, |
| 18 | + fontSize: 32, |
| 19 | + fontWeight: '300', |
| 20 | + }, |
| 21 | + card: { |
| 22 | + marginBottom: 20, |
| 23 | + }, |
| 24 | + cardBody: { |
| 25 | + color: c.black, |
| 26 | + paddingTop: 13, |
| 27 | + paddingBottom: 13, |
| 28 | + paddingLeft: 16, |
| 29 | + paddingRight: 16, |
| 30 | + fontSize: 16, |
| 31 | + }, |
| 32 | +}) |
| 33 | + |
| 34 | +function Title({event}: {event: EventType}) { |
| 35 | + return event.title ? <Text style={styles.name}>{event.title}</Text> : null |
| 36 | +} |
| 37 | + |
| 38 | +function Description({event}: {event: EventType}) { |
| 39 | + return event.rawSummary |
| 40 | + ? <Card header="Description" style={styles.card}> |
| 41 | + <Text style={styles.cardBody}> |
| 42 | + {event.rawSummary} |
| 43 | + </Text> |
| 44 | + </Card> |
| 45 | + : null |
| 46 | +} |
| 47 | + |
| 48 | +function When({event}: {event: EventType}) { |
| 49 | + return event.times |
| 50 | + ? <Card header="When" style={styles.card}> |
| 51 | + <Text style={styles.cardBody}> |
| 52 | + {event.times} |
| 53 | + </Text> |
| 54 | + </Card> |
| 55 | + : null |
| 56 | +} |
| 57 | + |
| 58 | +function Location({event}: {event: EventType}) { |
| 59 | + return event.location |
| 60 | + ? <Card header="Location" style={styles.card}> |
| 61 | + <Text style={styles.cardBody}> |
| 62 | + {event.location} |
| 63 | + </Text> |
| 64 | + </Card> |
| 65 | + : null |
| 66 | +} |
| 67 | + |
| 68 | +function Links({event}: {event: EventType}) { |
| 69 | + const links = getLinksFromEvent(event) |
| 70 | + return links.length |
| 71 | + ? <Card header="Links" style={styles.card}> |
| 72 | + {links.map(url => |
| 73 | + <Text key={url} style={styles.cardBody} onPress={() => openUrl(url)}> |
| 74 | + {url} |
| 75 | + </Text>, |
| 76 | + )} |
| 77 | + </Card> |
| 78 | + : null |
| 79 | +} |
| 80 | + |
| 81 | +const shareItem = (event: EventType) => { |
| 82 | + const times = getTimes(event) |
| 83 | + const message = `${event.summary}\n\n${times}\n\n${event.location}` |
| 84 | + Share.share({message}) |
| 85 | + .then(result => console.log(result)) |
| 86 | + .catch(error => console.log(error.message)) |
| 87 | +} |
| 88 | + |
| 89 | +export function EventDetail(props: { |
| 90 | + navigation: {state: {params: {event: EventType}}}, |
| 91 | +}) { |
| 92 | + const event = cleanEvent(props.navigation.state.params.event) |
| 93 | + return ( |
| 94 | + <ScrollView> |
| 95 | + <Title event={event} /> |
| 96 | + <When event={event} /> |
| 97 | + <Location event={event} /> |
| 98 | + <Description event={event} /> |
| 99 | + <Links event={event} /> |
| 100 | + </ScrollView> |
| 101 | + ) |
| 102 | +} |
| 103 | + |
| 104 | +EventDetail.navigationOptions = ({navigation}) => { |
| 105 | + const {event} = navigation.state.params |
| 106 | + return { |
| 107 | + title: event.summary, |
| 108 | + headerRight: <ShareButton onPress={() => shareItem(event)} />, |
| 109 | + } |
| 110 | +} |
0 commit comments