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

enhance nearby task completion modal #2552

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

Conversation

CollinBeczak
Copy link
Collaborator

@CollinBeczak CollinBeczak commented Feb 14, 2025

Requires: maproulette/maproulette-backend#1170

resolves: #2161
partially resolves: #2546

Modal before:
Screenshot 2025-02-14 at 7 09 48 PM

Modal after
Screenshot 2025-02-14 at 7 10 42 PM

Before clicking select all task in view
Screenshot 2025-02-14 at 7 08 56 PM

after clicking select all task in view
Screenshot 2025-02-14 at 7 09 07 PM

@CollinBeczak CollinBeczak marked this pull request as ready for review February 17, 2025 15:46
jake-low
jake-low previously approved these changes Feb 17, 2025
Copy link
Contributor

@jake-low jake-low left a comment

Choose a reason for hiding this comment

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

UI changes LGTM, left a couple comments about possible code improvements (optional)

Comment on lines 146 to 155
// componentDidUpdate(prevProps, prevState) {
// if (
// this.state.nearbyTasks &&
// !this.state.nearbyTasks.loading &&
// this.props.taskId !== this.state.nearbyTasks.nearTaskId
// ) {
// this.updateNearbyTasks(this.props);
// }
// }

Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: looks like this commented-out code can just be deleted

Comment on lines +79 to +124
const MapBounds = ({ taskMarkers, setMapBounds, loadByNearbyTasks, setLoadByNearbyTasks }) => {
const map = useMap();
const prevMarkersLength = useRef(taskMarkers?.length || 0);
const initialBoundsSet = useRef(false);

// Only track map bounds changes
useEffect(() => {
const handleMoveEnd = () => {
const bounds = map.getBounds();
setMapBounds(bounds);
};

map.on("moveend", handleMoveEnd);

// Set initial bounds tracking
if (!initialBoundsSet.current) {
handleMoveEnd();
initialBoundsSet.current = true;
}

return () => {
map.off("moveend", handleMoveEnd);
};
}, [map, setMapBounds]);

// Separate effect for handling bounds fitting
useEffect(() => {
const currentLength = taskMarkers?.length || 0;

// Only fit bounds if explicitly loading by nearby tasks AND markers count changed
if (loadByNearbyTasks && currentLength > 0 && taskMarkers !== prevMarkersLength.current) {
const bounds = L.latLngBounds(taskMarkers.map((marker) => marker.position));
map.fitBounds(bounds, {
padding: [40, 40],
maxZoom: 18,
});
prevMarkersLength.current = currentLength;
setLoadByNearbyTasks(false);
}
}, [map, taskMarkers, loadByNearbyTasks]);

return null;
};
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like this component doesn't actually return JSX, its only purpose is to set up some effects? If so you can write this as a custom hook. You'd name it useMapBounds() and I think setMapBounds might become a return value rather than an argument (similar to how useState returns a setter function that lets you change the state.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Im honestly not sure how to do what you are describing. The reason i did it this way to ket access to the map context: const map = useMap();. I could make a new map component but that would be a much bigger change. Your approach could be better, i just don't know how to do it or how exactly it would work.

@jschwarz2030
Copy link
Contributor

please resolve jake's comments and merge conflicts. happy to test and approve after

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.

Simple-by-default User Experience improving usability of "Load more tasks" screen
3 participants