-
Notifications
You must be signed in to change notification settings - Fork 17
Claude/fix waze api integration wf1 x8 #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
0671c4a
6fd6ec9
de30648
0c52d9b
9e25104
a3e91e5
2db95c4
ca2c098
2831ced
118da05
7d488a1
8664968
474e955
35078c6
1d1dfff
9a03e68
6f474c4
6c27adf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ interface GeolocationState { | |
| // Calculated/interpolated values for smooth animation | ||
| calculatedHeading: number | null; | ||
| timestamp: number | null; | ||
| permissionDenied: boolean; | ||
| } | ||
|
|
||
| // Calculate bearing between two points in degrees (0-360, where 0 is north) | ||
|
|
@@ -85,6 +86,7 @@ export function useGeolocation(enableHighAccuracy = true) { | |
| loading: true, | ||
| calculatedHeading: null, | ||
| timestamp: null, | ||
| permissionDenied: false, | ||
| }); | ||
|
|
||
| const [watchId, setWatchId] = useState<number | null>(null); | ||
|
|
@@ -155,14 +157,28 @@ export function useGeolocation(enableHighAccuracy = true) { | |
| loading: false, | ||
| calculatedHeading, | ||
| timestamp, | ||
| permissionDenied: false, | ||
| }); | ||
| }, []); | ||
|
|
||
| const handleError = useCallback((error: GeolocationPositionError) => { | ||
| let errorMsg = error.message; | ||
| const isPermissionDenied = error.code === 1; | ||
|
|
||
| // Provide more helpful error messages | ||
| if (error.code === 1) { | ||
| errorMsg = "Location access denied. Tap 'Request Permission' to try again."; | ||
| } else if (error.code === 2) { | ||
| errorMsg = "Location unavailable. Please ensure geolocation is enabled."; | ||
| } else if (error.code === 3) { | ||
| errorMsg = "Location request timed out. Please try again."; | ||
| } | ||
|
|
||
| setState((prev) => ({ | ||
| ...prev, | ||
| error: error.message, | ||
| error: errorMsg, | ||
| loading: false, | ||
| permissionDenied: isPermissionDenied, | ||
| })); | ||
|
|
||
| // Track geolocation error | ||
|
|
@@ -178,6 +194,20 @@ export function useGeolocation(enableHighAccuracy = true) { | |
| ...prev, | ||
| error: "Geolocation is not supported", | ||
| loading: false, | ||
| permissionDenied: false, | ||
| })); | ||
| return; | ||
| } | ||
|
|
||
| // Check if page is HTTPS or localhost (geolocation requires secure context) | ||
| const isSecureContext = window.location.protocol === 'https:' || window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1'; | ||
|
|
||
| if (!isSecureContext) { | ||
| setState((prev) => ({ | ||
| ...prev, | ||
| error: "Geolocation requires HTTPS. Please access this site over HTTPS.", | ||
| loading: false, | ||
| permissionDenied: false, | ||
| })); | ||
| return; | ||
| } | ||
|
|
@@ -209,14 +239,57 @@ export function useGeolocation(enableHighAccuracy = true) { | |
| } | ||
| }, [watchId]); | ||
|
|
||
| // Request permission manually (for when user taps "Request Permission") | ||
| const requestPermission = useCallback(() => { | ||
| if (!navigator.geolocation) { | ||
| setState((prev) => ({ | ||
| ...prev, | ||
| error: "Geolocation is not supported", | ||
| loading: false, | ||
| permissionDenied: false, | ||
| })); | ||
| return; | ||
| } | ||
|
|
||
| // Check if page is HTTPS or localhost (geolocation requires secure context) | ||
| const isSecureContext = window.location.protocol === 'https:' || window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1'; | ||
|
|
||
| if (!isSecureContext) { | ||
| setState((prev) => ({ | ||
| ...prev, | ||
| error: "Geolocation requires HTTPS. Please access this site over HTTPS.", | ||
| loading: false, | ||
| permissionDenied: false, | ||
| })); | ||
| return; | ||
| } | ||
|
|
||
| setState((prev) => ({ | ||
| ...prev, | ||
| loading: true, | ||
| error: null, | ||
| permissionDenied: false, | ||
| })); | ||
|
|
||
| const options: PositionOptions = { | ||
| enableHighAccuracy, | ||
| timeout: 10000, | ||
| maximumAge: 0, | ||
| }; | ||
|
|
||
| // Request position - this triggers the permission prompt | ||
| navigator.geolocation.getCurrentPosition(updatePosition, handleError, options); | ||
| }, [enableHighAccuracy, updatePosition, handleError]); | ||
|
Comment on lines
+242
to
+268
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Verify current retry behavior is one-shot and where watchPosition is established.
rg -nP 'const requestPermission|getCurrentPosition|watchPosition|setWatchId' hooks/useGeolocation.ts -C3Repository: R44VC0RP/teslanav.com Length of output: 1433 Re-enable continuous tracking after manual permission retry. The 💡 Suggested fix const requestPermission = useCallback(() => {
@@
// Request position - this triggers the permission prompt
- navigator.geolocation.getCurrentPosition(updatePosition, handleError, options);
- }, [enableHighAccuracy, updatePosition, handleError]);
+ navigator.geolocation.getCurrentPosition(
+ (position) => {
+ updatePosition(position);
+ // Ensure continuous updates resume after a successful retry
+ if (watchId === null) {
+ const id = navigator.geolocation.watchPosition(updatePosition, handleError, options);
+ setWatchId(id);
+ }
+ },
+ handleError,
+ options
+ );
+ }, [enableHighAccuracy, updatePosition, handleError, watchId]);🤖 Prompt for AI Agents |
||
|
|
||
| // Return the best available heading (GPS heading if moving fast enough, otherwise calculated) | ||
| const bestHeading = state.heading !== null && state.speed !== null && state.speed > MIN_SPEED_FOR_HEADING | ||
| ? state.heading | ||
| : state.calculatedHeading; | ||
|
|
||
| return { | ||
| ...state, | ||
| return { | ||
| ...state, | ||
| stopWatching, | ||
| requestPermission, | ||
| // Provide the best heading source | ||
| effectiveHeading: bestHeading, | ||
| }; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add an in-place retry action for non-permission geolocation errors.
Timeout/unavailable errors are often transient, but this branch only shows instructions. Add a retry button here too, so users can recover without navigation.
💡 Suggested fix
{!permissionDenied && ( <div className="bg-blue-50 border border-blue-200 rounded-lg p-4 text-left text-sm text-blue-900"> <p className="font-semibold mb-2">How to fix:</p> <ul className="list-disc list-inside space-y-1"> <li>Ensure you're using HTTPS</li> <li>Check browser location permissions</li> <li>Allow location access when prompted</li> <li>Restart your browser and try again</li> </ul> + <button + onClick={requestPermission} + className="mt-4 w-full px-4 py-3 bg-blue-500 hover:bg-blue-600 text-white font-semibold rounded-lg transition-colors" + > + Try Again + </button> </div> )}📝 Committable suggestion
🤖 Prompt for AI Agents