Repository navigation
Handle path details state within app - #75
Conversation
# Conflicts: # src/actions/Actions.ts # src/map/Mapbox.ts
# Conflicts: # src/App.module.css # src/App.tsx # src/custom.d.ts # src/map/Map.tsx # src/map/Mapbox.ts
# Conflicts: # src/App.tsx # src/actions/Actions.ts # src/index.tsx # src/map/Mapbox.ts
Janekdererste
left a comment
There was a problem hiding this comment.
Overall this looks good to me. I guess one can also see the limit of the used store pattern already. I think we are not there yet, but maybe soon.
| routeSegmentsSelectedCallback: onElevationSelected, | ||
| } | ||
| setGraph(new HeightGraph(containerRef.current, options, callbacks)) | ||
| }, [containerRef]) |
There was a problem hiding this comment.
Is the old heightgraph properly removed from the dom? I.e. when the large and small layouts are exhchanged this component will be unmounted. I don't know from just looking at this.
When the dependeny array is removed there are a lot of svg added to the dom which maybe indicate a missing cancel function as return value of this effect?
There was a problem hiding this comment.
The height graph is just a collection of elements attached to some parent
useEffect, but I am not sure what to remove?There was a problem hiding this comment.
It should be gone and I just noticed it when removing the dependencies as long as there is the containerRef dependency, I don't see more svg elements than expected.
There was a problem hiding this comment.
You mean there is nothing we need to do? :)
There was a problem hiding this comment.
Yes, sorry about that comment. I typed it while thinking, not considering whether it would be helpful or not.
| }, [containerRef]) | ||
| const resizeGraph = () => { | ||
| graph?.resize({ width: containerRef.current?.clientWidth, height: containerRef.current?.clientHeight }) | ||
| } |
There was a problem hiding this comment.
changed width to container's width
There was a problem hiding this comment.
Cool, thanks. Should the graph not use all available horizontal space? I thought this was kind of the original idea. But then it might 'collide' with the instructions list.. hm :)
There was a problem hiding this comment.
Yes, I gave it a container, which sits on top of the map. As it was with the widget before. It will not collide with the instruction list this way.
| const pathDetailsData = buildPathDetailsData(selectedPath) | ||
| graph?.setData(pathDetailsData.data, pathDetailsData.mappings) | ||
| }, [selectedPath, graph]) | ||
| return ( |
There was a problem hiding this comment.
It would be nice to hide the height graph if no route is selected. It doesn't look pleasant when empty something like:
return isPathPresent &&
<div className={styles.layoutContainer}>
<div className={styles.heightgraphContainer} ref={containerRef} />
</div>
There was a problem hiding this comment.
Sure. This is somewhat related to our discussion about using null for missing values. The selectedPath is never null, but it might be missing. I would find it very intuitive to check if its null here :) Currently it might be an RouteStore#emptyPath, but to obtain the isPathPresent value here I need to figure this out by checking if the points of the path are empty or something like this.
There was a problem hiding this comment.
I tried this but could not make it work yet :( I also wonder if we should or should not show the toggle button as in current master. I think it is useful to have the button so one can hide the graph if needed. Or maybe it should just be resizable in general? Previously I thought we would put the graph underneath the map so I removed the icon.
There was a problem hiding this comment.
I find a toggle button usefull.
There was a problem hiding this comment.
Ok I put back the toggle button, but I had to tweak the layout quite a bit for this. See my last commits
There was a problem hiding this comment.
The graph is no hidden when there is no path
| } | ||
| } | ||
|
|
||
| function createColorMapping(detail: any): any { |
There was a problem hiding this comment.
I know you've ported it from js, but maybe remove the anys? Probably future you will be happy about it.
There was a problem hiding this comment.
I added some types here even though I am not fully convinced this improved much :) But generally I agree that adding most or all the types will save time down the road. Here it is a bit awkward because we get these path details from the GH API which could either be [number, number, number][] or [number, number, string][] and there already is some code that needs to distinguish the two cases.
| } | ||
|
|
||
| export default class PathDetailsStore extends Store<PathDetailsStoreState> { | ||
| constructor() { |
There was a problem hiding this comment.
The default constructor may be ommited
| } | ||
|
|
||
| protected getInitialState(): PathDetailsStoreState { | ||
| return { |
There was a problem hiding this comment.
I find it nice to not have null or undefined values. Other than Java Typescript somewhat forces us to never have undefined values since it is necessary to separately declare that type. Not having undefined and null removes a lot of places where one has to test for presence.
If you can make it work maybe it is possible to supply an empty but valid state initially and design the components so that they always display the right thing also with an initial state.
There was a problem hiding this comment.
Yes, I also noticed this. Using types like <type> | null does seem a bit strange indeed. Then again it kind of expresses exactly what I want. pathDetailsPoint is the point on the map that corresponds to the mouse hover position in the height graph. When the mouse is not positioned above the heightgraph there is no such point and I use null to cover this state. What would be the alternative? We could use some special point value like [600,600] to represent 'no point selected', but so far I do not see why this would be better (and I think its worse tbh). Sure we would not need the extra | null in the typing but then we need to do another comparison like point !== [600,600] elsewhere. In this specific example there is only one place where we check if the point is null and this is the place where we have to decide whether there should or should not be a marker on the map. I think it would be the same if we had to check for some special value.
But generally I agree that thinking about null or undefined values can make the code worse and my default assumption is also that nothing is null or undefined (same in Java btw) unless cases like this where there is a notion of a value possibly 'missing'. Hm, another possibility could be adding something like pointSelected: boolean to the state?
There was a problem hiding this comment.
I see that it makes sense in this case. I also agree that the special value approach would be worse.
# Conflicts: # src/App.module.css # src/App.tsx # src/actions/Actions.ts # src/index.tsx # src/map/Map.tsx # src/map/Mapbox.ts # src/sidebar/search/AddressInput.module.css # src/sidebar/search/AddressInput.tsx # src/sidebar/search/GeocodingResult.tsx # src/stores/MapOptionsStore.ts
Why do you think we are getting closer to this limit? There is quite a bit of boiler-plate code needed, but this PR does not really do anything we did not do elsewhere yet? But sure probably at some point we should think about our current approach again. |
Because we add more and more stores. Probably, this would be somthing a library would structure for us. Now, thinking about this comment a second time. Maybe having more and more stores could also indicate that it is an easy pattern to use and we"re still all good :-) |
Yes maybe at some point we should do a little comparison but currently I think our approach does the trick. Can you please have a final look? From my side this is ready to merge. Note that the path detail graph now takes the maximum (as much as the instructions side bar allows) space in horizontal direction. If you do not like feel free to make it more narrow. Oh and maybe you want to adjust the fonts used in the path detail graph panel? |
|
There is still a layout issue in firefox. I will look into it. |
…tails_component # Conflicts: # src/pathDetails/PathDetails.module.css # src/pathDetails/PathDetails.tsx
…Component from App.tsx Make sure the graph always has the correct width
Also have a max width on the heightgraph
|
Okay, I solved the layout issues on firefox by making things simpler. I put the glue code to figure out the width of the graph back into the component. The component's container now forces the component to have the correct size. The width parameter which gets pushed down the heightgraph module is taken from that container. The height of the component's container is determined by the component itself I set it to 14rem which looks good on my screen and is slightly smaller than the default. I also limited the width to 1000px, which will make it span over all the available width on most screens I'd assume. The toggle button comes with its own background-color, corner-radius and drop-shadow. Maybe we can remove that. The code for this is not in our code base at the moment.
I didn't see an option to change it. If it is easily possible it would be great. It would also be nice to style the toggle button accordinto our other controls. I guess it is your tunr @easbar to have a final look now. |
|
Cool, thanks 👍 Your version works for me. I like that the graph resizing code is in
Sure
Regarding the styles of the toggle icon and the fonts: They are defined in |
The box shadow wouldn't show when attached to the heightgraph directly. So I removed it because I wanted to finish. But it should have one. I can take another look at it.
The button relies on the component's container to have
Probably that's the appropriate thing to do. |
|
Ok, but if these styling issues (box shadow, fonts etc.) aren't so easy to fix I'd say let's finish here now. For #87 I also had the problem that I did not manage to integrate the 'flag' that is shown on the map when we hover the path details and this might be related. And I am also not sure if we maybe should just move the entire diagram into our code base, so I think it's better to move on and postpone this for now unless there is a quick fix for the styling. I also do not understand why the font is now larger than in master since we did not really change it? |
# Conflicts: # src/map/Mapbox.ts
|
I opened #105 for the remaining styling issues |
Co-authored-by: Janekdererste <[email protected]>
todo: