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

Es/chore settings about and config #717

Draft
wants to merge 47 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
e7bb0fa
chore: added map-server to main thread
ErikSin Nov 28, 2022
eba9734
chore: scaffolded useMapServerQuery
ErikSin Nov 28, 2022
f5493be
chore: sampled typings
ErikSin Nov 28, 2022
bfbeb15
chore: JSDoc overload example
gmaclennan Nov 29, 2022
c9098f1
chore: Added custom hooks
ErikSin Dec 7, 2022
69dbd01
chore: update query invalidation
ErikSin Dec 7, 2022
fdeab8b
chore: update styles endpoint typing to return array
ErikSin Dec 7, 2022
2eec2d2
chore: ran electron-rebuild
ErikSin Dec 8, 2022
0574610
chore: update hooks
ErikSin Dec 8, 2022
68b6155
chore: update query invalidation to be more general
ErikSin Dec 10, 2022
e5f43f0
feat: Added settings tab
ErikSin Apr 17, 2022
36a98e9
chore: Added Translations
ErikSin Apr 17, 2022
0b15b12
chore: updated jsdoc types
ErikSin Apr 17, 2022
bb5af49
chore: updated translations
ErikSin Apr 18, 2022
e45a4ff
chore: translations
ErikSin Apr 18, 2022
9f4528a
chore: updated Types
ErikSin Apr 19, 2022
e31636a
chore: lazy load bg map info
ErikSin Apr 18, 2022
80e3223
chore: translations
ErikSin Apr 18, 2022
4b4da91
chore: Added zoom level definitions
ErikSin Apr 19, 2022
967e673
chore: translations
ErikSin Apr 19, 2022
546c209
chore: clean up
ErikSin Apr 19, 2022
3a46007
chore: translations
ErikSin Apr 19, 2022
11860e6
chore: Added offline area cards
ErikSin Apr 20, 2022
9f3a035
chore: translations
ErikSin Apr 20, 2022
9e4edb4
chore: Added type checking
ErikSin Apr 21, 2022
c36ab9e
chore: Cleaned up buttons
ErikSin Apr 25, 2022
d1ef2b4
chore: translations
ErikSin Apr 25, 2022
9986517
chore: linting fix for CI
ErikSin Apr 25, 2022
222be4c
chore: updated components with tanstack hooks
ErikSin Dec 7, 2022
8037109
chore: translations
ErikSin Dec 7, 2022
755b8d4
chore: added api logic to ui
ErikSin Dec 8, 2022
fd653ef
chore: add map and list styles
ErikSin Dec 10, 2022
968d9ee
chore: translations
ErikSin Dec 10, 2022
49ac141
chore: update dialog UI for import maps
ErikSin Dec 15, 2022
c66092a
chore: translations
ErikSin Dec 15, 2022
b962312
chore: create one instance of mapbox for prev
ErikSin Dec 15, 2022
f315ea0
chore: map card showing map
ErikSin Jan 19, 2023
7bc6d2a
chore: added summary of map
ErikSin Jan 19, 2023
5339099
chore: translations
ErikSin Jan 19, 2023
6f840a5
Merge branch 'master' into BGMapCards
ErikSin Jan 19, 2023
b6ddb86
chore: linting issues
ErikSin Jan 19, 2023
233d07f
chore: clean up excess brackets
ErikSin Jan 19, 2023
fba1d3c
chore: added about and project config to settings
ErikSin Dec 19, 2022
a9568c0
chore: translations
ErikSin Dec 19, 2022
92a3039
chore: added IPC call for config
ErikSin Jan 3, 2023
0a049a3
chore: called ipc for config in render thread
ErikSin Jan 4, 2023
7127663
chore: linting and styling
ErikSin Jan 24, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
104 changes: 104 additions & 0 deletions messages/renderer/en.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,52 @@
{
"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.BackgroundMaps.SidePanel.createOfflineMap": {
"description": "Button to create an offline area for a map backgroun",
"message": "Create Offline Map"
},
"renderer.components.Home.mapeditor": {
"description": "MapEditor tab label",
"message": "Territory"
Expand Down Expand Up @@ -464,6 +512,46 @@
"description": "Name to show for an observation when it does not match any preset",
"message": "Observation"
},
"renderer.components.Settings.AboutMapeo.aboutMapeo": {
"description": "Title for the About Mapeo Page",
"message": "About Mapeo"
},
"renderer.components.Settings.AboutMapeo.variant": {
"description": "Used to indicate the variant of mapeo the user is using",
"message": "Variant"
},
"renderer.components.Settings.AboutMapeo.version": {
"description": "Used to indicate the version of mapeo the user is using",
"message": "Version"
},
"renderer.components.Settings.BackgroundMaps.mapBackgroundTitle": {
"description": "Title for description of offline maps",
"message": "Managing Map Backgrounds and Offline Areas"
},
"renderer.components.Settings.ProjectConfig.config": {
"message": "Config"
},
"renderer.components.Settings.ProjectConfig.importConfig": {
"message": "Import Config"
},
"renderer.components.Settings.ProjectConfig.projectName": {
"message": "Project Name"
},
"renderer.components.Settings.ProjectConfig.title": {
"description": "title of project setting page",
"message": "Project Settings"
},
"renderer.components.Settings.index.aboutMapeo": {
"description": "Setting Tab title to open information about mapeo",
"message": "About Mapeo"
},
"renderer.components.Settings.index.backgroundMap": {
"description": "Setting Tab title to open background maps",
"message": "Background Map"
},
"renderer.components.Settings.index.projConfig": {
"message": "Project Configuration"
},
"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 @@ -620,6 +708,22 @@
"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."
},
"renderer.components.dialogs.ImportMapStyle.importErrorTitle": {
"description": "Title for import errot pop up dialog,",
"message": "Background Maps Import Error"
},
"renderer.components.dialogs.LatLon.button-submit": {
"message": "Submit"
},
Expand Down
4 changes: 4 additions & 0 deletions src/main/ipc.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,8 @@ module.exports = function (ipcSend) {
ipcMain.on('refresh-window', function () {
ipcSend('refresh-window')
})

ipcMain.on('update-config', (_, filepath) => {
userConfig.importSettings(filepath, () => {})
})
}
163 changes: 163 additions & 0 deletions src/renderer/components/BackgroundMaps/BackgroundMapInfo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
// @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'

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} idBeingViewed
* @prop {string} url
* @prop {number} size
* @prop {()=>void} unsetMapValue
*/

/** @param {BackgroundMapInfoProps} props */
export const BackgroundMapInfo = ({
id,
idBeingViewed,
unsetMapValue,
url,
size
}) => {
const shouldLoad = React.useMemo(() => id === idBeingViewed, [
id,
idBeingViewed
])

const { formatMessage: t } = useIntl()

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

// Lazy loading each one here: aka will only load when clicked
return shouldLoad ? (
<Fade in={shouldLoad} timeout={600}>
<Paper
style={{
flex: 1,
width: '100%',
height: '100%',
padding: !data ? 40 : 0
}}
>
{!data ? (
<Loading />
) : (
<React.Fragment>
<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'>{`${size} ${t(m.mb)}`}</Typography>
</div>
</React.Fragment>
)}
</Paper>
</Fade>
) : null
}

/**
* @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()

/**
*
* @param {string} mapId
*/

// To Do, useMapServerMutation.mutate()
function deleteMap (mapId) {}

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

<div>
<Button variant='outlined' onClick={() => deleteMap(id)}>
<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]}
/>
</React.Fragment>
)
}

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'
}
})
100 changes: 100 additions & 0 deletions src/renderer/components/BackgroundMaps/MapCard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// @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 '../Settings/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
}
})