Skip to content
This repository has been archived by the owner on Feb 2, 2021. It is now read-only.

Commit

Permalink
fix: smaller UI cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
coderbyheart committed Jul 31, 2019
1 parent 0a14e04 commit fa713f3
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 32 deletions.
71 changes: 44 additions & 27 deletions src/Cat/Cat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,31 @@ const ReportedTime = ({
}: {
reportedAt: string
receivedAt: Date
}) => (
<>
<TimeIcon /> <RelativeTime ts={reportedAt} key={reportedAt} />
{(receivedAt.getTime() - new Date(reportedAt).getTime()) / 1000 > 300 && (
}) => {
try {
const r = new Date(reportedAt)
return (
<>
<TimeIcon /> <RelativeTime ts={r} key={r.toISOString()} />
{(receivedAt.getTime() - new Date(reportedAt).getTime()) / 1000 >
300 && (
<>
{' '}
<CloudIcon />{' '}
<RelativeTime ts={receivedAt} key={receivedAt.toISOString()} />
</>
)}
</>
)
} catch {
return (
<>
{' '}
<CloudIcon />{' '}
<RelativeTime
ts={receivedAt.toISOString()}
key={receivedAt.toISOString()}
/>
<RelativeTime ts={receivedAt} key={receivedAt.toISOString()} />
</>
)}
</>
)
)
}
}

const ShowCat = ({
catId,
Expand Down Expand Up @@ -153,17 +163,22 @@ const ShowCat = ({
if (error) return <Error error={error} />
return (
<>
{reported.gps && (
<Map
position={{
lat: reported.gps.v.lat.value as number,
lng: reported.gps.v.lng.value as number,
}}
accuracy={reported.gps.v.acc.value as number}
heading={reported.gps.v.hdg.value as number}
label={catId}
/>
)}
{reported.gps &&
reported.gps.v &&
reported.gps.v.lat &&
reported.gps.v.lng && (
<Map
position={{
lat: reported.gps.v.lat.value as number,
lng: reported.gps.v.lng.value as number,
}}
accuracy={
reported.gps.v.acc && (reported.gps.v.acc.value as number)
}
heading={reported.gps.v.hdg && (reported.gps.v.hdg.value as number)}
label={catId}
/>
)}
<Card>
<CardHeader className={'cat'}>
<AvatarPicker
Expand Down Expand Up @@ -240,10 +255,12 @@ const ShowCat = ({
({ value }: { value: number }) => value,
)}
/>
<ReportedTime
reportedAt={reported.acc.ts.value}
receivedAt={reported.acc.v[0].receivedAt}
/>
<small>
<ReportedTime
reportedAt={reported.acc.ts.value}
receivedAt={reported.acc.v[0].receivedAt}
/>
</small>
</dd>
</>
)}
Expand Down
2 changes: 1 addition & 1 deletion src/Map/Map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const Map = ({
<Popup>{label}</Popup>
</Marker>
{accuracy && <Circle center={[lat, lng]} radius={accuracy} />}
{heading !== undefined && heading !== null && (
{heading && (
<LeafletConsumer>
{({ map }) => {
if (map) {
Expand Down
8 changes: 4 additions & 4 deletions src/RelativeTime/RelativeTime.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React, { useState, useEffect } from 'react'
import moment from 'moment'

const getDiffInSeconds = (ts: string) =>
(Date.now() - new Date(ts).getTime()) / 1000
const getDiffInSeconds = (ts: Date) =>
(Date.now() - ts.getTime()) / 1000

export const RelativeTime = ({ ts }: { ts: string }) => {
export const RelativeTime = ({ ts }: { ts: Date }) => {
const [label, setLabel] = useState(moment(ts).fromNow())
const [diffInSeconds, setDiffInSeconds] = useState(getDiffInSeconds(ts))

Expand All @@ -28,5 +28,5 @@ export const RelativeTime = ({ ts }: { ts: string }) => {
}
}, [diffInSeconds, ts])

return <time dateTime={ts}>{label}</time>
return <time dateTime={ts.toISOString()}>{label}</time>
}

0 comments on commit fa713f3

Please sign in to comment.