Skip to content

Commit

Permalink
Fix Twenty Four Hour Setting
Browse files Browse the repository at this point in the history
  • Loading branch information
consindo committed Feb 8, 2020
1 parent 48b967f commit a2c4170
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 12 deletions.
9 changes: 4 additions & 5 deletions js/stores/SettingsStore.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
class SettingsStore {
constructor() {
this.state = {
clock: true,
longName: false,
isTwentyFourHour: false,
lastLocation: [-36.844229, 174.767823], // britomart
bikeShare: false,
}
if (localStorage.getItem('SettingsData')) {
const preState = JSON.parse(localStorage.getItem('SettingsData'))
// copies saved state, preserves defaults
for (const attrname in preState) {
this.state[attrname] = preState[attrname]
}
Object.keys(preState).forEach(attr => {
this.state[attr] = preState[attr]
})
}
localStorage.setItem('AppVersion', '2.4.6')
}
Expand Down
3 changes: 3 additions & 0 deletions js/views/lines/Line.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { withRouter } from 'react-router'
import queryString from 'query-string'

import { vars } from '../../styles.js'
import SettingsStore from '../../stores/SettingsStore.js'
import UiStore from '../../stores/UiStore.js'
import Header from '../reusable/Header.jsx'
import Spinner from '../reusable/Spinner.jsx'
Expand Down Expand Up @@ -447,6 +448,7 @@ class Line extends React.Component {
realtimeStopUpdates={realtimeStopUpdates}
triggerTrip={this.triggerTrip}
region={match.params.region}
isTwentyFourHour={SettingsStore.state.isTwentyFourHour}
/>
) : null
const lineStops = loading ? (
Expand All @@ -465,6 +467,7 @@ class Line extends React.Component {
selectedStop={this.lineData.stop_id}
currentTrip={currentTrip}
realtimeStopUpdates={realtimeStopUpdates}
isTwentyFourHour={SettingsStore.state.isTwentyFourHour}
/>
</>
)
Expand Down
8 changes: 5 additions & 3 deletions js/views/lines/LineStops.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { Fragment, useState } from 'react'
import React, { useState } from 'react'
import { Text, View, StyleSheet, TouchableOpacity } from 'react-native'

import { vars } from '../../styles.js'
Expand All @@ -15,6 +15,7 @@ export const LineStops = ({
currentTrip = '',
selectedStop = null,
realtimeStopUpdates = {},
isTwentyFourHour = false,
}) => {
const stopStyle = [styles.stop, { borderColor: color }]
const [showAll, setShowAll] = useState(false)
Expand Down Expand Up @@ -59,7 +60,7 @@ export const LineStops = ({
comparisionStopTime.setSeconds(0) // so it makes more sense in the UI

return (
<Fragment>
<>
{!showAll && selectedStopIndex > 0 ? (
<TouchableOpacity
onClick={() => setShowAll(true)}
Expand Down Expand Up @@ -160,6 +161,7 @@ export const LineStops = ({
delay * 1000
).toLocaleTimeString(navigator.language, {
timeZone: 'UTC',
hour12: !isTwentyFourHour,
hour: 'numeric',
minute: 'numeric',
})}
Expand All @@ -170,7 +172,7 @@ export const LineStops = ({
)
})}
</View>
</Fragment>
</>
)
}

Expand Down
12 changes: 9 additions & 3 deletions js/views/lines/Timetable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import { vars } from '../../styles.js'

import { getTime } from '../../helpers/date.js'

const formatDate = (dateString, delay, region) => {
const formatDate = (dateString, delay, isTwentyFourHour, region) => {
const date = new Date(dateString)
date.setTime(date.getTime() + delay * 1000)
const humanTime = getTime(date, false, true, region)
const humanTime = getTime(date, isTwentyFourHour, true, region)

// make this nicer
return `${humanTime.text || ''}${humanTime.subtext || ''}${
Expand All @@ -25,6 +25,7 @@ const Timetable = ({
triggerTrip,
realtimeStopUpdates,
region,
isTwentyFourHour = false,
}) => {
const tripIds = {}
return (
Expand Down Expand Up @@ -99,7 +100,12 @@ const Timetable = ({
onPress={triggerTrip(service.trip_id)}
>
<Text style={[styles.departureDate, departureTextStyle]}>
{formatDate(service.departure_time, delay, region)}
{formatDate(
service.departure_time,
delay,
isTwentyFourHour,
region
)}
</Text>
<Text style={[styles.departureStatus, emotion]}>
{scheduleRelationship}
Expand Down
2 changes: 1 addition & 1 deletion js/views/pages/Settings.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const Settings = () => {
<Text style={paragraphStyles.h1}>
{t('settings.preferences.title')}
</Text>
<Toggle id="clock">
<Toggle id="isTwentyFourHour">
<ClockIcon />
<Text style={styles.buttonText}>{t('settings.preferences.hrs')}</Text>
</Toggle>
Expand Down
1 change: 1 addition & 0 deletions js/views/station/Station.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ class Station extends React.Component {
isRealtime: i.isRealtime,
platform: i.platform,
}))}
isTwentyFourHour={SettingsStore.state.isTwentyFourHour}
onClick={() =>
this.triggerMap(
agencyId,
Expand Down

0 comments on commit a2c4170

Please sign in to comment.