-
-
Notifications
You must be signed in to change notification settings - Fork 33
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
lightlii
wants to merge
60
commits into
master
Choose a base branch
from
ej/background-map-selection
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
60 commits
Select commit
Hold shift + click to select a range
108cf02
Revert "add SettingsMenu tabs component (WIP)"
lightlii 8fbdd3f
Revert "add settings menu tab"
lightlii 5f7d37d
Merge branch 'master' of github.com:digidem/mapeo-desktop
lightlii 7fed094
Merge branch 'master' of github.com:digidem/mapeo-desktop
lightlii 91b89ec
add settingsmenu component
lightlii e51c12d
better menu styling
lightlii b35e0ef
Revert "Revert "add SettingsMenu tabs component (WIP)""
lightlii 9342e17
fix breaks from bad merge (/revert order)
lightlii 467263f
chore: better jsdoc typing
lightlii e44e678
chore: add better typing
lightlii 3ea703b
chore: more improved typing
lightlii 6ebab38
add experiments menu
lightlii f39b76b
chore: usability improvements to settings list items
lightlii 9bfeb19
autogenerated translations file
lightlii bab7bcc
add experiments menu
lightlii 2e1d547
chore: add ExperimentsMenu types
lightlii 80ff041
chore: styling fixes
lightlii 9f9e086
chore: integrate background maps settings menu
lightlii 398178d
autogenerated translations file
lightlii 1e283fe
add experiments menu
lightlii 47c9d61
chore: usability improvements to settings list items
lightlii b3ee3dd
add experiments menu
lightlii 290569e
remove redundant translation
lightlii f46cd69
chore: add mapstyle deletion
lightlii 22c5935
fix: restore `selectMbTileFile` functionality
lightlii bd00458
chore: internationalise 'Import File' label
lightlii 16257b2
chore: disable continuous querying and call refresh when new style is…
lightlii ffb723a
chore: add error handling when importing map style
lightlii 2ea6977
chore: auto-gen translation file
lightlii 5c1ac88
fix: remove merge-duplication
lightlii 9fd494e
chore: auto-gen translation file
lightlii 7753f87
Merge branch 'master' of github.com:digidem/mapeo-desktop
lightlii a27c04b
Merge branch 'master' into ej/background-map-selection
lightlii 4fd671f
feat: add button to select current map
lightlii 35472d3
wip: add backgroundMap selector component to Observations view
lightlii 8494d0e
chore: add background maps selector component. Currently with hardcod…
lightlii be8a4d0
chore: remove hardcoded value (still WIP)
lightlii 99e3c16
Merge branch 'master' of github.com:digidem/mapeo-desktop
lightlii 96b4ef3
Merge branch 'master' into ej/background-map-selection
lightlii b434580
fix: restore setting persisted storage async
lightlii 06c68b8
fix: make saved types in config consistent
lightlii c8c0848
fix: revert async await again (??) problem appears to be the format t…
lightlii 6aa6578
fix: revert zustand serialisation stuf... persisted store working cor…
lightlii cc800ef
Merge branch 'ej/fix-persisted-store' into ej/background-map-selection
lightlii 879bfb3
feat: implement map selection
lightlii 70e3726
fix: add key to Fragment in map
lightlii e6fea7f
Merge branch 'master' of github.com:digidem/mapeo-desktop
lightlii 0666a81
Merge branch 'master' into ej/background-map-selection
lightlii 610e745
fix: remove unused inports
lightlii 99d7450
fix: use fuill screen dialog for BackgroundMapSelector and fix overflow
lightlii 0cc0147
fix: make style list in background maps screen scrollable
lightlii d07b385
fix: refactor hooks to simplify where styles data is coming from
lightlii 472cfa1
fix: clean up unused variables
lightlii 0f15556
fix: save full map style in store and get rid of lookp hook + more ti…
lightlii 9b19b39
fix: map use default style when backgroundmaps flagdisabled
lightlii c6b63ff
Es/example of persisted state (#747)
ErikSin fbd5e4a
chore: make background maps description text translatable
lightlii 8a00112
chore: set default map when current map is deleted
lightlii 6012b8a
chore: make map preview card non-interactive
lightlii eb8e950
chore: remove log
lightlii File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
206 changes: 206 additions & 0 deletions
206
src/renderer/components/BackgroundMaps/BackgroundMapInfo.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,206 @@ | ||
// @ts-check | ||
import { Button, Fade, makeStyles, Paper, Typography } from '@material-ui/core' | ||
import * as React from 'react' | ||
import { defineMessages, useIntl } from 'react-intl' | ||
import DeleteIcon from '@material-ui/icons/DeleteForeverOutlined' | ||
import CheckIcon from '@material-ui/icons/Check' | ||
import ReactMapboxGl from 'react-mapbox-gl' | ||
|
||
import { MAPBOX_ACCESS_TOKEN } from '../../../../config' | ||
import Loading from '../Loading' | ||
import { convertKbToMb } from '../SettingsView/BackgroundMaps' | ||
import { useMapServerMutation } from '../../hooks/useMapServerMutation' | ||
import { useBackgroundMapStore } from '../../hooks/store' | ||
import { DEFAULT_MAP, useMapStylesQuery } from '../../hooks/useMapStylesQuery' | ||
|
||
const MapboxPrevOnly = ReactMapboxGl({ | ||
accessToken: MAPBOX_ACCESS_TOKEN, | ||
dragRotate: false, | ||
pitchWithRotate: false, | ||
attributionControl: false, | ||
injectCSS: false | ||
}) | ||
|
||
const m = defineMessages({ | ||
// Title for Offline Areas | ||
offlineAreas: 'Offline Areas', | ||
// Button to create an offline area | ||
createOfflineArea: 'Create Offline Area', | ||
// Button to delete style | ||
deleteStyle: 'Delete Style', | ||
// Title for error message when deleting style | ||
deleteErrorTitle: 'Error Deleting Style', | ||
// Description for error message when deleting style, | ||
deleteErrorDescription: 'There was an error deleting the style', | ||
// Zoom Level Title | ||
zoomLevel: 'Zoom Level: {zoom}', | ||
// abbreviation for megabyte | ||
mb: 'MB', | ||
// Button text for 'Use Map' button | ||
useMap: 'Use Map', | ||
// Button text for 'Use Map' button when map is selected | ||
currentMap: 'Current Map' | ||
}) | ||
|
||
/** | ||
* @typedef {import('../../hooks/store').MapStyle} BackgroundMapInfo | ||
* @typedef BackgroundMapInfoProps | ||
* @prop {BackgroundMapInfo} map | ||
* @prop {()=>void} unsetMapValue | ||
*/ | ||
|
||
/** @param {BackgroundMapInfoProps} props */ | ||
export const BackgroundMapInfo = ({ map, unsetMapValue }) => { | ||
const { formatMessage: t } = useIntl() | ||
|
||
const [mapStyle, setMapStyle] = useBackgroundMapStore() | ||
|
||
const classes = useStyles() | ||
|
||
const isCurrentMap = mapStyle?.id === map.id | ||
|
||
return ( | ||
<Fade in timeout={0}> | ||
<Paper | ||
style={{ | ||
flex: 1, | ||
width: '100%', | ||
height: '100%', | ||
padding: !map ? 40 : 0 | ||
}} | ||
> | ||
{!map ? ( | ||
<Loading /> | ||
) : ( | ||
<> | ||
<MapInfo | ||
name={typeof map.name === 'string' ? map.name : t(map.name)} | ||
id={map.id} | ||
unsetMapValue={unsetMapValue} | ||
url={map.url} | ||
isDefault={map.isDefault} | ||
isCurrentMap={isCurrentMap} | ||
/> | ||
{/* Text */} | ||
<div className={classes.paddedContainer}> | ||
<Typography variant='subtitle2' style={{ fontSize: 18 }}> | ||
{typeof map.name === 'string' ? map.name : t(map.name)} | ||
</Typography> | ||
{!map.isDefault ? ( | ||
<Typography variant='body1'>{`${Math.round( | ||
convertKbToMb(map.bytesStored) | ||
)} ${t(m.mb)}`}</Typography> | ||
) : null} | ||
<Button | ||
variant='outlined' | ||
onClick={() => setMapStyle(map)} | ||
className={`${classes.paddedButton} ${isCurrentMap && | ||
classes.iconButton}`} | ||
disabled={map.id === mapStyle?.id} | ||
> | ||
<Typography | ||
style={{ textTransform: 'none' }} | ||
variant='subtitle2' | ||
> | ||
{isCurrentMap ? t(m.currentMap) : t(m.useMap)} | ||
</Typography> | ||
{isCurrentMap ? <CheckIcon className={classes.icon} /> : null} | ||
</Button> | ||
</div> | ||
</> | ||
)} | ||
</Paper> | ||
</Fade> | ||
) | ||
} | ||
|
||
/** | ||
* @typedef MapInfoProps | ||
* @prop {string|null|undefined} name | ||
* @prop {string} id | ||
* @prop {()=>void} unsetMapValue | ||
* @prop {string} url | ||
* @prop {boolean | undefined} isDefault | ||
* @prop {boolean} isCurrentMap | ||
*/ | ||
|
||
/** @param {MapInfoProps} props */ | ||
const MapInfo = ({ name, id, isDefault, unsetMapValue, url, isCurrentMap }) => { | ||
const classes = useStyles() | ||
|
||
const { formatMessage: t } = useIntl() | ||
|
||
const { data: mapsData } = useMapStylesQuery() | ||
const [, setMapStyle] = useBackgroundMapStore() | ||
const mutation = useMapServerMutation('delete', `/styles/${id}`) | ||
|
||
async function deleteMap () { | ||
if (isCurrentMap && mapsData?.length) { | ||
setMapStyle(DEFAULT_MAP) | ||
} | ||
await mutation.mutateAsync(null) // tc complains if no arg is passed... | ||
} | ||
|
||
return ( | ||
<> | ||
{/* Banner */} | ||
<Paper className={classes.banner}> | ||
<Typography variant='h5'>{name}</Typography> | ||
|
||
<div> | ||
{!isDefault && ( | ||
<Button variant='outlined' onClick={() => deleteMap()}> | ||
<DeleteIcon className={classes.icon} /> | ||
<Typography style={{ textTransform: 'none' }} variant='subtitle2'> | ||
{t(m.deleteStyle)} | ||
</Typography> | ||
</Button> | ||
)} | ||
</div> | ||
</Paper> | ||
|
||
{/* Map */} | ||
<MapboxPrevOnly | ||
style={url} | ||
containerStyle={{ height: '60%', width: '100%' }} | ||
zoom={[0]} | ||
/> | ||
</> | ||
) | ||
} | ||
|
||
const useStyles = makeStyles({ | ||
buttonContainer: { | ||
display: 'flex', | ||
justifyContent: 'space-between', | ||
alignItems: 'center' | ||
}, | ||
banner: { | ||
width: '100%', | ||
display: 'flex', | ||
justifyContent: 'space-between', | ||
padding: '10px 20px', | ||
borderRadius: 0 | ||
}, | ||
textBanner: { | ||
display: 'flex', | ||
justifyContent: 'space-evenly' | ||
}, | ||
offlineCardContainer: { | ||
display: 'flex', | ||
flexWrap: 'wrap', | ||
justifyContent: 'space-evenly' | ||
}, | ||
paddedContainer: { | ||
padding: 20 | ||
}, | ||
paddedButton: { | ||
marginTop: 20 | ||
}, | ||
iconButton: { | ||
padding: '5px 10px 5px 15px' | ||
}, | ||
icon: { | ||
height: 20 | ||
} | ||
}) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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)