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

Ej/background map selection #744

Open
wants to merge 60 commits into
base: master
Choose a base branch
from
Open

Conversation

lightlii
Copy link
Contributor

Currently WIP. PR #741 contains work that needs confirming and merging so this can be completed

image

@lightlii lightlii requested a review from ErikSin August 22, 2023 07:36
@lightlii lightlii marked this pull request as ready for review August 22, 2023 07:37
Copy link
Contributor

@ErikSin ErikSin left a comment

Choose a reason for hiding this comment

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

I left a comment about architectural changes needeed for the hooks.

Comment on lines 66 to 71
<BackgroundMapInfo
key={offlineMap.id}
size={offlineMap.bytesStored}
id={offlineMap.id}
unsetMapValue={unsetMapValue}
url={offlineMap.url}
Copy link
Contributor

Choose a reason for hiding this comment

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

Default map should be the available on this list.

Also if this list is longer than the screen, the user is unable to scroll

image

Comment on lines 84 to 106
<Box className={classes.styleRow}>
{mapStyles
.filter(({ isImporting }) => !isImporting)
.map(({ id, url, name }) => {
const isSelected = mapStyle === id
return (
<React.Fragment key={id}>
<div className={classes.mapCardWrapper}>
<MapPreviewCard
onClick={() => {
if (isSelected) return
dismiss()
setMapStyle(id)
}}
selected={isSelected}
styleUrl={url}
title={name}
/>
</div>
</React.Fragment>
)
})}
</Box>
Copy link
Contributor

Choose a reason for hiding this comment

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

if there are lots of map the user is unable to scroll to see them. When you convert this to a dialog, you may need to add a scroll view, but the user should be able to see the majority of the maps if you make it a full screen dialog

image

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the architecture of this is a little confusing.

We could simplify this by just exporting 1 hook, a react query (server state) hook.

Thisreact-query-hook that always returns the list of available styles. This would mean that when background maps is disabled, it just returns an array with 1 map style. And when background maps is enabled, it returns an array (which also includes the default map style). This hook should encapsulate all this logic. If returning the react-query is too complicated, you could just return the list of styles and encapsulate the loading state inside of the hook (aka the hook does not have to return a react-query). It should also handle whether experiments flag is turned on or not.

And then the zustand persisted store, useBackgroundMapStore, should handle which map style is used. What that does mean is the map should not be shown while the server state hook is loading. Therefore zustand does not have to deal with any of the loading state, and only deals with returning the persisted map style as chosen by the user. As well the zustand store does not need to deal with experimentsFlag, and is scoped to just serving the map.

Right now, the hook serving the mapStyle and the hook dealing with server state are both dealing loading state AND the experiments flag, which will make it hard to maintain in the future . As well, because there are so many hooks, the data that is being returned is a combination of the hooks, that again will be hard to maintain in the future.

Essentially there should be 2 exported hooks:

  1. zustand state hook that returns the map being used (which is already created)
  2. A hook that serves list of avialable maps, that encapsulates experimentsFlag and loading state

And those can be used in both your modal and in the setting/background map page, without having to transform any data.

@lightlii
Copy link
Contributor Author

I've made a bit of a refactor but I'm not sure it's exactly what you meant. We still need the useSelectedMapStyle hook since it needs to run useMapStylesQuery and we're not in a react component

@lightlii lightlii requested a review from ErikSin August 29, 2023 15:37
lightlii and others added 3 commits August 30, 2023 14:52
* persisted state

* chore: translations

* chore: create default map export & adapt code

---------

Co-authored-by: lightlii <32508751+lightlii@users.noreply.github.com>
Copy link
Contributor

@ErikSin ErikSin left a comment

Choose a reason for hiding this comment

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

some minor comments to address, but otherwise looks good

src/renderer/hooks/store.js Outdated Show resolved Hide resolved
@@ -18,29 +18,49 @@ const m = defineMessages({
offlineBackgroundMapName: 'Offline Map'
})

export const useMapStylesQuery = () => {
export const useMapStylesQuery = (enabled = true) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I dont think I understand what the difference between enable and backgroundMapsEnabled

Copy link
Contributor Author

Choose a reason for hiding this comment

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

enable enables the query. It allows us to disable the querying and manually call refetch when we want the data. I can't find the original ticket but it was one of the first thing you asked me to add on this feature!

src/renderer/components/SettingsView/BackgroundMaps.js Outdated Show resolved Hide resolved
Comment on lines +142 to +151
<div>
{!isDefault && (
<Button variant='outlined' onClick={() => deleteMap()}>
<DeleteIcon className={classes.icon} />
<Typography style={{ textTransform: 'none' }} variant='subtitle2'>
{t(m.deleteStyle)}
</Typography>
</Button>
)}
</div>
Copy link
Contributor

Choose a reason for hiding this comment

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

this is currently not working, but I believe this is a map server thing, so just remove it for now (and the user will not be able to delete a map)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is working fine for me, lets check together later whats going on

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(I added a little check so it will set the the default map if you delete the current selected one)

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.

None yet

2 participants