Skip to content

Commit

Permalink
Update for geolocation update
Browse files Browse the repository at this point in the history
  • Loading branch information
chunlaw committed May 9, 2024
1 parent b148fde commit b5824bf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
"build": ". ./scripts/prebuild.sh; tsc && vite build",
"production-build": "yarn build && node scripts/sitemap-generator.js && node scripts/pre-rendering.js",
"render": "node scripts/pre-rendering.js",
"deploy": "yarn build && gh-pages -d build -t -f",
"full-deploy": "yarn production-build && gh-pages -d build -t -f",
"alpha-deploy": "yarn build && gh-pages -d build --remote alpha -t -f",
"alpha-full-deploy": "yarn production-build && gh-pages -d build --remote alpha -t -f",
"deploy": "yarn build && gh-pages -d build -t -f -a",
"full-deploy": "yarn production-build && gh-pages -d build -t -f -a",
"alpha-deploy": "yarn build && gh-pages -d build --remote alpha -t -f -a",
"alpha-full-deploy": "yarn production-build && gh-pages -d build --remote alpha -t -f -a",
"docker": "cd docker && docker-compose up -d --build",
"docker:build": "docker build . --pull --build-arg $(sed 's:#.*$::g' docker/.env | sed '/^\\s*$/d' | sed ':a;N;$!ba;s/\\n/ --build-arg /g')",
"docker:build-noenv": "docker build . --pull --build-arg $(sed 's:#.*$::g' .env | sed '/^\\s*$/d' | sed ':a;N;$!ba;s/\\n/ --build-arg /g')",
Expand Down
29 changes: 15 additions & 14 deletions src/context/AppContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -291,27 +291,28 @@ export const AppContextProvider = ({ children }: AppContextProviderProps) => {
}, []);

useEffect(() => {
if (geoPermission === "granted") {
try {
// @ts-expect-error don't use geolocation navigator for Webview
if (window.iOSRNWebView === true) return;
const _geoWatcherId = navigator.geolocation.watchPosition(
({ coords: { latitude, longitude } }) => {
updateGeolocation({ lat: latitude, lng: longitude });
}
);
geoWatcherId.current = _geoWatcherId;
} catch (e) {
console.error("cannot watch position", e);
}
}
const onVisibilityChange = () => {
if (geoPermission === "granted") {
try {
// @ts-expect-error don't use geolocation navigator for Webview
if (window.iOSRNWebView === true) return;
const _geoWatcherId = navigator.geolocation.watchPosition(
({ coords: { latitude, longitude } }) => {
updateGeolocation({ lat: latitude, lng: longitude });
}
);
geoWatcherId.current = _geoWatcherId;
} catch (e) {
console.error("cannot watch position", e);
}
}
setStateRaw(
produce((state: State) => {
state.isVisible = !document.hidden;
})
);
};
onVisibilityChange();
window.addEventListener("visibilitychange", onVisibilityChange);
return () => {
if (geoPermission === "granted" && geoWatcherId.current) {
Expand Down

0 comments on commit b5824bf

Please sign in to comment.