Skip to content
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

Initial Map Loading #668

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open

Conversation

mwpark2014
Copy link
Contributor

@mwpark2014 mwpark2014 commented Apr 23, 2023

Fixes #447

Builds off of https://docs.google.com/document/d/1MSSbkCo77VCE9tHZdWKAr8lfrBpRF_1AEMptInFjUBI/edit#

// 1. If URL contains a valid id hash param, map ignores the pos in favor of coordinates of tree with id
// 2. Else if URL contains valid pos hash param, map loads in with passed in LatLng and zoom
// 3. Otherwise, center map around the user’s last map url params if available
4. [Not implemented]. Otherwise, attempt to use IP address to infer user's location
5. If all else fails, default map to -99.08, 41.03 at global zoom

This PR:

  • Refactors 1) since now we can add capability to wait for async map load in Mapbox Manager
  • Implements 3) using local storage

enabled: initialLoadTreeId.current != null,
onSuccess: ({ lng, lat, id }) => {
mapboxManager.setCenter({
coords: { lng, lat },

Choose a reason for hiding this comment

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

The TODO comment should be addressed or removed if it's no longer relevant.

localStorage.setItem('lastVisitedUrl', window.location.href);
});

setIsMapLoaded(true);

Choose a reason for hiding this comment

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

Consider wrapping setIsMapLoaded(true) in a separate useEffect with proper dependencies to avoid potential issues with the component lifecycle.

zoom: 15,
});
hasInitialFlyToFired.current = true;
// 1. If URL contains a valid id hash param, map ignores the pos in favor of coordinates of tree with id

Choose a reason for hiding this comment

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

Consider checking if 'lastVisitedUrl' is a valid URL before assigning it to 'window.location'.

@mwpark2014 mwpark2014 changed the base branch from main to mwpark/feature/mapbox-camera-manager April 23, 2023 15:55
@mwpark2014 mwpark2014 force-pushed the mwpark/feature/refactor-initial-load branch from a883806 to 021126f Compare April 23, 2023 16:34
@mwpark2014 mwpark2014 requested a review from zoobot April 25, 2023 01:42
@mwpark2014 mwpark2014 marked this pull request as ready for review April 25, 2023 01:43
Copy link
Member

@zoobot zoobot left a comment

Choose a reason for hiding this comment

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

Is this merge intentional?
Do you want to merge this into your other branch or do you want to stagger the PRs with mwpark/feature/mapbox-camera-manager going in first?

@zoobot
Copy link
Member

zoobot commented Apr 25, 2023

Lighthouse should be fixed now but Paul just made another change/revert. Need to rebase main rebase for lighthouse test to pass.

@mwpark2014
Copy link
Contributor Author

Is this merge intentional? Do you want to merge this into your other branch or do you want to stagger the PRs with mwpark/feature/mapbox-camera-manager going in first?

Stagger the PRs with mwpark/feature/mapbox-camera-manager going in first

},
{
retry: 0,
enabled: initialLoadTreeId.current != null,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah crap, just realized there's a bug in here in that this query will be repeated after the default cache/stale time runs out. If that happens, the map will be recentered at seemingly random times.

Maybe an alternative is having a hook for doing something just once after all conditions pass lol. Seems hacky but better than having a bunch of isInitiated flags laying around

@mwpark2014 mwpark2014 force-pushed the mwpark/feature/mapbox-camera-manager branch from d41229b to 87d1ef2 Compare April 29, 2023 21:39
@mwpark2014 mwpark2014 force-pushed the mwpark/feature/refactor-initial-load branch from 021126f to 053e147 Compare April 29, 2023 21:48
@mwpark2014 mwpark2014 force-pushed the mwpark/feature/refactor-initial-load branch from 053e147 to fe8662e Compare April 29, 2023 21:55
@zoobot
Copy link
Member

zoobot commented May 2, 2023

Is this still in draft mode? Are you still working on this?

Base automatically changed from mwpark/feature/mapbox-camera-manager to main May 9, 2023 06:05
@zoobot
Copy link
Member

zoobot commented May 18, 2023

@mwpark2014 Is this ready for review or still in progress? Thanks

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.

Save user's params in local storage and load them by default on load
2 participants