Skip to content
This repository has been archived by the owner on May 13, 2024. It is now read-only.

Commit

Permalink
Merge pull request #247 from brave/c71-clock-period
Browse files Browse the repository at this point in the history
Fix NTP clock for c71
  • Loading branch information
petemill authored Dec 11, 2018
2 parents 69a3399 + 20d2a61 commit dd46eab
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/old/clock/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,20 @@ export interface ClockProps {
customStyle?: ClockTheme
}

interface TimeComponent {
type: string,
value: string
}

export interface ClockState {
currentTime: Array<{type: string, value: string}>
currentTime: Array<TimeComponent>
date: Date
}

function isDayPeriod (timeComponent: TimeComponent): boolean {
return timeComponent.type.toLowerCase() === 'dayperiod'
}

class Clock extends React.PureComponent<ClockProps, ClockState> {
constructor (props: ClockProps) {
super(props)
Expand All @@ -44,7 +53,7 @@ class Clock extends React.PureComponent<ClockProps, ClockState> {
// hide blank strings
return null
}
} else if (component.type === 'dayperiod') {
} else if (isDayPeriod(component)) {
// hide day-period (AM / PM), it's rendered in a separate component
return null
}
Expand All @@ -54,7 +63,7 @@ class Clock extends React.PureComponent<ClockProps, ClockState> {

get formattedTimePeriod () {
const time: any = this.state.currentTime
const period = time.find((component: {type: string}) => component.type === 'dayperiod')
const period = time.find(isDayPeriod)
return period ? period.value : ''
}

Expand Down
6 changes: 6 additions & 0 deletions stories/old/views.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import * as React from 'react'
// TBD import Clock from '../components/clock'
import Page from '../../src/old/page'
import { DataBlock, DataItem } from '../../src/old/dataBlock'
import Clock from '../../src/old/clock'

storiesOf('Old/Views', module)
.addDecorator(withKnobs)
Expand Down Expand Up @@ -73,3 +74,8 @@ storiesOf('Old/Views', module)
</DataBlock>
)
})
.add('Clock', () => {
return (
<Clock />
)
})

0 comments on commit dd46eab

Please sign in to comment.