axelclark / metroAppIOS

A simple IOS app project that tells you when WMATA Metro trains arrive.
MIT License
1 stars 0 forks source link

Handle case where no trains are scheduled #26

Closed axelclark closed 6 years ago

axelclark commented 6 years ago

When no trains are scheduled, the app renders a blank area. The app should provide a message like "No trains scheduled".

axelclark commented 6 years ago
const Train = ({ train }) => (
  <View style={styles.container}>
    <Text style={styles.text}>{train.Name}</Text>
    <Text style={styles.text}>Destination: {train.DestinationName}</Text>
    <Text style={styles.text}>Arrival in {train.Min} minutes</Text>
  </View>
)

const TrainList = ({ trains }) => {
  if(trains !== []) {
    const renderTrains = trains.map(train =>
      (<Train
        key={`${train.DestinationCode}-${train.Min}`}
        train={train}
      />))

    return (
      <View>
        {renderTrains}
      </View>
    )
  } else {
    return (
      <View style={styles.container}>
        <Text style={styles.text}>No trains are currently scheduled</Text>
      </View>
    )
  }
}