Skip to content

Improve Map View UX and Refactor React Services#172

Merged
kargig merged 6 commits intomainfrom
feature/fix_react_violations
Jan 26, 2026
Merged

Improve Map View UX and Refactor React Services#172
kargig merged 6 commits intomainfrom
feature/fix_react_violations

Conversation

@kargig
Copy link
Owner

@kargig kargig commented Jan 26, 2026

Summary

This pull request introduces significant User Experience (UX) improvements to the interactive map, specifically targeting mobile usability, filter persistence, and visual consistency. It also continues the ongoing refactor to address React best practice violations, including the extraction of API logic into dedicated service files and code style standardization in Admin pages.

Changes Made

Map View Improvements

  • Filter Persistence: Fixed a bug where the map filter (e.g., "Dive Trips") would reset when scrolling or zooming. The selectedEntityType is now correctly synced to the URL type query parameter.
  • Reduced Clustering: Disabled marker clustering for all entity types (Dive Sites, Centers, Trips) at zoom level 11 and higher, allowing users to see individual points more clearly when zoomed in.
  • Date Filter Logic: Updated the default date range for "Dive Trips" to include the past year, ensuring historical or test data is visible by default.
  • Enhanced Popups (Mobile & Desktop):
    • Unified Layout: Implemented a responsive popup design that works seamlessly on both mobile and desktop.
    • Compact Metrics: Key weather metrics (Wind, Waves, Water Temp) are now displayed in a single row with icons, saving vertical space.
    • Expandable Details: Detailed information (reasoning, gusts, etc.) is moved to a "More Info" tooltip. This prevents the popup from dynamically resizing and shifting the map view, solving a critical UX issue on mobile.
    • Visual Consistency: Replaced unicode emojis in 'Dive' popups with consistent SVG icons (Lucide) and the custom shell rating image, matching the DiveDetail page design.
    • Horizontal Scroll Fix: Fixed layout issues that caused horizontal scrollbars in popups.
  • Map Controls:
    • Mobile: Replaced the native select dropdown with Ant Design Mobile components for a more native feel.
    • Desktop: Upgraded header controls to Ant Design components, improved grouping of the "Show on map" label, and added descriptive text to buttons.
    • Auto-pan Mitigation: Reduced Leaflet's auto-pan padding to prevent the map from moving unnecessarily when opening popups.

React Architecture & Code Quality

  • Service Extraction: Refactored API logic from barrel files into dedicated service modules to reduce circular dependencies and improve maintainability (addressing Violation Implement comprehensive dive trips functionality with enhanced list/grid views and UX improvements #3 in react-violations.md):
    • services/admin.js
    • services/dives.js
    • services/notifications.js
    • services/auth.js
  • Code Style: Reordered imports in Admin pages (AdminGrowthVisualizations, AdminRecentActivity, AdminSystemMetrics) to align with project linting standards.
  • PWA Optimization: Optimized PWA asset loading (from previous commits in branch).

Testing

  • Manual Testing:
    • Verified map filter persistence by selecting "Dive Trips" and panning/zooming; confirmed filter remains active.
    • Verified popup behavior on mobile: checked that detailed info opens in a tooltip without shifting the map.
    • Verified "Dive Trips" visibility with the new date range logic.
    • Verified desktop header layout and controls.
  • Unit Tests: Ran npm test (frontend) and pytest (backend) to ensure no regressions.
  • Linting: Verified code quality with make lint-frontend.

Related Issues

Additional Notes

  • The map popup tooltip uses absolute positioning to "pop up" (bottom-full), ensuring it doesn't expand the container height.
  • Admin page changes are primarily import reordering to satisfy linter rules after service extraction.

Refactor frontend codebase to adhere to React best practices and resolve
Service Worker development issues.

React Best Practice Fixes:
- Implement `useFlickrImages` hook to replace manual data fetching in
  `DiveDetail` and `DiveSiteDetail`, resolving waterfall fetching and
  race conditions.
- Create `useClickOutside` hook to centralize click-outside logic in
  `NotificationBell` and `ResponsiveFilterBar`.
- Standardize responsive logic with `useResponsive` hook across
  multiple components.
- Optimize high-frequency updates in `Home.js` using `AnimatedCounter`.
- Add passive event listeners for scroll and resize events to improve
  scroll performance.
- Optimize SVG animations in `IndependentMapView` using GPU acceleration.

PWA & Service Worker Improvements:
- Update `vite.config.js` to remove conflicting Workbox options and
  disable SW in development by default.
- Fix `PWAUpdater` double-mount issue in Strict Mode using refs.
- Remove redundant manual Service Worker registration in `index.html`.
- Configure Nginx proxy to correctly serve Service Worker in dev mode.

This commit resolves 9/10 identified architectural violations.
This commit addresses multiple technical debt items:

1. Refactor Monolithic API (Violation #3):
   - Extract `services/auth.js` for authentication logic.
   - Extract `utils/apiErrors.js` for error handling utilities.
   - Update `AuthContext` and 15+ other files to use these modular imports.
   - Remove unused code from `api.js` while preserving internal usage.

2. Fix Ant Design Deprecations:
   - Update `Card` props: `bordered` -> `variant`, `bodyStyle` -> `styles.body`.
   - Update `Progress` props: `width` -> `size`.
   - Update `Avatar.Group` props: `maxCount` -> `max={{ count }}`.
   - Update `Statistic` props: `valueStyle` -> `styles.content`.
   - Resolve `Spin` tip warning by separating text from spinner.

3. Fix Import Errors:
   - Restore accidentally removed imports in `CreateDive`, `EditDive`, etc.
   - Fix syntax error in `DiveDetail.js`.

Verified with full test suite and manual page navigation. No console
warnings remain.
Move notification-related API functions from `frontend/src/api.js` to a
new `frontend/src/services/notifications.js` file to improve modularity
and separation of concerns.

Update all dependent components, hooks, and pages to import from the new
service location. Clean up unused imports (including `React`, `SEO`, and
`antd` components) in the modified files.

Fix `NotificationBell` tests to mock the correct hook path.
Move dive-related API functions from `frontend/src/api.js` to a new
`frontend/src/services/dives.js` file to improve modularity and reduce
the size of `api.js`.

Update imports in all dependent files:
- `CreateDive.js`, `DiveDetail.js`, `Dives.js`, `EditDive.js`
- `ImportDivesModal.js`
- `flickrHelpers.js`

Clean up unused imports in `DiveDetail.js` and `CreateDive.js`.
Resolve "api is not defined" error in `DiveDetail.js` by ensuring `api`
is correctly imported for profile data fetching.
Move system, storage, metrics, statistics, and settings API functions
from `frontend/src/api.js` to a new `frontend/src/services/admin.js`
file to improve modularity and reduce the size of `api.js`.

Update imports in:
- `AdminGeneralStatistics.js`
- `AdminGrowthVisualizations.js`
- `AdminRecentActivity.js`
- `AdminSystemMetrics.js`
- `useSettings.js`

Clean up unused imports in admin pages (Recharts, React, etc.) and
fix JSDoc and signature in `useSettings.js`.
This commit introduces several user experience improvements to the Map
View and includes code style fixes for Admin pages related to the
ongoing React architecture cleanup.

Map View Improvements:
- **Persist Filter:** The 'selectedEntityType' (e.g., 'Dive Trips') is
  now synced to the URL query parameters, ensuring it persists during
  map navigation (scrolling/zooming).
- **Clustering:** Disabled marker clustering for all entity types at
  zoom level 11 and higher to improve visibility of individual points.
- **Mobile UX:**
  - Replaced the native select dropdown with Ant Design Mobile
    components for a better native-like experience.
- **Desktop UX:**
  - Upgraded the header controls to use Ant Design components.
  - Grouped the "Show on map" label with the dropdown.
  - Added descriptive text to the "Map Controls" button.
- Optimize map popup layout for mobile and desktop:
  - Unified compact view with icons for key weather metrics.
  - Expandable "More Info" tooltip for detailed reasoning to prevent
    popup resizing and map shifting.
  - Suitability badge moved to header for better space utilization.
- **Visual Consistency:**
  - Replaced unicode emojis in 'Dive' popups with SVG icons (Lucide)
    and the custom shell image for ratings, matching the Dive Detail page.
  - Fixed horizontal scrollbar issues in popups by wrapping content.
- Reduce map auto-panning aggressiveness when opening popups to prevent
  popup closure issues.

React Best Practices (Refactor):
- **Admin Pages:** Reordered imports in AdminGrowthVisualizations,
  AdminRecentActivity, and AdminSystemMetrics. This aligns with the
  cleanup of Barrel File Imports (Violation #3 in react-violations.md),
  ensuring consistent ordering following the extraction of specific
  service files (e.g., 'services/admin.js').
@kargig kargig merged commit 3e98496 into main Jan 26, 2026
1 check passed
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.

1 participant