Skip to content

Conversation

@DeveloperAmrit
Copy link

@DeveloperAmrit DeveloperAmrit commented Dec 29, 2025

Closes #138

📝 Description

🔧 Changes Made

📷 Screenshots or Visual Changes (if applicable)

🤝 Collaboration

Collaborated with: @username (optional)

✅ Checklist

  • [ y] I have read the contributing guidelines.
  • [y ] I have added tests that prove my fix is effective or that my feature works.
  • [ y] I have added necessary documentation (if applicable).
  • [y ] Any dependent changes have been merged and published in downstream modules.

Summary by CodeRabbit

  • New Features
    • Added automatic country detection using device location.
    • Added searchable country selection in the basic details screen.
    • Added location permission requests for Android and iOS to support location-based features.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 29, 2025

📝 Walkthrough

Walkthrough

The changes implement automatic location detection to auto-fill the country field during user registration. Location permissions are added for both iOS and Android platforms, the geolocation service dependency is introduced, location detection logic with error handling is implemented in the registration screen, and a country search feature enables manual selection if location access is denied.

Changes

Cohort / File(s) Summary
Platform Permissions
Frontend/android/app/src/main/AndroidManifest.xml, Frontend/ios/BabyNest/Info.plist
Added ACCESS_FINE_LOCATION and ACCESS_COARSE_LOCATION Android permissions; updated iOS location usage description to "We need your location to automatically detect your country."
Dependencies
Frontend/package.json, package.json
Added react-native-geolocation-service@^5.3.1 to Frontend dependencies; root package.json created as empty file.
Location Detection Implementation
Frontend/src/Screens/BasicDetailsScreen.jsx
Integrated location detection with requestLocationPermission and detectLocation flows; added loading state and error handling for location fetch and reverse geocoding; implemented country search/filtering with searchQuery state and modal TextInput; triggers auto-detection on component mount via useEffect.
Test Data
Backend/cache/context_default.json
Updated cached user session metadata: current_week (3), location (Australia), age (30), weight (65), due_date (2026-09-17), lmp (2025-12-11); refreshed last_updated timestamp.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 A location request takes flight,
From coordinates to country's light,
Permissions asked on Android, iOS too,
Geolocation finds what home means for you!
And if the signal's shy, a search will do,
No more scrolling—the form fills through! 🌍

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title mentions adding auto-fill and search country features, which aligns with the main changes but contains a typo ('featueres' instead of 'features') and is slightly redundant ('Added auto fill country and search country').
Linked Issues check ✅ Passed All coding requirements from issue #138 are met: location permissions added (Android/iOS), auto-detection implemented with reverse geocoding, fallback search mechanism added, and location-based country pre-filling in BasicDetailsScreen.
Out of Scope Changes check ✅ Passed All changes are directly related to issue #138 objectives. The cache update reflects test data, and package.json appears to be a minor configuration file with no substantive impact.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
Frontend/src/Screens/BasicDetailsScreen.jsx (1)

170-174: Reset searchQuery when country is selected or modal is closed.

The searchQuery state persists after selection or cancellation, so reopening the modal shows filtered results from the previous search instead of the full list.

🔎 Proposed fix
 const handleSelectCountry = selectedCountry => {
   setCountry(selectedCountry);
   setShowCountryModal(false);
+  setSearchQuery('');
   setErrors(prev => ({...prev, country: ''}));
 };

Also update the cancel button handler:

onPress={() => {
  setShowCountryModal(false);
  setSearchQuery('');
}}
🧹 Nitpick comments (2)
Frontend/android/app/src/main/AndroidManifest.xml (1)

4-5: Consider whether ACCESS_FINE_LOCATION is necessary.

For country detection, ACCESS_COARSE_LOCATION alone would typically suffice and is more privacy-friendly. The code currently uses enableHighAccuracy: true, which requires fine location. If precise GPS coordinates aren't needed for reverse geocoding to country level, consider removing ACCESS_FINE_LOCATION and setting enableHighAccuracy: false to request only approximate location.

Frontend/src/Screens/BasicDetailsScreen.jsx (1)

102-106: Minor: Use console.error for error logging consistency.

Line 103 uses console.log while line 96 uses console.error. For consistency and proper error severity in logs, consider using console.error here as well.

🔎 Proposed fix
       error => {
-        console.log(error.code, error.message);
+        console.error('Geolocation error:', error.code, error.message);
         setErrors(prev => ({...prev, country: 'Error getting location'}));
         setLoadingLocation(false);
       },
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c2d9f82 and 4d110be.

⛔ Files ignored due to path filters (3)
  • Frontend/ios/Podfile.lock is excluded by !**/*.lock
  • Frontend/package-lock.json is excluded by !**/package-lock.json
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (6)
  • Backend/cache/context_default.json
  • Frontend/android/app/src/main/AndroidManifest.xml
  • Frontend/ios/BabyNest/Info.plist
  • Frontend/package.json
  • Frontend/src/Screens/BasicDetailsScreen.jsx
  • package.json
🧰 Additional context used
🧬 Code graph analysis (1)
Frontend/src/Screens/BasicDetailsScreen.jsx (1)
Frontend/src/data/countries.js (2)
  • countries (1-23)
  • countries (1-23)
🔇 Additional comments (8)
Backend/cache/context_default.json (1)

2-7: Verify if these are intended default values or leftover test data.

The updated values (location: "Australia", age: 30, weight: 65, due_date: "2026-09-17", lmp: "2025-12-11") appear to be from a testing session rather than meaningful defaults. Consider resetting to neutral placeholder values or documenting why these specific values are the intended defaults.

Frontend/ios/BabyNest/Info.plist (1)

34-35: LGTM!

The location usage description is clear and appropriately scoped. Using NSLocationWhenInUseUsageDescription (foreground-only) is the correct choice since the app only needs location during registration for country detection.

Frontend/src/Screens/BasicDetailsScreen.jsx (5)

1-1: LGTM on imports.

The necessary imports for location functionality are correctly added.


40-42: LGTM on mount effect.

The useEffect correctly triggers location detection once on component mount. The empty dependency array is appropriate here.


193-197: LGTM on loading indicator.

The conditional rendering logic correctly shows the spinner during location detection and the dropdown arrow otherwise.


396-403: LGTM on search input styling.

The styling is consistent with the existing input styles in the component.


44-49: No action required. The Geolocation.requestAuthorization('whenInUse') call on iOS correctly returns 'granted' when the user permits location access, so the permission check is properly implemented.

Likely an incorrect or invalid review comment.

Frontend/package.json (1)

33-33: Use the latest stable version of the geolocation service.

The react-native-geolocation-service version 5.3.1 is the latest stable release and has no known security vulnerabilities. Ensure pod install is run for iOS and that native linking is properly configured.

Comment on lines +89 to +94
if (data && data.address && data.address.country) {
setCountry(data.address.country);
setErrors(prev => ({...prev, country: ''}));
} else {
setErrors(prev => ({...prev, country: 'Could not detect country'}));
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Country name mismatch risk with local countries list.

Nominatim may return country names that don't exactly match the entries in your countries array (e.g., "United States of America" vs "United States", "United Kingdom of Great Britain and Northern Ireland" vs "United Kingdom"). This could cause form validation issues since handleContinue checks country.trim() but doesn't validate against the allowed list.

Consider normalizing the returned country name or finding the closest match in the countries array:

🔎 Proposed fix to match against countries list
 if (data && data.address && data.address.country) {
-  setCountry(data.address.country);
-  setErrors(prev => ({...prev, country: ''}));
+  const detectedCountry = data.address.country;
+  // Find exact or partial match in countries list
+  const matchedCountry = countries.find(
+    c => c.toLowerCase() === detectedCountry.toLowerCase()
+  ) || countries.find(
+    c => detectedCountry.toLowerCase().includes(c.toLowerCase()) ||
+         c.toLowerCase().includes(detectedCountry.toLowerCase())
+  );
+  if (matchedCountry) {
+    setCountry(matchedCountry);
+    setErrors(prev => ({...prev, country: ''}));
+  } else {
+    setErrors(prev => ({...prev, country: 'Please select your country manually'}));
+  }
 } else {
🤖 Prompt for AI Agents
In Frontend/src/Screens/BasicDetailsScreen.jsx around lines 89-94, the country
returned by Nominatim may not exactly match entries in your local countries
array which can break validation; instead of setting the raw returned country
string, normalize and resolve it to an allowed country before calling setCountry
— e.g., trim and compare case-insensitively, try exact match first, then try
startsWith/contains matches or a small normalization map (handle common variants
like "United States of America" -> "United States", "United Kingdom of Great
Britain and Northern Ireland" -> "United Kingdom"), and as a fallback run a
fuzzy/Levenshtein or report “Could not detect country” via setErrors if no
confident match is found.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FEATURE REQUEST: Automatically detecting user's location to mark her country during login

1 participant