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 maps settings flag #737

Closed
wants to merge 35 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
108cf02
Revert "add SettingsMenu tabs component (WIP)"
lightlii Jun 28, 2023
8fbdd3f
Revert "add settings menu tab"
lightlii Jun 28, 2023
5f7d37d
Merge branch 'master' of github.com:digidem/mapeo-desktop
lightlii Jul 3, 2023
7fed094
Merge branch 'master' of github.com:digidem/mapeo-desktop
lightlii Jul 27, 2023
91b89ec
add settingsmenu component
lightlii Jun 29, 2023
e51c12d
better menu styling
lightlii Jun 29, 2023
b35e0ef
Revert "Revert "add SettingsMenu tabs component (WIP)""
lightlii Jul 3, 2023
9342e17
fix breaks from bad merge (/revert order)
lightlii Jul 4, 2023
467263f
chore: better jsdoc typing
lightlii Jul 13, 2023
e44e678
chore: add better typing
lightlii Jul 14, 2023
3ea703b
chore: more improved typing
lightlii Jul 14, 2023
6ebab38
add experiments menu
lightlii Jul 12, 2023
f39b76b
chore: usability improvements to settings list items
lightlii Jul 14, 2023
9bfeb19
autogenerated translations file
lightlii Jul 14, 2023
bab7bcc
add experiments menu
lightlii Jul 12, 2023
2e1d547
chore: add ExperimentsMenu types
lightlii Jul 14, 2023
80ff041
chore: styling fixes
lightlii Jul 14, 2023
9f9e086
chore: integrate background maps settings menu
lightlii Jul 17, 2023
398178d
autogenerated translations file
lightlii Jul 17, 2023
1e283fe
add experiments menu
lightlii Jul 12, 2023
47c9d61
chore: usability improvements to settings list items
lightlii Jul 14, 2023
b3ee3dd
add experiments menu
lightlii Jul 12, 2023
290569e
remove redundant translation
lightlii Jul 26, 2023
f46cd69
chore: add mapstyle deletion
lightlii Jul 26, 2023
22c5935
fix: restore `selectMbTileFile` functionality
lightlii Jul 26, 2023
bd00458
chore: internationalise 'Import File' label
lightlii Jul 26, 2023
16257b2
chore: disable continuous querying and call refresh when new style is…
lightlii Jul 26, 2023
ffb723a
chore: add error handling when importing map style
lightlii Jul 27, 2023
2ea6977
chore: auto-gen translation file
lightlii Jul 27, 2023
5c1ac88
fix: remove merge-duplication
lightlii Jul 27, 2023
9fd494e
chore: auto-gen translation file
lightlii Jul 27, 2023
5ab6015
Merge branch 'master' into ej/background-maps-settings-flag
lightlii Aug 22, 2023
a9e1f0d
fix: remove unused variables
lightlii Aug 23, 2023
6e0a7a6
Merge branch 'ej/background-maps-settings-flag' of github.com:digidem…
lightlii Aug 23, 2023
d195f55
fix: settings menu now should use store
lightlii Aug 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions messages/renderer/en.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,48 @@
{
"renderer.components.BackgroundMaps.BackgroundMapInfo.createOfflineArea": {
"description": "Button to create an offline area",
"message": "Create Offline Area"
},
"renderer.components.BackgroundMaps.BackgroundMapInfo.deleteErrorDescription": {
"description": "Description for error message when deleting style,",
"message": "There was an error deleting the style"
},
"renderer.components.BackgroundMaps.BackgroundMapInfo.deleteErrorTitle": {
"description": "Title for error message when deleting style",
"message": "Error Deleting Style"
},
"renderer.components.BackgroundMaps.BackgroundMapInfo.deleteStyle": {
"description": "Button to delete style",
"message": "Delete Style"
},
"renderer.components.BackgroundMaps.BackgroundMapInfo.mb": {
"description": "abbreviation for megabyte",
"message": "MB"
},
"renderer.components.BackgroundMaps.BackgroundMapInfo.offlineAreas": {
"description": "Title for Offline Areas",
"message": "Offline Areas"
},
"renderer.components.BackgroundMaps.BackgroundMapInfo.zoomLevel": {
"description": "Zoom Level Title",
"message": "Zoom Level: {zoom}"
},
"renderer.components.BackgroundMaps.MapCard.areas": {
"description": "indicates how many offline areas",
"message": "offline areas"
},
"renderer.components.BackgroundMaps.MapCard.mb": {
"description": "Abbreviation for megabytes",
"message": "MB"
},
"renderer.components.BackgroundMaps.SidePanel.addMap": {
"description": "Button to add map background",
"message": "Add Map Background"
},
"renderer.components.BackgroundMaps.SidePanel.backToSettings": {
"description": "button to go back to settings",
"message": "Back to Settings"
},
"renderer.components.Home.mapeditor": {
"description": "MapEditor tab label",
"message": "Territory"
Expand Down Expand Up @@ -474,12 +518,40 @@
"renderer.components.SettingsView.AboutMapeo.mapeoVersion": {
"message": "Mapeo Version"
},
"renderer.components.SettingsView.BackgroundMaps.mapBackgroundTitle": {
"description": "Title for description of offline maps",
"message": "Managing Map Backgrounds and Offline Areas"
},
"renderer.components.SettingsView.ExperimentsMenu.backgroundMaps": {
"message": "Background Maps"
},
"renderer.components.SettingsView.SettingsItem.off": {
"message": "Off"
},
"renderer.components.SettingsView.SettingsItem.on": {
"message": "On"
},
"renderer.components.SettingsView.SettingsList.off": {
"message": "Off"
},
"renderer.components.SettingsView.SettingsList.on": {
"message": "On"
},
"renderer.components.SettingsView.index.aboutMapeo": {
"message": "About Mapeo"
},
"renderer.components.SettingsView.index.aboutMapeoSubtitle": {
"message": "Version and build number"
},
"renderer.components.SettingsView.index.backgroundMaps": {
"message": "Background maps"
},
"renderer.components.SettingsView.index.experiments": {
"message": "Experiments"
},
"renderer.components.SettingsView.index.experimentsSubtitle": {
"message": "Turn on experimental new features"
},
"renderer.components.SyncView.Searching.searchingHint": {
"description": "Hint on sync screen when searching on wifi for devices",
"message": "Make sure devices are turned on and connected to the same wifi network"
Expand Down Expand Up @@ -636,6 +708,26 @@
"renderer.components.dialogs.Error.openLog": {
"message": "Open log..."
},
"renderer.components.dialogs.ImportMapStyle.addMap": {
"description": "Title of screen used to add a new background map",
"message": "Add Map Background"
},
"renderer.components.dialogs.ImportMapStyle.cancel": {
"description": "button to cancel the import of a background map",
"message": "Cancel"
},
"renderer.components.dialogs.ImportMapStyle.importErrorDescription": {
"description": "Description of map import error",
"message": "There was an error importing the background maps. Please try again. Error message:"
},
"renderer.components.dialogs.ImportMapStyle.importErrorTitle": {
"description": "Title for import errot pop up dialog,",
"message": "Background Maps Import Error"
},
"renderer.components.dialogs.ImportMapStyle.importFile": {
"description": "Label of 'Import File' button",
"message": "Import File"
},
"renderer.components.dialogs.LatLon.button-submit": {
"message": "Submit"
},
Expand Down
13 changes: 13 additions & 0 deletions src/main/ipc.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,19 @@ module.exports = function (ipcSend) {
return i18n.t('closing-screen')
})

ipcMain.handle('select-mb-tile-file', async function () {
const result = await dialog.showOpenDialog({
filters: [{ name: 'MbTiles', extensions: ['mbtiles'] }],
properties: ['openFile']
})

return result
})

ipcMain.on('show-error-dialog', function (event, title, content) {
dialog.showErrorBox(title, content)
})

ipcMain.on('save-file', function () {
var metadata = userConfig.getSettings('metadata')
var ext = metadata ? metadata.dataset_id : 'mapeodata'
Expand Down
152 changes: 152 additions & 0 deletions src/renderer/components/BackgroundMaps/BackgroundMapInfo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
// @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 Loading from '../Loading'
import { useMapServerQuery } from '../../hooks/useMapServerQuery'
import { MapboxPrevOnly } from './MapCard'
import { convertKbToMb } from '../SettingsView/BackgroundMaps'
import { useMapServerMutation } from '../../hooks/useMapServerMutation'

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'
})

/**
* @typedef BackgroundMapInfoProps
* @prop {string} id
* @prop {string} url
* @prop {number} size
* @prop {()=>void} unsetMapValue
*/

/** @param {BackgroundMapInfoProps} props */
export const BackgroundMapInfo = ({ id, unsetMapValue, url, size }) => {
const { formatMessage: t } = useIntl()

const { data } = useMapServerQuery(`/styles/${id}`)

return (
<Fade in timeout={0}>
<Paper
style={{
flex: 1,
width: '100%',
height: '100%',
padding: !data ? 40 : 0
}}
>
{!data ? (
<Loading />
) : (
<>
<MapInfo
name={data.name}
id={id}
unsetMapValue={unsetMapValue}
url={url}
/>
{/* Text */}
<div style={{ padding: 20 }}>
<Typography variant='subtitle2' style={{ fontSize: 18 }}>
{data.name}
</Typography>
{data.zoom && (
<Typography variant='body1'>
{t(m.zoomLevel, { zoom: data.zoom })}
</Typography>
)}
<Typography variant='body1'>{`${Math.round(
convertKbToMb(size)
)} ${t(m.mb)}`}</Typography>
</div>
</>
)}
</Paper>
</Fade>
)
}

/**
* @typedef MapInfoProps
* @prop {string|undefined} name
* @prop {string} id
* @prop {()=>void} unsetMapValue
* @prop {string} url
*/

/** @param {MapInfoProps} props */
const MapInfo = ({ name, id, unsetMapValue, url }) => {
const classes = useStyles()

const { formatMessage: t } = useIntl()

const mutation = useMapServerMutation('delete', `/styles/${id}`)

async function deleteMap () {
await mutation.mutateAsync(null) // tc complains if no arg is passed...
}

return (
<>
{/* Banner */}
<Paper className={classes.banner}>
<Typography variant='h5'>{name}</Typography>

<div>
<Button variant='outlined' onClick={() => deleteMap()}>
<DeleteIcon />
<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'
},
textBanner: {
display: 'flex',
justifyContent: 'space-evenly'
},
offlineCardContainer: {
display: 'flex',
flexWrap: 'wrap',
justifyContent: 'space-evenly'
}
})
93 changes: 93 additions & 0 deletions src/renderer/components/BackgroundMaps/MapCard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// @ts-check
import * as React from 'react'
import Button from '@material-ui/core/Button'
import { makeStyles, Typography } from '@material-ui/core'
import { useIntl, defineMessages } from 'react-intl'
import ReactMapboxGl from 'react-mapbox-gl'

import { MAPBOX_ACCESS_TOKEN } from '../../../../config'
import { convertKbToMb } from '../SettingsView/BackgroundMaps'

const m = defineMessages({
// Abbreviation for megabytes
mb: 'MB',
// indicates how many offline areas
areas: 'offline areas',
})

export const MapboxPrevOnly = ReactMapboxGl({
accessToken: MAPBOX_ACCESS_TOKEN,
dragRotate: false,
pitchWithRotate: false,
attributionControl: false,
injectCSS: false,
})

/**
* @typedef MapCardProps
* @prop {import('../Settings/BackgroundMaps').MapServerStyleInfo} offlineMap
* @prop {React.Dispatch<React.SetStateAction<import('../Settings/BackgroundMaps').MapServerStyleInfo['id'] | false>>} setMap
* @prop {boolean } isBeingViewed
*/

/** @param {MapCardProps} param */
export const MapCard = ({ offlineMap, setMap, isBeingViewed }) => {
const classes = useStyles()
const { formatMessage: t } = useIntl()

return (
<Button variant='outlined' className={classes.root} onClick={() => setMap(offlineMap.id)}>
<div className={classes.inner} style={{ backgroundColor: !isBeingViewed ? '#CCCCD6' : '#0066FF' }}>
<div style={{ width: '30%' }}>
<MapboxPrevOnly
containerStyle={{
height: '100%',
width: '100%',
}}
style={offlineMap.url}
zoom={[0]}
/>
</div>
<div className={classes.text}>
<Typography>{offlineMap.name}</Typography>
<Typography variant='subtitle1'>
{`${Math.round(convertKbToMb(offlineMap.bytesStored))} ${t(m.mb)}`}
</Typography>
</div>
</div>
</Button>
)
}

const useStyles = makeStyles({
root: {
height: 90,
width: '90%',
marginBottom: 20,
textTransform: 'none',
padding: 0,
'& .MuiButton-root': {
padding: 0,
},
'& .MuiButton-outlined': {
padding: 0,
},
'& .MuiButton-label': {
height: '100%',
},
},
inner: {
display: 'flex',
flex: 1,
height: '100%',
},
text: {
alignItems: 'flex-start',
display: 'flex',
flexDirection: 'column',
justifyContent: 'center',
flex: 1,
height: '100%',
marginLeft: 10,
},
})
Loading
Loading