import * as React from 'react' ; import { Text } from 'react-native' ; import type { Moment } from 'moment' ; import type { UnprocessedBusLine } from './types' ; import { NoticeView } from '@frogpond/notice' ; import { getScheduleForNow , processBusLine } from './lib' ; import isEqual from 'lodash/isEqual' ; import { Timer } from '@frogpond/timer' ; import { timezone } from '@frogpond/constants' ; type WrapperProps = { navigation : { state : { params : { line : UnprocessedBusLine ; } ; } ; } ; } ; export function BusMap ( props ) { let lineToDisplay = props . navigation . state . params . line ; return ( < Timer interval = { 60000 } moment = { true } render = { ( { now } ) => < Map line = { lineToDisplay } now = { now } / > } timezone = { timezone ( ) } / > ) ; } type Props = { line : UnprocessedBusLine ; now : Moment ; } ; type State = { region : { latitude : number ; latitudeDelta : number ; longitude : number ; longitudeDelta : number ; } ; } ; class Map extends React . Component < Props , State > { static navigationOptions = ( args ) => ( { title : `${ args . navigation . state . params . line . line } Map` , } ) ; state = { region : { latitude : 44.44946671480875 , latitudeDelta : 0.06175530810822494 , longitude : - 93.17014753996669 , longitudeDelta : 0.05493163793703104 , } , } ; onRegionChangeComplete = ( newRegion ) => { this . setState ( ( state ) => { if ( isEqual ( state . region , newRegion ) ) { return ; } return { region : newRegion } ; } ) ; } ; render ( ) { let lineToDisplay = this . props . line ; let now = this . props . now ; let processedLine = processBusLine ( lineToDisplay , now ) ; let scheduleForToday = getScheduleForNow ( processedLine . schedules , now ) ; if ( ! scheduleForToday ) { let notice = `No schedule was found for today, ${ now . format ( 'dddd' ) }` ; return < NoticeView text = { notice } />; } let entriesWithCoordinates = scheduleForToday . timetable . filter ( ( entry ) => entry . coordinates ) ; if ( ! entriesWithCoordinates . length ) { let today = now . format ( 'dddd' ) ; let msg = `No coordinates have been provided for today's (${ today }) schedule on the "${ lineToDisplay . line }" line` ; return < NoticeView text = { msg } />; } return < Text > Mapbox has been removed . < /Text>; } }