Skip to content

Commit

Permalink
feat: add timestamp prop to the wrapped component
Browse files Browse the repository at this point in the history
Adds support for the Geolocation API timestamp property and passes it to the wrapped component.

Fixes #734
  • Loading branch information
no23reason committed Apr 25, 2021
1 parent bc2e102 commit e110b08
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ The props passed to the wrapped component are:
heading,
speed,
},
timestamp, // timestamp of when the last position was retrieved
isGeolocationAvailable, // boolean flag indicating that the browser supports the Geolocation API
isGeolocationEnabled, // boolean flag indicating that the user has allowed the use of the Geolocation API
positionError, // object with the error returned from the Geolocation API call
Expand Down Expand Up @@ -167,7 +168,7 @@ class Demo extends React.Component<IDemoProps & GeolocatedProps> {
return (
<div>
label: {this.props.label}
lattitude: {this.props.coords && this.props.coords.latitude}
latitude: {this.props.coords && this.props.coords.latitude}
</div>
);
}
Expand Down
4 changes: 4 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ interface GeolocatedProps {
* The Geolocation API's coords object containing latitude, longitude, and accuracy and also optionally containing altitude, altitudeAccuracy, heading and speed.
*/
coords?: Coordinates;
/**
* The Geolocation API's timestamp value representing the time at which the location was retrieved.
*/
timestamp?: DOMTimeStamp;
/**
* Flag indicating that the browser supports the Geolocation API.
*/
Expand Down
3 changes: 3 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const geolocated = ({

state = {
coords: null,
timestamp: null,
isGeolocationAvailable: Boolean(geolocationProvider),
isGeolocationEnabled: isOptimisticGeolocationEnabled,
positionError: null,
Expand Down Expand Up @@ -54,6 +55,7 @@ export const geolocated = ({
if (this.isCurrentlyMounted) {
this.setState({
coords: position.coords,
timestamp: position.timestamp,
isGeolocationEnabled: true,
positionError: null,
});
Expand Down Expand Up @@ -127,6 +129,7 @@ export const geoPropTypes = {
heading: PropTypes.number,
speed: PropTypes.number,
}),
timestamp: PropTypes.number,
isGeolocationAvailable: PropTypes.bool,
isGeolocationEnabled: PropTypes.bool,
positionError: PropTypes.shape({
Expand Down
2 changes: 2 additions & 0 deletions tests/typescript/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ const StatelessDemo: React.FC<GeolocatedProps> = (props) => (
isGeolocationAvailable: {props.isGeolocationAvailable}
isGeolocationEnabled: {props.isGeolocationEnabled}
positionError: {props.positionError}
coords: {props.coords}
timestamp: {props.timestamp}
</div>
);

Expand Down

0 comments on commit e110b08

Please sign in to comment.