From 8e74f078456450024e6555cfc6f03e97ff12fc6b Mon Sep 17 00:00:00 2001 From: Oleksii Trekhleb Date: Tue, 26 Oct 2021 19:42:39 +0200 Subject: [PATCH] Add heading to Storybook. --- README.md | 8 +++---- demo/Demo.js | 4 +++- tests/__snapshots__/usePosition.test.js.snap | 25 +++++++++++++++++--- tests/usePosition.test.js | 1 + 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index fd018c7..c76f7e0 100644 --- a/README.md +++ b/README.md @@ -77,7 +77,7 @@ const { accuracy, heading, error, -} = usePosition(watch, {enableHighAccuracy: true}); +} = usePosition(watch, { enableHighAccuracy: true }); ``` ### Full example @@ -104,8 +104,8 @@ export const Demo = () => { longitude: {longitude}
speed: {speed}
timestamp: {timestamp}
- accuracy: {accuracy && `${accuracy}m`}
- heading: {heading && `${heading} degree`}
+ accuracy: {accuracy && `${accuracy} meters`}
+ heading: {heading && `${heading} degrees`}
error: {error} ); @@ -129,5 +129,5 @@ export const Demo = () => { - `speed: number | null` - velocity of the device in meters per second (i.e. `2.5`), - `timestamp: number` - timestamp when location was detected (i.e. `1561815013194`), - `accuracy: number` - location accuracy in meters (i.e. `24`), -- `heading: number | null` - this value, specified in degrees, indicates how far off from heading due north the device is +- `heading: number | null` - direction in which the device is traveling, in degrees (`0` degrees - north, `90` degrees - east, `270` degrees - west, and so on), - `error: string` - error message or `null` (i.e. `User denied Geolocation`) diff --git a/demo/Demo.js b/demo/Demo.js index 918f4fb..03da549 100644 --- a/demo/Demo.js +++ b/demo/Demo.js @@ -9,6 +9,7 @@ export const Demo = ({watch, settings}) => { timestamp, accuracy, speed, + heading, error, } = usePosition(watch, settings); @@ -26,8 +27,9 @@ export const Demo = ({watch, settings}) => { latitude: {latitude}
longitude: {longitude}
timestamp: {timestamp}
- accuracy: {accuracy && `${accuracy}m`}
+ accuracy: {accuracy && `${accuracy} meters`}
speed: {speed}
+ heading: {heading && `${heading} degrees`}
error: {error} diff --git a/tests/__snapshots__/usePosition.test.js.snap b/tests/__snapshots__/usePosition.test.js.snap index 80dbd47..bd196c4 100644 --- a/tests/__snapshots__/usePosition.test.js.snap +++ b/tests/__snapshots__/usePosition.test.js.snap @@ -17,6 +17,8 @@ Array [
speed:
+ heading: +
error: , ] @@ -34,6 +36,8 @@ exports[`usePosition should return empty values by default in watching mode 1`]
speed:
+ heading: +
error: Geolocation is not supported @@ -51,6 +55,8 @@ exports[`usePosition should return error if navigator is not supported 1`] = `
speed:
+ heading: +
error: Geolocation is not supported @@ -68,6 +74,8 @@ exports[`usePosition should return error while fetching 1`] = `
speed:
+ heading: +
error: User denied Geolocation @@ -85,6 +93,8 @@ exports[`usePosition should return error while watching 1`] = `
speed:
+ heading: +
error: User denied Geolocation @@ -102,11 +112,14 @@ exports[`usePosition should return latitude and longitude even if watch is undef 1561815013194
accuracy: - 24m + 24 meters
speed: 0
+ heading: + 90 degrees +
error: `; @@ -123,11 +136,14 @@ exports[`usePosition should return latitude and longitude while fetching 1`] = ` 1561815013194
accuracy: - 24m + 24 meters
speed: 0
+ heading: + 90 degrees +
error: `; @@ -144,11 +160,14 @@ exports[`usePosition should return latitude and longitude while watching 1`] = ` 1561815013194
accuracy: - 24m + 24 meters
speed: 0
+ heading: + 90 degrees +
error: `; diff --git a/tests/usePosition.test.js b/tests/usePosition.test.js index 6cf9d2b..951e20f 100644 --- a/tests/usePosition.test.js +++ b/tests/usePosition.test.js @@ -7,6 +7,7 @@ const mockPosition = { latitude: 52.3172414, longitude: 4.8717809, accuracy: 24, + heading: 90, speed: 0, }, timestamp: 1561815013194,