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

refactor: create MapContent component #743

Merged
merged 22 commits into from
May 29, 2024
Merged

Conversation

menachem95
Copy link
Collaborator

Description

refactor: I built the component

screenshots

WhatsApp Image 2024-05-09 at 13 14 52

@menachem95 menachem95 requested a review from NoamGaash as a code owner May 9, 2024 10:15
@menachem95 menachem95 changed the title create MapContent component refactor: create MapContent component May 9, 2024
Copy link
Member

@NoamGaash NoamGaash left a comment

Choose a reason for hiding this comment

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

great start!
by the way, would you like to add some tests to the "expand" button?

@@ -147,7 +68,7 @@ export function MapIndex({
)
}

function RecenterOnDataChange({ positions, plannedRouteStops }: MapProps) {
export function RecenterOnDataChange({ positions, plannedRouteStops }: MapProps) {
Copy link
Member

Choose a reason for hiding this comment

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

can it be moved to the other file?

src/pages/components/map-related/MapContent.tsx Outdated Show resolved Hide resolved
Copy link
Member

@NoamGaash NoamGaash left a comment

Choose a reason for hiding this comment

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

much better
consider the comment (optional)

@itsoriki
Copy link
Collaborator

itsoriki commented May 9, 2024

Fantastic!
Resolves #736

@itsoriki
Copy link
Collaborator

@menachem95 do you need any help? I just saw Noam's great suggestion to improve UX regarding the hook you created - do you need clarifications about it?

Btw, I wanna mention that on this Tuesday 8PM there will be a Q&A session so you can ask there if you prefer Maakaf discord

@NoamGaash
Copy link
Member

Hi @menachem95 , could you please try npm run lint on your branch?

@menachem95
Copy link
Collaborator Author

Yeah, I think I'm going to need some guidance with that.
And I plan to be in the session too

@NoamGaash
Copy link
Member

feel free to consult everyone in the discord and slack groups, and please let us know how can we make the contribution experience smoother
you're doing a great thing, thanks for putting your efforts to this pull request and apologies for the current status of the CI pipeline. normally, it's more verbose and tells exactly what's the problem with the code.
I'll merge a small CI fix to your branch (use git pull to sync with it) and hopefully we'll get a better error message with what's going on there

@NoamGaash
Copy link
Member

allright, seems there's a little circular dependency problem - two files are importing each other
it can be a problem, because when building the project vite won't know which package should come first

image

Comment on lines 17 to 24
// const positionsSum = positions.reduce(
// (acc, { loc }) => [acc[0] + loc[0], acc[1] + loc[1]],
// [0, 0],
// )
// const mean: LatLngTuple = [
// positionsSum[0] / positions.length || position.loc[0],
// positionsSum[1] / positions.length || position.loc[1],
// ]
Copy link
Member

Choose a reason for hiding this comment

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

great! let's just remove the comments

Comment on lines 24 to 27
export interface MapProps {
positions: Point[]
plannedRouteStops: BusStop[]
}
Copy link
Member

Choose a reason for hiding this comment

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

exporting this to a different file (map-types.ts?) can solve the circular dependency

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ok

Copy link
Member

@NoamGaash NoamGaash left a comment

Choose a reason for hiding this comment

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

🏅 🏅 🏅

import { useEffect } from 'react'
import { LatLngTuple } from 'leaflet'
import { useMap } from 'react-leaflet'
import { position } from './MapWithLocationsAndPath'
Copy link
Member

Choose a reason for hiding this comment

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

it creates a circular dependency
maybe you can avoid using it?

@NoamGaash
Copy link
Member

NoamGaash commented May 14, 2024

import { useEffect } from 'react'
import { LatLngTuple } from 'leaflet'
import { useMap } from 'react-leaflet'
import { position } from './MapWithLocationsAndPath'
import { MapProps } from './map-types'

export function useRecenterOnDataChange({ positions, plannedRouteStops }: MapProps) {
  const map = useMap()
  const top = Math.min(...positions.map((pos) => pos.loc[0]))
  const left = Math.min(...positions.map((pos) => pos.loc[1]))
  const bottom = Math.max(...positions.map((pos) => pos.loc[0]))
  const right = Math.max(...positions.map((pos) => pos.loc[1]))

  const center = [(top + bottom) / 2, (left + right) / 2] as LatLngTuple

  const zoom = center[0]
    ? map.getBoundsZoom([
        [top, left],
        [bottom, right],
      ])
    : undefined

  useEffect(() => {
    if (center[0] && center[1] && zoom) map.setView(center, zoom, { animate: true })
  }, [...center])
}

import '../../Map.scss'

const position: Point = {
export const position: Point = {
Copy link
Member

Choose a reason for hiding this comment

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

this cause a circular dependency error -

✖ Found 1 circular dependency!

1) src/pages/components/map-related/MapContent.tsx > src/pages/components/map-related/useRecenterOnDataChange.ts > src/pages/components/map-related/MapWithLocationsAndPath.tsx

Copy link
Member

@NoamGaash NoamGaash left a comment

Choose a reason for hiding this comment

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

it seems great!
but you do have this error to handle:

#14 10.47 src/pages/lineProfile/LineProfile.tsx(115,8): error TS2741: Property 'position' is missing in type '{ positions: Point[]; plannedRouteStops: BusStop[]; }' but required in type 'MapProps'.
#14 10.47 src/pages/singleLineMap/index.tsx(136,8): error TS2741: Property 'position' is missing in type '{ positions: Point[]; plannedRouteStops: BusStop[]; }' but required in type 'MapProps'.

also, I've added some optional comments

Copy link
Member

@NoamGaash NoamGaash left a comment

Choose a reason for hiding this comment

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

💯

@menachem95 menachem95 closed this May 20, 2024
@menachem95 menachem95 reopened this May 27, 2024
@menachem95 menachem95 merged commit badc0eb into hasadna:main May 29, 2024
15 checks passed
@NoamGaash
Copy link
Member

Good job, thanks!
@all-contributors add @menachem95 for code
👏

Copy link
Contributor

@NoamGaash

I've put up a pull request to add @menachem95! 🎉

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.

3 participants