From 108cf020cde1138714f73b0100337ba3d48a351d Mon Sep 17 00:00:00 2001 From: lightlii <32508751+lightlii@users.noreply.github.com> Date: Wed, 28 Jun 2023 18:50:30 +0200 Subject: [PATCH 01/51] Revert "add SettingsMenu tabs component (WIP)" This reverts commit 9a478ed2899ae0264e8a37f128f3cdf79171ef4f. --- messages/renderer/en.json | 3 - src/renderer/components/Home.js | 2 - .../components/SettingsView/AboutMapeo.js | 6 -- .../components/SettingsView/SettingsMenu.js | 101 ------------------ src/renderer/components/SettingsView/index.js | 41 ------- 5 files changed, 153 deletions(-) delete mode 100644 src/renderer/components/SettingsView/AboutMapeo.js delete mode 100644 src/renderer/components/SettingsView/SettingsMenu.js delete mode 100644 src/renderer/components/SettingsView/index.js diff --git a/messages/renderer/en.json b/messages/renderer/en.json index b53534eb..13d2f6b1 100644 --- a/messages/renderer/en.json +++ b/messages/renderer/en.json @@ -468,9 +468,6 @@ "description": "Name to show for an observation when it does not match any preset", "message": "Observation" }, - "renderer.components.SettingsView.index.aboutMapeo": { - "message": "About Mapeo" - }, "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" diff --git a/src/renderer/components/Home.js b/src/renderer/components/Home.js index c279214e..c517c64e 100644 --- a/src/renderer/components/Home.js +++ b/src/renderer/components/Home.js @@ -18,7 +18,6 @@ import TitleBarShim from './TitleBarShim' import { defineMessages, useIntl } from 'react-intl' import createPersistedState from '../hooks/createPersistedState' import SyncView from './SyncView' -import { SettingsView } from './SettingsView' import { STATES as updateStates, UpdaterView, UpdateTab } from './UpdaterView' import useUpdater from './UpdaterView/useUpdater' import Loading from './Loading' @@ -302,7 +301,6 @@ export default function Home ({ onSelectLanguage }) { component={SyncView} unmountOnExit /> - { - return -} diff --git a/src/renderer/components/SettingsView/SettingsMenu.js b/src/renderer/components/SettingsView/SettingsMenu.js deleted file mode 100644 index 95e06aa0..00000000 --- a/src/renderer/components/SettingsView/SettingsMenu.js +++ /dev/null @@ -1,101 +0,0 @@ -import * as React from 'react' -import Tabs from '@material-ui/core/Tabs' -import Tab from '@material-ui/core/Tab' -import { useIntl } from 'react-intl' -import styled from 'styled-components' -import { Paper, Typography } from '@material-ui/core' - -export const SettingsMenu = ({ tabs, currentTab, onTabChange }) => { - const { formatMessage: t } = useIntl() - - return ( - onTabChange(newValue)} - style={{ - maxWidth: '300px' - }} - > - {tabs.map((tab, index) => ( - - ))} - - ) -} - -const RenderTab = ({ - tab: { icon: Icon, label, subtitle }, - active, - ...rest -}) => { - const { formatMessage: t } = useIntl() - - console.log({ active, rest }) - - return ( - - - {Icon ? : null} - - - {t(label)} - - - {subtitle} - - - - - ) -} - -const Row = styled.div` - display: flex; - flex-direction: row; -` - -const Column = styled.div` - display: flex; - flex-direction: column; -` - -const WrapperRow = styled(Row)` - padding: 10px; - align-items: center; -` - -const IconContainer = styled.div` - flex: 1; - padding: 10px; - display: flex; - align-items: center; -` - -const TitleContainer = styled(Column)` - justify-content: flex-start; - flex: 8; -` diff --git a/src/renderer/components/SettingsView/index.js b/src/renderer/components/SettingsView/index.js deleted file mode 100644 index e58f3baa..00000000 --- a/src/renderer/components/SettingsView/index.js +++ /dev/null @@ -1,41 +0,0 @@ -import React, { useState } from 'react' -import Paper from '@material-ui/core/Paper' -import InfoIcon from '@material-ui/icons/Info' -import { SettingsMenu } from './SettingsMenu' -import { defineMessages } from 'react-intl' -import { AboutMapeoMenu } from './AboutMapeo' - -const m = defineMessages({ - aboutMapeo: 'About Mapeo' -}) - -const tabs = /** @typedef {const} */ [ - { - tabId: 'AboutMapeo', - icon: InfoIcon, - label: m.aboutMapeo, - subtitle: 'Version and build number' - } -] - -export const SettingsView = () => { - const [menuItem, setMenuItem] = useState(null) - - console.log({ menuItem }) - - return ( -
- - - {menuItem === 'AboutMapeo' && ( - - - - )} -
- ) -} From 8fbdd3fd9e6e0277226edd4fac816a16e5b500e3 Mon Sep 17 00:00:00 2001 From: lightlii <32508751+lightlii@users.noreply.github.com> Date: Wed, 28 Jun 2023 18:50:34 +0200 Subject: [PATCH 02/51] Revert "add settings menu tab" This reverts commit fd8a0baefef743cb14e9c6d0a620bd2daa671ae3. --- messages/renderer/en.json | 4 ---- src/renderer/components/Home.js | 34 ++++++++++++++++----------------- 2 files changed, 16 insertions(+), 22 deletions(-) diff --git a/messages/renderer/en.json b/messages/renderer/en.json index 13d2f6b1..cd5e1513 100644 --- a/messages/renderer/en.json +++ b/messages/renderer/en.json @@ -7,10 +7,6 @@ "description": "MapFilter tab label", "message": "Observations" }, - "renderer.components.Home.settings": { - "description": "Settings tab label", - "message": "Settings" - }, "renderer.components.Home.sync": { "description": "Synchronize tab label", "message": "Synchronize" diff --git a/src/renderer/components/Home.js b/src/renderer/components/Home.js index c517c64e..27395e92 100644 --- a/src/renderer/components/Home.js +++ b/src/renderer/components/Home.js @@ -8,7 +8,6 @@ import LocationOn from '@material-ui/icons/LocationOn' import MapIcon from '@material-ui/icons/Map' import ObservationIcon from '@material-ui/icons/PhotoLibrary' import SyncIcon from '@material-ui/icons/OfflineBolt' -import SettingsIcon from '@material-ui/icons/Settings' import WarningIcon from '@material-ui/icons/Warning' import LatLonDialog from './dialogs/LatLon' @@ -46,8 +45,6 @@ const m = defineMessages({ mapfilter: 'Observations', // Synchronize tab label sync: 'Synchronize', - // Settings tab label - settings: 'Settings', update: 'Update Mapeo' }) @@ -111,17 +108,11 @@ const MapeoIcon = styled(LocationOn)` ` const StyledTabs = styled(Tabs)` - height: 100%; - border-right: 1px solid rgba(0, 0, 0, 0.12); -webkit-app-region: no-drag; .PrivateTabIndicator-root-1 { background-color: #ff9933; } - - .MuiTabs-flexContainerVertical { - height: 100%; - } ` const StyledTab = styled(Tab)` @@ -163,6 +154,13 @@ const StyledPanel = styled.div` } ` +const Version = styled.div` + align-self: flex-start; + margin: auto 10px 10px 10px; + font-size: 0.8rem; + color: ${buildConfig.variant === 'icca' ? '#eeeeee' : '#aaaaaa'}; +` + const LoadingContainer = styled.div` display: flex; width: 100%; @@ -271,19 +269,11 @@ export default function Home ({ onSelectLanguage }) { orientation='vertical' variant='scrollable' value={tabIndex} - onChange={(e, value) => { - console.log({ value }) - setTabIndex(value) - }} + onChange={(e, value) => setTabIndex(value)} > } label={t(m.mapeditor)} /> } label={t(m.mapfilter)} /> } label={t(m.sync)} /> - } - label={t(m.settings)} - /> {hasUpdate && ( } @@ -291,6 +281,7 @@ export default function Home ({ onSelectLanguage }) { /> )} + Mapeo v{buildConfig.version} @@ -301,6 +292,13 @@ export default function Home ({ onSelectLanguage }) { component={SyncView} unmountOnExit /> + Date: Thu, 29 Jun 2023 15:40:08 +0200 Subject: [PATCH 03/51] add settingsmenu component --- src/renderer/components/SettingsView/SettingsMenu.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/renderer/components/SettingsView/SettingsMenu.js b/src/renderer/components/SettingsView/SettingsMenu.js index 7bad924e..e8222bae 100644 --- a/src/renderer/components/SettingsView/SettingsMenu.js +++ b/src/renderer/components/SettingsView/SettingsMenu.js @@ -109,6 +109,14 @@ const StyledTabs = styled(Tabs)` } ` +const StyledTabs = styled(Tabs)` + height: 100vh; + padding-top: 1em; + & .MuiTabs-indicator { + display: none; + } +` + const Row = styled.div` display: flex; flex-direction: row; From e51c12d00ee69b2a2e1ce898dd8579469b37a204 Mon Sep 17 00:00:00 2001 From: lightlii <32508751+lightlii@users.noreply.github.com> Date: Thu, 29 Jun 2023 17:00:07 +0200 Subject: [PATCH 04/51] better menu styling --- src/renderer/components/SettingsView/SettingsMenu.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/renderer/components/SettingsView/SettingsMenu.js b/src/renderer/components/SettingsView/SettingsMenu.js index e8222bae..acd070ee 100644 --- a/src/renderer/components/SettingsView/SettingsMenu.js +++ b/src/renderer/components/SettingsView/SettingsMenu.js @@ -115,6 +115,10 @@ const StyledTabs = styled(Tabs)` & .MuiTabs-indicator { display: none; } + + & .MuiTab-root { + max-width: 100%; + } ` const Row = styled.div` From b35e0ef28a9bbd056abdaa51bddf372419a43ca3 Mon Sep 17 00:00:00 2001 From: lightlii <32508751+lightlii@users.noreply.github.com> Date: Mon, 3 Jul 2023 11:49:01 +0200 Subject: [PATCH 05/51] Revert "Revert "add SettingsMenu tabs component (WIP)"" This reverts commit 108cf020cde1138714f73b0100337ba3d48a351d. --- src/renderer/components/Home.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/renderer/components/Home.js b/src/renderer/components/Home.js index 90a1c4ff..4c8a15cf 100644 --- a/src/renderer/components/Home.js +++ b/src/renderer/components/Home.js @@ -18,6 +18,7 @@ import TitleBarShim from './TitleBarShim' import { defineMessages, useIntl } from 'react-intl' import createPersistedState from '../hooks/createPersistedState' import SyncView from './SyncView' +import { SettingsView } from './SettingsView' import { STATES as updateStates, UpdaterView, UpdateTab } from './UpdaterView' import { SettingsView } from './SettingsView' @@ -180,7 +181,7 @@ const focusStates = { exited: 'blurred' } -function TabPanel (props) { +function TabPanel(props) { const { value, index, @@ -224,7 +225,7 @@ function TabPanel (props) { const useTabIndex = createPersistedState('currentView') -export default function Home ({ onSelectLanguage }) { +export default function Home({ onSelectLanguage }) { const [dialog, setDialog] = React.useState(null) const [error, setError] = React.useState(null) const [tabIndex, setTabIndex] = useTabIndex(0) From 9342e1796c6d2deacbc1bfa1ea076098b8034c8d Mon Sep 17 00:00:00 2001 From: lightlii <32508751+lightlii@users.noreply.github.com> Date: Tue, 4 Jul 2023 14:25:43 +0200 Subject: [PATCH 06/51] fix breaks from bad merge (/revert order) --- src/renderer/components/Home.js | 1 - .../components/SettingsView/SettingsMenu.js | 28 ++++++++++--------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/renderer/components/Home.js b/src/renderer/components/Home.js index 4c8a15cf..accd1ebb 100644 --- a/src/renderer/components/Home.js +++ b/src/renderer/components/Home.js @@ -18,7 +18,6 @@ import TitleBarShim from './TitleBarShim' import { defineMessages, useIntl } from 'react-intl' import createPersistedState from '../hooks/createPersistedState' import SyncView from './SyncView' -import { SettingsView } from './SettingsView' import { STATES as updateStates, UpdaterView, UpdateTab } from './UpdaterView' import { SettingsView } from './SettingsView' diff --git a/src/renderer/components/SettingsView/SettingsMenu.js b/src/renderer/components/SettingsView/SettingsMenu.js index acd070ee..70d048e9 100644 --- a/src/renderer/components/SettingsView/SettingsMenu.js +++ b/src/renderer/components/SettingsView/SettingsMenu.js @@ -37,19 +37,21 @@ export const SettingsMenu = ({ tabs, currentTab, onTabChange }) => { value={currentTab} onChange={(e, newValue) => onTabChange(newValue)} > - {tabs.map(tab => ( - - ))} - - + { + tabs.map(tab => ( + + )) + } + + ) } From 467263fca5d1ff7491ce759ab76511ae7794b96b Mon Sep 17 00:00:00 2001 From: lightlii <32508751+lightlii@users.noreply.github.com> Date: Thu, 13 Jul 2023 14:24:56 +0200 Subject: [PATCH 07/51] chore: better jsdoc typing --- .../components/SettingsView/SettingsMenu.js | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/renderer/components/SettingsView/SettingsMenu.js b/src/renderer/components/SettingsView/SettingsMenu.js index 70d048e9..8500f592 100644 --- a/src/renderer/components/SettingsView/SettingsMenu.js +++ b/src/renderer/components/SettingsView/SettingsMenu.js @@ -29,7 +29,7 @@ export const SettingsMenu = ({ tabs, currentTab, onTabChange }) => { height: '100vh', borderRadius: 0, zIndex: 1, - position: 'relative' + position: 'relative', }} > { } const RenderTab = React.forwardRef( - ( - { tab: { icon: Icon, label, subtitle }, active, children, ...rest }, - ref - ) => { + ({ tab: { icon: Icon, label, subtitle }, active, children, ...rest }, ref) => { const { formatMessage: t } = useIntl() const theme = useTheme() return ( - - {Icon ? : null} - + {Icon ? : null} {typeof label === 'string' ? label : t(label)} @@ -87,7 +82,7 @@ const RenderTab = React.forwardRef( textTransform: 'none', textAlign: 'left', cursor: 'pointer', - color: theme.palette.grey['700'] + color: theme.palette.grey['700'], }} > {typeof subtitle === 'string' ? subtitle : t(subtitle)} @@ -96,7 +91,7 @@ const RenderTab = React.forwardRef( ) - } + }, ) const StyledTabs = styled(Tabs)` From e44e6786246b9ff4bb13060139731e90d73300bf Mon Sep 17 00:00:00 2001 From: lightlii <32508751+lightlii@users.noreply.github.com> Date: Fri, 14 Jul 2023 13:29:55 +0200 Subject: [PATCH 08/51] chore: add better typing --- .../components/SettingsView/SettingsMenu.js | 17 +++++++++++------ src/renderer/components/SettingsView/index.js | 6 +++--- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/renderer/components/SettingsView/SettingsMenu.js b/src/renderer/components/SettingsView/SettingsMenu.js index 8500f592..70d048e9 100644 --- a/src/renderer/components/SettingsView/SettingsMenu.js +++ b/src/renderer/components/SettingsView/SettingsMenu.js @@ -29,7 +29,7 @@ export const SettingsMenu = ({ tabs, currentTab, onTabChange }) => { height: '100vh', borderRadius: 0, zIndex: 1, - position: 'relative', + position: 'relative' }} > { } const RenderTab = React.forwardRef( - ({ tab: { icon: Icon, label, subtitle }, active, children, ...rest }, ref) => { + ( + { tab: { icon: Icon, label, subtitle }, active, children, ...rest }, + ref + ) => { const { formatMessage: t } = useIntl() const theme = useTheme() return ( - {Icon ? : null} + + {Icon ? : null} + {typeof label === 'string' ? label : t(label)} @@ -82,7 +87,7 @@ const RenderTab = React.forwardRef( textTransform: 'none', textAlign: 'left', cursor: 'pointer', - color: theme.palette.grey['700'], + color: theme.palette.grey['700'] }} > {typeof subtitle === 'string' ? subtitle : t(subtitle)} @@ -91,7 +96,7 @@ const RenderTab = React.forwardRef( ) - }, + } ) const StyledTabs = styled(Tabs)` diff --git a/src/renderer/components/SettingsView/index.js b/src/renderer/components/SettingsView/index.js index 8ccca6ef..5ad0ad3a 100644 --- a/src/renderer/components/SettingsView/index.js +++ b/src/renderer/components/SettingsView/index.js @@ -7,7 +7,7 @@ import styled from 'styled-components' const m = defineMessages({ aboutMapeo: 'About Mapeo', - aboutMapeoSubtitle: 'Version and build number', + aboutMapeoSubtitle: 'Version and build number' }) const tabs = [ @@ -16,8 +16,8 @@ const tabs = [ tabId: 'AboutMapeo', icon: InfoIcon, label: m.aboutMapeo, - subtitle: m.aboutMapeoSubtitle, - }, + subtitle: m.aboutMapeoSubtitle + } ] export const SettingsView = () => { From 3ea703b80165840e854e994b2223a518fda504ad Mon Sep 17 00:00:00 2001 From: lightlii <32508751+lightlii@users.noreply.github.com> Date: Fri, 14 Jul 2023 13:46:58 +0200 Subject: [PATCH 09/51] chore: more improved typing --- src/renderer/components/SettingsView/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/renderer/components/SettingsView/index.js b/src/renderer/components/SettingsView/index.js index 5ad0ad3a..8ccca6ef 100644 --- a/src/renderer/components/SettingsView/index.js +++ b/src/renderer/components/SettingsView/index.js @@ -7,7 +7,7 @@ import styled from 'styled-components' const m = defineMessages({ aboutMapeo: 'About Mapeo', - aboutMapeoSubtitle: 'Version and build number' + aboutMapeoSubtitle: 'Version and build number', }) const tabs = [ @@ -16,8 +16,8 @@ const tabs = [ tabId: 'AboutMapeo', icon: InfoIcon, label: m.aboutMapeo, - subtitle: m.aboutMapeoSubtitle - } + subtitle: m.aboutMapeoSubtitle, + }, ] export const SettingsView = () => { From 6ebab38b15fc31f900a550aff998b0d4a2efb7ac Mon Sep 17 00:00:00 2001 From: lightlii <32508751+lightlii@users.noreply.github.com> Date: Wed, 12 Jul 2023 15:33:19 +0200 Subject: [PATCH 10/51] add experiments menu --- .../BackgroundMaps/BackgroundMapInfo.js | 138 ++++++++++++++++++ .../components/BackgroundMaps/MapCard.js | 93 ++++++++++++ .../components/BackgroundMaps/SidePanel.js | 105 +++++++++++++ .../components/SettingsView/BackgroundMaps.js | 76 ++++++++++ .../SettingsView/ExperimentsMenu.js | 30 ++++ .../components/SettingsView/SettingsItem.js | 91 ++++++++++++ .../components/SettingsView/SettingsMenu.js | 53 +------ src/renderer/components/SettingsView/index.js | 13 +- .../components/dialogs/ImportMapStyle.js | 109 ++++++++++++++ 9 files changed, 660 insertions(+), 48 deletions(-) create mode 100644 src/renderer/components/BackgroundMaps/BackgroundMapInfo.js create mode 100644 src/renderer/components/BackgroundMaps/MapCard.js create mode 100644 src/renderer/components/BackgroundMaps/SidePanel.js create mode 100644 src/renderer/components/SettingsView/BackgroundMaps.js create mode 100644 src/renderer/components/SettingsView/ExperimentsMenu.js create mode 100644 src/renderer/components/SettingsView/SettingsItem.js create mode 100644 src/renderer/components/dialogs/ImportMapStyle.js diff --git a/src/renderer/components/BackgroundMaps/BackgroundMapInfo.js b/src/renderer/components/BackgroundMaps/BackgroundMapInfo.js new file mode 100644 index 00000000..03cc6efc --- /dev/null +++ b/src/renderer/components/BackgroundMaps/BackgroundMapInfo.js @@ -0,0 +1,138 @@ +// @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' + +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 ( + + + {!data ? ( + + ) : ( + + + {/* Text */} +
+ + {data.name} + + {data.zoom && {t(m.zoomLevel, { zoom: data.zoom })}} + {`${Math.round(convertKbToMb(size))} ${t(m.mb)}`} +
+
+ )} +
+
+ ) +} + +/** + * @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 ( + + {/* Banner */} + + {name} + +
+ +
+
+ + {/* Map */} + +
+ ) +} + +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', + }, +}) diff --git a/src/renderer/components/BackgroundMaps/MapCard.js b/src/renderer/components/BackgroundMaps/MapCard.js new file mode 100644 index 00000000..a018bd2a --- /dev/null +++ b/src/renderer/components/BackgroundMaps/MapCard.js @@ -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>} setMap + * @prop {boolean } isBeingViewed + */ + +/** @param {MapCardProps} param */ +export const MapCard = ({ offlineMap, setMap, isBeingViewed }) => { + const classes = useStyles() + const { formatMessage: t } = useIntl() + + return ( + + ) +} + +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, + }, +}) diff --git a/src/renderer/components/BackgroundMaps/SidePanel.js b/src/renderer/components/BackgroundMaps/SidePanel.js new file mode 100644 index 00000000..56eac5f2 --- /dev/null +++ b/src/renderer/components/BackgroundMaps/SidePanel.js @@ -0,0 +1,105 @@ +// @ts-check +import { Button, makeStyles } from '@material-ui/core' +import ChevronLeft from '@material-ui/icons/ChevronLeft' +import * as React from 'react' +import { defineMessages, useIntl } from 'react-intl' +import { useMapServerQuery } from '../../hooks/useMapServerQuery' +import { ImportMapStyleDialog } from '../dialogs/ImportMapStyle' +import Loader from '../Loader' +import { MapCard } from './MapCard' + +const m = defineMessages({ + // Button to add map background + addMap: 'Add Map Background', + // Button to create an offline area for a map backgroun + createOfflineMap: 'Create Offline Map', + // button to go back to settings + backToSettings: 'Back to Settings', +}) +/** + * @typedef SidePanelProps + * @prop {()=>void} openSettings + * @prop {string|false} mapValue + * @prop {React.Dispatch>} setMapValue + */ + +/** @param {SidePanelProps} param */ +export const SidePanel = ({ openSettings, mapValue, setMapValue }) => { + const { formatMessage: t } = useIntl() + + const classes = useStyles() + const [open, setOpen] = React.useState(false) + + const { data, isLoading } = useMapServerQuery('/styles', true) + + return ( + +
+ +
+ +
+ + {isLoading ? ( + + ) : data ? ( + data.map(offlineMap => ( + + )) + ) : null} +
+ setOpen(false)} /> +
+ ) +} + +const useStyles = makeStyles({ + sidePanel: { + width: 'auto', + borderRight: '1px solid #E0E0E0', + height: '100%', + display: 'flex', + flexDirection: 'column', + alignItems: 'center', + minWidth: '35%', + }, + buttonContainer: { + display: 'flex', + justifyContent: 'space-between', + padding: 20, + }, + button: { + textTransform: 'none', + fontSize: 12, + }, + firstButton: { + marginRight: 10, + }, + backHeader: { + justifyContent: 'flex-start', + alignSelf: 'flex-start', + paddingLeft: 20, + paddingTop: 20, + paddingBottom: 20, + width: '100%', + display: 'flex', + textTransform: 'none', + '& :first-child': { + marginRight: 20, + }, + }, +}) diff --git a/src/renderer/components/SettingsView/BackgroundMaps.js b/src/renderer/components/SettingsView/BackgroundMaps.js new file mode 100644 index 00000000..d3e96231 --- /dev/null +++ b/src/renderer/components/SettingsView/BackgroundMaps.js @@ -0,0 +1,76 @@ +// @ts-check +import * as React from 'react' +import { defineMessages, useIntl } from 'react-intl' +import Typography from '@material-ui/core/Typography' + +import { BackgroundMapInfo } from '../BackgroundMaps/BackgroundMapInfo' +import { SidePanel } from '../BackgroundMaps/SidePanel' +import { useMapServerQuery } from '../../hooks/useMapServerQuery' + +const m = defineMessages({ + // Title for description of offline maps + mapBackgroundTitle: 'Managing Map Backgrounds and Offline Areas', +}) + +/** @typedef {import('../../hooks/useMapServerQuery').MapServerStyleInfo} MapServerStyleInfo */ + +/** + * @typedef BackgroundMapsProps + * @prop {()=>void} openSettings + */ + +/** @param {BackgroundMapsProps} param */ +export const BackgroundMaps = ({ openSettings }) => { + const { formatMessage: t } = useIntl() + + /** @type {MapServerStyleInfo['id']|false} */ + const initialMapId = /** {const} */ false + + const [mapValue, setMapValue] = React.useState(initialMapId) + + const { data } = useMapServerQuery('/styles') + + function unsetMapValue () { + setMapValue(false) + } + + const offlineMap = React.useMemo(() => data && data.find(m => m.id === mapValue), [data, mapValue]) + + return ( + + + + {!mapValue || !data ? ( +
+ {t(m.mapBackgroundTitle)} + + + Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut + labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris + nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit + esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt + in culpa qui officia deserunt mollit anim id est laborum. +
+
+
+ ) : offlineMap ? ( + + ) : null} +
+ ) +} + +/** + * + * @param {number} kilobyte + * @returns {number} + */ +export const convertKbToMb = kilobyte => { + return kilobyte / 2 ** 20 +} diff --git a/src/renderer/components/SettingsView/ExperimentsMenu.js b/src/renderer/components/SettingsView/ExperimentsMenu.js new file mode 100644 index 00000000..6fcdb4c7 --- /dev/null +++ b/src/renderer/components/SettingsView/ExperimentsMenu.js @@ -0,0 +1,30 @@ +import React, { useState } from 'react' +import { defineMessages } from 'react-intl' +import { Map as MapIcon } from '@material-ui/icons' +import { SettingsMenu } from './SettingsMenu' +import createPersistedState from '../../hooks/createPersistedState' + +const m = defineMessages({ + backgroundMaps: 'Background Maps', + on: 'On', + off: 'Off', +}) + +export const useBackgroundMapsActive = createPersistedState('backgroundMapsActive') + +export const ExperiementsMenu = () => { + const [backgroundMapsActive, setBackgroundMapsActive] = useBackgroundMapsActive(false) + const [menuItem, setMenuItem] = useState(null) + + const tabs = [ + { + tabId: 'BackgroundMaps', + icon: MapIcon, + label: m.backgroundMaps, + subtitle: backgroundMapsActive ? m.on : m.off, + onClick: () => setBackgroundMapsActive(prev => !prev), + }, + ] + + return +} diff --git a/src/renderer/components/SettingsView/SettingsItem.js b/src/renderer/components/SettingsView/SettingsItem.js new file mode 100644 index 00000000..de36d50a --- /dev/null +++ b/src/renderer/components/SettingsView/SettingsItem.js @@ -0,0 +1,91 @@ +import React, { useEffect } from 'react' + +import { Typography, useTheme } from '@material-ui/core' +import ChevronRightIcon from '@material-ui/icons/ChevronRight' + +import { defineMessages, useIntl } from 'react-intl' +import styled from 'styled-components' + +const m = defineMessages({ + on: 'On', + off: 'Off', +}) + +export const SettingsItem = React.forwardRef( + ({ type, label, subtitle, icon: Icon, active, onClick, ...rest }, ref) => { + const theme = useTheme() + const { formatMessage: t } = useIntl() + + return ( + + {Icon ? : null} + + + {typeof label === 'string' ? label : t(label)} + + + {type === 'toggle' ? : } + + + {type === 'menuItem' && } + + ) + }, +) + +const Subtitle = ({ label }) => { + const { formatMessage: t } = useIntl() + return typeof label === 'string' ? label : t(label) +} + +const ToggleSubtitle = ({ on }) => { + const { formatMessage: t } = useIntl() + + return t(on ? m.on : m.off) +} + +const Row = styled.div` + display: flex; + flex-direction: row; +` + +const Column = styled.div` + display: flex; + flex-direction: column; +` + +const WrapperRow = styled(Row)` + padding: 20px; + align-items: center; + justify-content: space-between; + cursor: pointer; +` + +const IconContainer = styled.div` + flex: 1; + padding: 10px 30px 10px 10px; + display: flex; + align-items: center; +` + +const TitleContainer = styled(Column)` + justify-content: flex-start; + flex: 8; +` diff --git a/src/renderer/components/SettingsView/SettingsMenu.js b/src/renderer/components/SettingsView/SettingsMenu.js index 70d048e9..39100135 100644 --- a/src/renderer/components/SettingsView/SettingsMenu.js +++ b/src/renderer/components/SettingsView/SettingsMenu.js @@ -1,10 +1,9 @@ import * as React from 'react' import Tabs from '@material-ui/core/Tabs' import Tab from '@material-ui/core/Tab' -import { useIntl } from 'react-intl' -import ChevronRightIcon from '@material-ui/icons/ChevronRight' import styled from 'styled-components' -import { Paper, Typography, useTheme } from '@material-ui/core' +import { Paper } from '@material-ui/core' +import { SettingsItem } from './SettingsItem' /** @typedef {'AboutMapeo'} tabId */ @@ -25,7 +24,7 @@ export const SettingsMenu = ({ tabs, currentTab, onTabChange }) => { return ( { ) } -const RenderTab = React.forwardRef( - ( - { tab: { icon: Icon, label, subtitle }, active, children, ...rest }, - ref - ) => { - const { formatMessage: t } = useIntl() - const theme = useTheme() - - return ( - - - {Icon ? : null} - - - - {typeof label === 'string' ? label : t(label)} - - - {typeof subtitle === 'string' ? subtitle : t(subtitle)} - - - - - ) - } -) +export const RenderTab = React.forwardRef(({ tab: { icon, label, subtitle }, ...rest }, ref) => ( + +)) const StyledTabs = styled(Tabs)` height: 100vh; diff --git a/src/renderer/components/SettingsView/index.js b/src/renderer/components/SettingsView/index.js index 8ccca6ef..d036ffb7 100644 --- a/src/renderer/components/SettingsView/index.js +++ b/src/renderer/components/SettingsView/index.js @@ -1,16 +1,20 @@ import React, { useState } from 'react' import InfoIcon from '@material-ui/icons/InfoOutlined' +import FlagIcon from '@material-ui/icons/Flag' import { SettingsMenu } from './SettingsMenu' import { defineMessages } from 'react-intl' import { AboutMapeoMenu } from './AboutMapeo' import styled from 'styled-components' +import { ExperiementsMenu } from './ExperimentsMenu' const m = defineMessages({ aboutMapeo: 'About Mapeo', aboutMapeoSubtitle: 'Version and build number', + experiments: 'Experiments', + experimentsSubtitle: 'Turn on experimental new features', }) -const tabs = [ +const tabs = /** @typedef {const} */[ { /** @type {import('./SettingsMenu').tabId} */ tabId: 'AboutMapeo', @@ -18,6 +22,12 @@ const tabs = [ label: m.aboutMapeo, subtitle: m.aboutMapeoSubtitle, }, + { + tabId: 'Experiments', + icon: FlagIcon, + label: m.experiments, + subtitle: m.experimentsSubtitle, + }, ] export const SettingsView = () => { @@ -29,6 +39,7 @@ export const SettingsView = () => { {menuItem === 'AboutMapeo' && } + {menuItem === 'Experiments' && } ) } diff --git a/src/renderer/components/dialogs/ImportMapStyle.js b/src/renderer/components/dialogs/ImportMapStyle.js new file mode 100644 index 00000000..de8c9349 --- /dev/null +++ b/src/renderer/components/dialogs/ImportMapStyle.js @@ -0,0 +1,109 @@ +// @ts-check +import * as React from 'react' +import { Button, CardActionArea, makeStyles, Typography } from '@material-ui/core' +import Dialog from '@material-ui/core/Dialog' +import DialogTitle from '@material-ui/core/DialogTitle' +import DialogActions from '@material-ui/core/DialogActions' +import DialogContent from '@material-ui/core/DialogContent' +import { defineMessages, useIntl } from 'react-intl' +import { useMapServerMutation } from '../../hooks/useMapServerMutation' +import Card from '@material-ui/core/Card' +import CardContent from '@material-ui/core/CardContent' +import { remote } from 'electron' +import SystemUpdateAltIcon from '@material-ui/icons/SystemUpdateAlt' +import CloseIcon from '@material-ui/icons/Close' +import IconButton from '@material-ui/core/IconButton' + +const m = defineMessages({ + // Title of screen used to add a new background map + addMap: 'Add Map Background', + // button to cancel the import of a background map + cancel: 'Cancel', + // Title for import errot pop up dialog, + importErrorTitle: 'Background Maps Import Error', + // Description of map import error + importErrorDescription: 'There was an error importing the background maps. Please try again.', +}) + +/** + * @typedef ImportMapStyleDialogProps + * @prop {boolean} open + * @prop {()=>void} close + */ + +/** @param {ImportMapStyleDialogProps} importMapStyleDialogProps */ +export const ImportMapStyleDialog = ({ open, close }) => { + const { formatMessage: t } = useIntl() + const mutation = useMapServerMutation('post', '/tilesets/import') + + const classes = useStyles() + + async function selectMbTileFile () { + const result = await remote.dialog.showOpenDialog({ + filters: [{ name: 'MbTiles', extensions: ['mbtiles'] }], + properties: ['openFile'], + }) + + if (result.canceled) return + + if (!result.filePaths || !result.filePaths.length) return + + try { + const filePath = result.filePaths[0] + await mutation.mutateAsync({ filePath }) + close() + } catch (err) { + close() + onError(err) + } + + function onError (err) { + remote.dialog.showErrorBox(t(m.importErrorTitle), t(m.importErrorDescription) + ': ' + err) + } + } + + return ( + + + + {t(m.addMap)} + + + + + + + + + + + + Import File + + + {'(.mbtiles)'} + + + + + + + + + + ) +} + +const useStyles = makeStyles({ + titleContainer: { + display: 'flex', + alignItems: 'center', + justifyContent: 'space-between', + }, + title: { + fontSize: 24, + fontWeight: 500, + }, +}) From f39b76b19ae665537edbbf9e3498e6ad05101fd6 Mon Sep 17 00:00:00 2001 From: lightlii <32508751+lightlii@users.noreply.github.com> Date: Fri, 14 Jul 2023 11:51:59 +0200 Subject: [PATCH 11/51] chore: usability improvements to settings list items --- .../SettingsView/ExperimentsMenu.js | 29 +++++---- .../{SettingsItem.js => SettingsList.js} | 36 +++++++++-- .../components/SettingsView/SettingsMenu.js | 6 +- src/renderer/components/SettingsView/index.js | 59 +++++++++++++------ 4 files changed, 90 insertions(+), 40 deletions(-) rename src/renderer/components/SettingsView/{SettingsItem.js => SettingsList.js} (73%) diff --git a/src/renderer/components/SettingsView/ExperimentsMenu.js b/src/renderer/components/SettingsView/ExperimentsMenu.js index 6fcdb4c7..91fb931c 100644 --- a/src/renderer/components/SettingsView/ExperimentsMenu.js +++ b/src/renderer/components/SettingsView/ExperimentsMenu.js @@ -1,30 +1,29 @@ -import React, { useState } from 'react' +import React from 'react' import { defineMessages } from 'react-intl' import { Map as MapIcon } from '@material-ui/icons' -import { SettingsMenu } from './SettingsMenu' -import createPersistedState from '../../hooks/createPersistedState' +import { SettingsList } from './SettingsList' const m = defineMessages({ backgroundMaps: 'Background Maps', - on: 'On', - off: 'Off', }) -export const useBackgroundMapsActive = createPersistedState('backgroundMapsActive') +export const ExperiementsMenu = ({ backgroundMaps, setBackgroundMaps }) => { + const toggleBackgroundMaps = () => { + setBackgroundMaps(prevState => { + return !prevState + }) + } -export const ExperiementsMenu = () => { - const [backgroundMapsActive, setBackgroundMapsActive] = useBackgroundMapsActive(false) - const [menuItem, setMenuItem] = useState(null) - - const tabs = [ + const options = [ { - tabId: 'BackgroundMaps', + id: 'BackgroundMaps', icon: MapIcon, label: m.backgroundMaps, - subtitle: backgroundMapsActive ? m.on : m.off, - onClick: () => setBackgroundMapsActive(prev => !prev), + checked: backgroundMaps, + onClick: toggleBackgroundMaps, + type: 'toggle', }, ] - return + return } diff --git a/src/renderer/components/SettingsView/SettingsItem.js b/src/renderer/components/SettingsView/SettingsList.js similarity index 73% rename from src/renderer/components/SettingsView/SettingsItem.js rename to src/renderer/components/SettingsView/SettingsList.js index de36d50a..a452dd8c 100644 --- a/src/renderer/components/SettingsView/SettingsItem.js +++ b/src/renderer/components/SettingsView/SettingsList.js @@ -1,18 +1,30 @@ -import React, { useEffect } from 'react' +import React from 'react' +import styled from 'styled-components' -import { Typography, useTheme } from '@material-ui/core' +import { Switch, Typography, Paper, useTheme } from '@material-ui/core' import ChevronRightIcon from '@material-ui/icons/ChevronRight' import { defineMessages, useIntl } from 'react-intl' -import styled from 'styled-components' const m = defineMessages({ on: 'On', off: 'Off', }) +export const SettingsList = ({ options }) => { + return ( + + {options + ? options.map(({ id, onClick, ...rest }) => { + return + }) + : null} + + ) +} + export const SettingsItem = React.forwardRef( - ({ type, label, subtitle, icon: Icon, active, onClick, ...rest }, ref) => { + ({ type, label, subtitle, icon: Icon, active, checked, onClick, ...rest }, ref) => { const theme = useTheme() const { formatMessage: t } = useIntl() @@ -45,13 +57,21 @@ export const SettingsItem = React.forwardRef( {type === 'menuItem' && } + {type === 'toggle' && } ) }, ) +const Stack = styled(Paper)` + display: flex; + flex-direction: column; + gap: ${props => props.gap || '10px'}; +` const Subtitle = ({ label }) => { const { formatMessage: t } = useIntl() + if (!label) return null + return typeof label === 'string' ? label : t(label) } @@ -76,6 +96,10 @@ const WrapperRow = styled(Row)` align-items: center; justify-content: space-between; cursor: pointer; + + .MuiSwitch-root { + margin-left: 30px; + } ` const IconContainer = styled.div` @@ -88,4 +112,8 @@ const IconContainer = styled.div` const TitleContainer = styled(Column)` justify-content: flex-start; flex: 8; + + * { + user-select: none; + } ` diff --git a/src/renderer/components/SettingsView/SettingsMenu.js b/src/renderer/components/SettingsView/SettingsMenu.js index 39100135..242572dc 100644 --- a/src/renderer/components/SettingsView/SettingsMenu.js +++ b/src/renderer/components/SettingsView/SettingsMenu.js @@ -3,7 +3,7 @@ import Tabs from '@material-ui/core/Tabs' import Tab from '@material-ui/core/Tab' import styled from 'styled-components' import { Paper } from '@material-ui/core' -import { SettingsItem } from './SettingsItem' +import { SettingsItem } from './SettingsList' /** @typedef {'AboutMapeo'} tabId */ @@ -54,8 +54,8 @@ export const SettingsMenu = ({ tabs, currentTab, onTabChange }) => { ) } -export const RenderTab = React.forwardRef(({ tab: { icon, label, subtitle }, ...rest }, ref) => ( - +export const RenderTab = React.forwardRef(({ tab: { icon, label, subtitle, type }, ...rest }, ref) => ( + )) const StyledTabs = styled(Tabs)` diff --git a/src/renderer/components/SettingsView/index.js b/src/renderer/components/SettingsView/index.js index d036ffb7..aa27e7b4 100644 --- a/src/renderer/components/SettingsView/index.js +++ b/src/renderer/components/SettingsView/index.js @@ -1,45 +1,61 @@ import React, { useState } from 'react' import InfoIcon from '@material-ui/icons/InfoOutlined' import FlagIcon from '@material-ui/icons/Flag' +import MapIcon from '@material-ui/icons/Map' import { SettingsMenu } from './SettingsMenu' import { defineMessages } from 'react-intl' import { AboutMapeoMenu } from './AboutMapeo' import styled from 'styled-components' import { ExperiementsMenu } from './ExperimentsMenu' +import createPersistedState from '../../hooks/createPersistedState' const m = defineMessages({ aboutMapeo: 'About Mapeo', aboutMapeoSubtitle: 'Version and build number', experiments: 'Experiments', experimentsSubtitle: 'Turn on experimental new features', + backgroundMaps: 'Background maps', }) -const tabs = /** @typedef {const} */[ - { - /** @type {import('./SettingsMenu').tabId} */ - tabId: 'AboutMapeo', - icon: InfoIcon, - label: m.aboutMapeo, - subtitle: m.aboutMapeoSubtitle, - }, - { - tabId: 'Experiments', - icon: FlagIcon, - label: m.experiments, - subtitle: m.experimentsSubtitle, - }, -] +const useExperimentsFlagsState = createPersistedState('experimentsFlags') export const SettingsView = () => { - /** @type {import('./SettingsMenu').tabId | null} */ - const initialMenuState = /** {const} */ null + const [backgroundMaps, setBackgroundMaps] = useExperimentsFlagsState(false) + const tabs = /** @typedef {const} */[ + { + /** @type {import('./SettingsMenu').tabId} */ + tabId: 'AboutMapeo', + icon: InfoIcon, + label: m.aboutMapeo, + subtitle: m.aboutMapeoSubtitle, + }, + { + tabId: 'Experiments', + icon: FlagIcon, + label: m.experiments, + subtitle: m.experimentsSubtitle, + }, + ...(backgroundMaps + ? [ + { + tabId: 'BackgroundMaps', + icon: MapIcon, + label: m.backgroundMaps, + }, + ] + : []), + ] + const initialMenuState = /** {null | number} */ null const [menuItem, setMenuItem] = useState(initialMenuState) return ( {menuItem === 'AboutMapeo' && } - {menuItem === 'Experiments' && } + {menuItem === 'Experiments' && ( + + )} + {menuItem === 'BackgroundMaps' && } ) } @@ -48,3 +64,10 @@ const Container = styled.div` width: 100%; display: flex; ` + +const Boc = styled.div` + +background-color: red +height: 200px; +width:100px; +` From 9bfeb19a7c4454b045e71c159807c3f0150212bd Mon Sep 17 00:00:00 2001 From: lightlii <32508751+lightlii@users.noreply.github.com> Date: Fri, 14 Jul 2023 12:14:19 +0200 Subject: [PATCH 12/51] autogenerated translations file --- messages/renderer/en.json | 86 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/messages/renderer/en.json b/messages/renderer/en.json index 7deaed5f..08eae78d 100644 --- a/messages/renderer/en.json +++ b/messages/renderer/en.json @@ -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" @@ -474,12 +522,34 @@ "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.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" @@ -636,6 +706,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" }, From bab7bcc28742148effd2388cf442e8a60551bbaa Mon Sep 17 00:00:00 2001 From: lightlii <32508751+lightlii@users.noreply.github.com> Date: Wed, 12 Jul 2023 15:33:19 +0200 Subject: [PATCH 13/51] add experiments menu --- .../components/SettingsView/SettingsItem.js | 91 +++++++++++++++++++ .../components/SettingsView/SettingsMenu.js | 2 +- 2 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 src/renderer/components/SettingsView/SettingsItem.js diff --git a/src/renderer/components/SettingsView/SettingsItem.js b/src/renderer/components/SettingsView/SettingsItem.js new file mode 100644 index 00000000..de36d50a --- /dev/null +++ b/src/renderer/components/SettingsView/SettingsItem.js @@ -0,0 +1,91 @@ +import React, { useEffect } from 'react' + +import { Typography, useTheme } from '@material-ui/core' +import ChevronRightIcon from '@material-ui/icons/ChevronRight' + +import { defineMessages, useIntl } from 'react-intl' +import styled from 'styled-components' + +const m = defineMessages({ + on: 'On', + off: 'Off', +}) + +export const SettingsItem = React.forwardRef( + ({ type, label, subtitle, icon: Icon, active, onClick, ...rest }, ref) => { + const theme = useTheme() + const { formatMessage: t } = useIntl() + + return ( + + {Icon ? : null} + + + {typeof label === 'string' ? label : t(label)} + + + {type === 'toggle' ? : } + + + {type === 'menuItem' && } + + ) + }, +) + +const Subtitle = ({ label }) => { + const { formatMessage: t } = useIntl() + return typeof label === 'string' ? label : t(label) +} + +const ToggleSubtitle = ({ on }) => { + const { formatMessage: t } = useIntl() + + return t(on ? m.on : m.off) +} + +const Row = styled.div` + display: flex; + flex-direction: row; +` + +const Column = styled.div` + display: flex; + flex-direction: column; +` + +const WrapperRow = styled(Row)` + padding: 20px; + align-items: center; + justify-content: space-between; + cursor: pointer; +` + +const IconContainer = styled.div` + flex: 1; + padding: 10px 30px 10px 10px; + display: flex; + align-items: center; +` + +const TitleContainer = styled(Column)` + justify-content: flex-start; + flex: 8; +` diff --git a/src/renderer/components/SettingsView/SettingsMenu.js b/src/renderer/components/SettingsView/SettingsMenu.js index 242572dc..d08d8545 100644 --- a/src/renderer/components/SettingsView/SettingsMenu.js +++ b/src/renderer/components/SettingsView/SettingsMenu.js @@ -28,7 +28,7 @@ export const SettingsMenu = ({ tabs, currentTab, onTabChange }) => { height: '100vh', borderRadius: 0, zIndex: 1, - position: 'relative' + position: 'relative', }} > Date: Fri, 14 Jul 2023 14:04:43 +0200 Subject: [PATCH 14/51] chore: add ExperimentsMenu types --- src/renderer/components/SettingsView/ExperimentsMenu.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/renderer/components/SettingsView/ExperimentsMenu.js b/src/renderer/components/SettingsView/ExperimentsMenu.js index 91fb931c..8dc0f6d2 100644 --- a/src/renderer/components/SettingsView/ExperimentsMenu.js +++ b/src/renderer/components/SettingsView/ExperimentsMenu.js @@ -7,6 +7,13 @@ const m = defineMessages({ backgroundMaps: 'Background Maps', }) +/** + * @typedef ExperiementsMenuProps + * @prop {boolean} backgroundMaps + * @prop {(e: React.Dispatch) => number} setBackgroundMaps + */ + +/** @param {ExperiementsMenuProps} props */ export const ExperiementsMenu = ({ backgroundMaps, setBackgroundMaps }) => { const toggleBackgroundMaps = () => { setBackgroundMaps(prevState => { From 80ff0410f380d71d911a43b439a5c144d0c45158 Mon Sep 17 00:00:00 2001 From: lightlii <32508751+lightlii@users.noreply.github.com> Date: Fri, 14 Jul 2023 14:04:55 +0200 Subject: [PATCH 15/51] chore: styling fixes --- src/renderer/components/SettingsView/SettingsList.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/renderer/components/SettingsView/SettingsList.js b/src/renderer/components/SettingsView/SettingsList.js index a452dd8c..3286755b 100644 --- a/src/renderer/components/SettingsView/SettingsList.js +++ b/src/renderer/components/SettingsView/SettingsList.js @@ -67,6 +67,10 @@ const Stack = styled(Paper)` display: flex; flex-direction: column; gap: ${props => props.gap || '10px'}; + + &.MuiPaper-rounded { + border-radius: 0; + } ` const Subtitle = ({ label }) => { const { formatMessage: t } = useIntl() From 9f9e08682b9db5f4079a04f58c5f440ba18672d3 Mon Sep 17 00:00:00 2001 From: lightlii <32508751+lightlii@users.noreply.github.com> Date: Mon, 17 Jul 2023 12:15:51 +0200 Subject: [PATCH 16/51] chore: integrate background maps settings menu --- messages/renderer/en.json | 6 ++ .../components/SettingsView/BackgroundMaps.js | 6 +- .../SettingsView/ExperimentsMenu.js | 1 + .../components/SettingsView/SettingsItem.js | 91 ------------------- .../components/SettingsView/SettingsList.js | 27 ++++++ .../components/SettingsView/SettingsMenu.js | 10 +- src/renderer/components/SettingsView/index.js | 39 ++++---- 7 files changed, 65 insertions(+), 115 deletions(-) delete mode 100644 src/renderer/components/SettingsView/SettingsItem.js diff --git a/messages/renderer/en.json b/messages/renderer/en.json index 08eae78d..40c74337 100644 --- a/messages/renderer/en.json +++ b/messages/renderer/en.json @@ -529,6 +529,12 @@ "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" }, diff --git a/src/renderer/components/SettingsView/BackgroundMaps.js b/src/renderer/components/SettingsView/BackgroundMaps.js index d3e96231..b943eef4 100644 --- a/src/renderer/components/SettingsView/BackgroundMaps.js +++ b/src/renderer/components/SettingsView/BackgroundMaps.js @@ -16,11 +16,11 @@ const m = defineMessages({ /** * @typedef BackgroundMapsProps - * @prop {()=>void} openSettings + * @prop {()=>void} returnToSettings */ /** @param {BackgroundMapsProps} param */ -export const BackgroundMaps = ({ openSettings }) => { +export const BackgroundMaps = ({ returnToSettings }) => { const { formatMessage: t } = useIntl() /** @type {MapServerStyleInfo['id']|false} */ @@ -38,7 +38,7 @@ export const BackgroundMaps = ({ openSettings }) => { return ( - + {!mapValue || !data ? (
diff --git a/src/renderer/components/SettingsView/ExperimentsMenu.js b/src/renderer/components/SettingsView/ExperimentsMenu.js index 8dc0f6d2..d2ec1c86 100644 --- a/src/renderer/components/SettingsView/ExperimentsMenu.js +++ b/src/renderer/components/SettingsView/ExperimentsMenu.js @@ -21,6 +21,7 @@ export const ExperiementsMenu = ({ backgroundMaps, setBackgroundMaps }) => { }) } + /** @type {import('./SettingsList').option[]} */ const options = [ { id: 'BackgroundMaps', diff --git a/src/renderer/components/SettingsView/SettingsItem.js b/src/renderer/components/SettingsView/SettingsItem.js deleted file mode 100644 index de36d50a..00000000 --- a/src/renderer/components/SettingsView/SettingsItem.js +++ /dev/null @@ -1,91 +0,0 @@ -import React, { useEffect } from 'react' - -import { Typography, useTheme } from '@material-ui/core' -import ChevronRightIcon from '@material-ui/icons/ChevronRight' - -import { defineMessages, useIntl } from 'react-intl' -import styled from 'styled-components' - -const m = defineMessages({ - on: 'On', - off: 'Off', -}) - -export const SettingsItem = React.forwardRef( - ({ type, label, subtitle, icon: Icon, active, onClick, ...rest }, ref) => { - const theme = useTheme() - const { formatMessage: t } = useIntl() - - return ( - - {Icon ? : null} - - - {typeof label === 'string' ? label : t(label)} - - - {type === 'toggle' ? : } - - - {type === 'menuItem' && } - - ) - }, -) - -const Subtitle = ({ label }) => { - const { formatMessage: t } = useIntl() - return typeof label === 'string' ? label : t(label) -} - -const ToggleSubtitle = ({ on }) => { - const { formatMessage: t } = useIntl() - - return t(on ? m.on : m.off) -} - -const Row = styled.div` - display: flex; - flex-direction: row; -` - -const Column = styled.div` - display: flex; - flex-direction: column; -` - -const WrapperRow = styled(Row)` - padding: 20px; - align-items: center; - justify-content: space-between; - cursor: pointer; -` - -const IconContainer = styled.div` - flex: 1; - padding: 10px 30px 10px 10px; - display: flex; - align-items: center; -` - -const TitleContainer = styled(Column)` - justify-content: flex-start; - flex: 8; -` diff --git a/src/renderer/components/SettingsView/SettingsList.js b/src/renderer/components/SettingsView/SettingsList.js index 3286755b..5a25f37e 100644 --- a/src/renderer/components/SettingsView/SettingsList.js +++ b/src/renderer/components/SettingsView/SettingsList.js @@ -11,6 +11,20 @@ const m = defineMessages({ off: 'Off', }) +/** + * @typedef {object} option + * @prop {string} option.id + * @prop {boolean} option.checked + * @prop {() => void} option.onClick + * @prop {string | import('react-intl').MessageDescriptor} option.label + * @prop {string | import('react-intl').MessageDescriptor} option.subtitle + * @prop {'menuItem' | 'toggle'} option.type + * @prop {import('@material-ui/core/OverridableComponent').OverridableComponent>} tab.icon + * @typedef SettingsListProps + * @prop {option[]} options + */ + +/** @param {SettingsListProps} props */ export const SettingsList = ({ options }) => { return ( @@ -23,7 +37,20 @@ export const SettingsList = ({ options }) => { ) } +/** + * @typedef SettingsItemProps + * @prop {'menuItem' | 'toggle'} type + * @prop {string | import('react-intl').MessageDescriptor} label + * @prop {string | import('react-intl').MessageDescriptor} subtitle + * @prop {import('@material-ui/core/OverridableComponent').OverridableComponent>} icon + * @prop {boolean} checked + * @prop {boolean} active + * @prop {string} option.id + * @prop {() => void} onClick + */ + export const SettingsItem = React.forwardRef( + /** @param {SettingsItemProps} props */ ({ type, label, subtitle, icon: Icon, active, checked, onClick, ...rest }, ref) => { const theme = useTheme() const { formatMessage: t } = useIntl() diff --git a/src/renderer/components/SettingsView/SettingsMenu.js b/src/renderer/components/SettingsView/SettingsMenu.js index d08d8545..6b0ba087 100644 --- a/src/renderer/components/SettingsView/SettingsMenu.js +++ b/src/renderer/components/SettingsView/SettingsMenu.js @@ -5,13 +5,14 @@ import styled from 'styled-components' import { Paper } from '@material-ui/core' import { SettingsItem } from './SettingsList' -/** @typedef {'AboutMapeo'} tabId */ +/** @typedef {'AboutMapeo'| 'Experiments' | 'BackgroundMaps'} tabId */ /** * @typedef {object} tab * @prop {tabId} tab.tabId * @prop {string | import('react-intl').MessageDescriptor} tab.label * @prop {string | import('react-intl').MessageDescriptor} tab.subtitle + * @prop {'menuItem' | 'toggle'} tab.type * @prop {import('@material-ui/core/OverridableComponent').OverridableComponent>} tab.icon * @typedef SettingsMenuProps * @prop {tab[]} tabs @@ -54,6 +55,13 @@ export const SettingsMenu = ({ tabs, currentTab, onTabChange }) => { ) } +/** + * @typedef RenderTabProps + * @prop {tab} tab + * @prop {number} currentTab + * @prop {(e: React.Dispatch) => number} onTabChange + */ +/** @param {RenderTabProps} props */ export const RenderTab = React.forwardRef(({ tab: { icon, label, subtitle, type }, ...rest }, ref) => ( )) diff --git a/src/renderer/components/SettingsView/index.js b/src/renderer/components/SettingsView/index.js index aa27e7b4..8391da67 100644 --- a/src/renderer/components/SettingsView/index.js +++ b/src/renderer/components/SettingsView/index.js @@ -8,6 +8,7 @@ import { AboutMapeoMenu } from './AboutMapeo' import styled from 'styled-components' import { ExperiementsMenu } from './ExperimentsMenu' import createPersistedState from '../../hooks/createPersistedState' +import { BackgroundMaps } from './BackgroundMaps' const m = defineMessages({ aboutMapeo: 'About Mapeo', @@ -21,9 +22,8 @@ const useExperimentsFlagsState = createPersistedState('experimentsFlags') export const SettingsView = () => { const [backgroundMaps, setBackgroundMaps] = useExperimentsFlagsState(false) - const tabs = /** @typedef {const} */[ + const tabs = /** @type {import('./SettingsMenu').tabs} */ [ { - /** @type {import('./SettingsMenu').tabId} */ tabId: 'AboutMapeo', icon: InfoIcon, label: m.aboutMapeo, @@ -37,12 +37,12 @@ export const SettingsView = () => { }, ...(backgroundMaps ? [ - { - tabId: 'BackgroundMaps', - icon: MapIcon, - label: m.backgroundMaps, - }, - ] + { + tabId: 'BackgroundMaps', + icon: MapIcon, + label: m.backgroundMaps, + }, + ] : []), ] const initialMenuState = /** {null | number} */ null @@ -50,12 +50,17 @@ export const SettingsView = () => { return ( - - {menuItem === 'AboutMapeo' && } - {menuItem === 'Experiments' && ( - + {menuItem === 'BackgroundMaps' ? ( + setMenuItem(initialMenuState)} /> + ) : ( + <> + + {menuItem === 'AboutMapeo' && } + {menuItem === 'Experiments' && ( + + )} + )} - {menuItem === 'BackgroundMaps' && } ) } @@ -63,11 +68,5 @@ export const SettingsView = () => { const Container = styled.div` width: 100%; display: flex; -` - -const Boc = styled.div` - -background-color: red -height: 200px; -width:100px; + height: 100%; ` From 398178df3382cfdb10c3449316c66386487c6ee4 Mon Sep 17 00:00:00 2001 From: lightlii <32508751+lightlii@users.noreply.github.com> Date: Mon, 17 Jul 2023 12:16:06 +0200 Subject: [PATCH 17/51] autogenerated translations file --- messages/renderer/en.json | 6 ------ 1 file changed, 6 deletions(-) diff --git a/messages/renderer/en.json b/messages/renderer/en.json index 40c74337..08eae78d 100644 --- a/messages/renderer/en.json +++ b/messages/renderer/en.json @@ -529,12 +529,6 @@ "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" }, From 1e283feae8f758c4889b7f00d07f5bdb974c1d9e Mon Sep 17 00:00:00 2001 From: lightlii <32508751+lightlii@users.noreply.github.com> Date: Wed, 12 Jul 2023 15:33:19 +0200 Subject: [PATCH 18/51] add experiments menu --- .../components/SettingsView/BackgroundMaps.js | 2 +- .../components/SettingsView/SettingsItem.js | 91 +++++++++++++++++++ .../components/SettingsView/SettingsMenu.js | 28 ------ src/renderer/components/SettingsView/index.js | 14 +-- 4 files changed, 99 insertions(+), 36 deletions(-) create mode 100644 src/renderer/components/SettingsView/SettingsItem.js diff --git a/src/renderer/components/SettingsView/BackgroundMaps.js b/src/renderer/components/SettingsView/BackgroundMaps.js index b943eef4..338e2bc0 100644 --- a/src/renderer/components/SettingsView/BackgroundMaps.js +++ b/src/renderer/components/SettingsView/BackgroundMaps.js @@ -30,7 +30,7 @@ export const BackgroundMaps = ({ returnToSettings }) => { const { data } = useMapServerQuery('/styles') - function unsetMapValue () { + function unsetMapValue() { setMapValue(false) } diff --git a/src/renderer/components/SettingsView/SettingsItem.js b/src/renderer/components/SettingsView/SettingsItem.js new file mode 100644 index 00000000..de36d50a --- /dev/null +++ b/src/renderer/components/SettingsView/SettingsItem.js @@ -0,0 +1,91 @@ +import React, { useEffect } from 'react' + +import { Typography, useTheme } from '@material-ui/core' +import ChevronRightIcon from '@material-ui/icons/ChevronRight' + +import { defineMessages, useIntl } from 'react-intl' +import styled from 'styled-components' + +const m = defineMessages({ + on: 'On', + off: 'Off', +}) + +export const SettingsItem = React.forwardRef( + ({ type, label, subtitle, icon: Icon, active, onClick, ...rest }, ref) => { + const theme = useTheme() + const { formatMessage: t } = useIntl() + + return ( + + {Icon ? : null} + + + {typeof label === 'string' ? label : t(label)} + + + {type === 'toggle' ? : } + + + {type === 'menuItem' && } + + ) + }, +) + +const Subtitle = ({ label }) => { + const { formatMessage: t } = useIntl() + return typeof label === 'string' ? label : t(label) +} + +const ToggleSubtitle = ({ on }) => { + const { formatMessage: t } = useIntl() + + return t(on ? m.on : m.off) +} + +const Row = styled.div` + display: flex; + flex-direction: row; +` + +const Column = styled.div` + display: flex; + flex-direction: column; +` + +const WrapperRow = styled(Row)` + padding: 20px; + align-items: center; + justify-content: space-between; + cursor: pointer; +` + +const IconContainer = styled.div` + flex: 1; + padding: 10px 30px 10px 10px; + display: flex; + align-items: center; +` + +const TitleContainer = styled(Column)` + justify-content: flex-start; + flex: 8; +` diff --git a/src/renderer/components/SettingsView/SettingsMenu.js b/src/renderer/components/SettingsView/SettingsMenu.js index 6b0ba087..09ff57ba 100644 --- a/src/renderer/components/SettingsView/SettingsMenu.js +++ b/src/renderer/components/SettingsView/SettingsMenu.js @@ -89,31 +89,3 @@ const StyledTabs = styled(Tabs)` max-width: 100%; } ` - -const Row = styled.div` - display: flex; - flex-direction: row; -` - -const Column = styled.div` - display: flex; - flex-direction: column; -` - -const WrapperRow = styled(Row)` - padding: 20px; - align-items: center; - justify-content: space-between; -` - -const IconContainer = styled.div` - flex: 1; - padding: 10px 30px 10px 10px; - display: flex; - align-items: center; -` - -const TitleContainer = styled(Column)` - justify-content: flex-start; - flex: 8; -` diff --git a/src/renderer/components/SettingsView/index.js b/src/renderer/components/SettingsView/index.js index 8391da67..dfe9ca80 100644 --- a/src/renderer/components/SettingsView/index.js +++ b/src/renderer/components/SettingsView/index.js @@ -22,7 +22,7 @@ const useExperimentsFlagsState = createPersistedState('experimentsFlags') export const SettingsView = () => { const [backgroundMaps, setBackgroundMaps] = useExperimentsFlagsState(false) - const tabs = /** @type {import('./SettingsMenu').tabs} */ [ + const tabs = /** @type {import('./SettingsMenu').tabs} */[ { tabId: 'AboutMapeo', icon: InfoIcon, @@ -37,12 +37,12 @@ export const SettingsView = () => { }, ...(backgroundMaps ? [ - { - tabId: 'BackgroundMaps', - icon: MapIcon, - label: m.backgroundMaps, - }, - ] + { + tabId: 'BackgroundMaps', + icon: MapIcon, + label: m.backgroundMaps, + }, + ] : []), ] const initialMenuState = /** {null | number} */ null From 47c9d6142e31e529fbf6fc1d94b9aa60baaef7cc Mon Sep 17 00:00:00 2001 From: lightlii <32508751+lightlii@users.noreply.github.com> Date: Fri, 14 Jul 2023 11:51:59 +0200 Subject: [PATCH 19/51] chore: usability improvements to settings list items --- .../components/SettingsView/SettingsItem.js | 91 ------------------- .../components/SettingsView/SettingsList.js | 4 +- src/renderer/components/SettingsView/index.js | 7 ++ 3 files changed, 9 insertions(+), 93 deletions(-) delete mode 100644 src/renderer/components/SettingsView/SettingsItem.js diff --git a/src/renderer/components/SettingsView/SettingsItem.js b/src/renderer/components/SettingsView/SettingsItem.js deleted file mode 100644 index de36d50a..00000000 --- a/src/renderer/components/SettingsView/SettingsItem.js +++ /dev/null @@ -1,91 +0,0 @@ -import React, { useEffect } from 'react' - -import { Typography, useTheme } from '@material-ui/core' -import ChevronRightIcon from '@material-ui/icons/ChevronRight' - -import { defineMessages, useIntl } from 'react-intl' -import styled from 'styled-components' - -const m = defineMessages({ - on: 'On', - off: 'Off', -}) - -export const SettingsItem = React.forwardRef( - ({ type, label, subtitle, icon: Icon, active, onClick, ...rest }, ref) => { - const theme = useTheme() - const { formatMessage: t } = useIntl() - - return ( - - {Icon ? : null} - - - {typeof label === 'string' ? label : t(label)} - - - {type === 'toggle' ? : } - - - {type === 'menuItem' && } - - ) - }, -) - -const Subtitle = ({ label }) => { - const { formatMessage: t } = useIntl() - return typeof label === 'string' ? label : t(label) -} - -const ToggleSubtitle = ({ on }) => { - const { formatMessage: t } = useIntl() - - return t(on ? m.on : m.off) -} - -const Row = styled.div` - display: flex; - flex-direction: row; -` - -const Column = styled.div` - display: flex; - flex-direction: column; -` - -const WrapperRow = styled(Row)` - padding: 20px; - align-items: center; - justify-content: space-between; - cursor: pointer; -` - -const IconContainer = styled.div` - flex: 1; - padding: 10px 30px 10px 10px; - display: flex; - align-items: center; -` - -const TitleContainer = styled(Column)` - justify-content: flex-start; - flex: 8; -` diff --git a/src/renderer/components/SettingsView/SettingsList.js b/src/renderer/components/SettingsView/SettingsList.js index 5a25f37e..c15b9724 100644 --- a/src/renderer/components/SettingsView/SettingsList.js +++ b/src/renderer/components/SettingsView/SettingsList.js @@ -30,8 +30,8 @@ export const SettingsList = ({ options }) => { {options ? options.map(({ id, onClick, ...rest }) => { - return - }) + return + }) : null} ) diff --git a/src/renderer/components/SettingsView/index.js b/src/renderer/components/SettingsView/index.js index dfe9ca80..9a0f01df 100644 --- a/src/renderer/components/SettingsView/index.js +++ b/src/renderer/components/SettingsView/index.js @@ -70,3 +70,10 @@ const Container = styled.div` display: flex; height: 100%; ` + +const Boc = styled.div` + +background-color: red +height: 200px; +width:100px; +` From b3ee3ddd49f8b953c6e33b1064077acf9fd2fb43 Mon Sep 17 00:00:00 2001 From: lightlii <32508751+lightlii@users.noreply.github.com> Date: Wed, 12 Jul 2023 15:33:19 +0200 Subject: [PATCH 20/51] add experiments menu --- .../components/SettingsView/SettingsItem.js | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 src/renderer/components/SettingsView/SettingsItem.js diff --git a/src/renderer/components/SettingsView/SettingsItem.js b/src/renderer/components/SettingsView/SettingsItem.js new file mode 100644 index 00000000..de36d50a --- /dev/null +++ b/src/renderer/components/SettingsView/SettingsItem.js @@ -0,0 +1,91 @@ +import React, { useEffect } from 'react' + +import { Typography, useTheme } from '@material-ui/core' +import ChevronRightIcon from '@material-ui/icons/ChevronRight' + +import { defineMessages, useIntl } from 'react-intl' +import styled from 'styled-components' + +const m = defineMessages({ + on: 'On', + off: 'Off', +}) + +export const SettingsItem = React.forwardRef( + ({ type, label, subtitle, icon: Icon, active, onClick, ...rest }, ref) => { + const theme = useTheme() + const { formatMessage: t } = useIntl() + + return ( + + {Icon ? : null} + + + {typeof label === 'string' ? label : t(label)} + + + {type === 'toggle' ? : } + + + {type === 'menuItem' && } + + ) + }, +) + +const Subtitle = ({ label }) => { + const { formatMessage: t } = useIntl() + return typeof label === 'string' ? label : t(label) +} + +const ToggleSubtitle = ({ on }) => { + const { formatMessage: t } = useIntl() + + return t(on ? m.on : m.off) +} + +const Row = styled.div` + display: flex; + flex-direction: row; +` + +const Column = styled.div` + display: flex; + flex-direction: column; +` + +const WrapperRow = styled(Row)` + padding: 20px; + align-items: center; + justify-content: space-between; + cursor: pointer; +` + +const IconContainer = styled.div` + flex: 1; + padding: 10px 30px 10px 10px; + display: flex; + align-items: center; +` + +const TitleContainer = styled(Column)` + justify-content: flex-start; + flex: 8; +` From 290569e73242361f85ba5073e1855ade1019318f Mon Sep 17 00:00:00 2001 From: lightlii <32508751+lightlii@users.noreply.github.com> Date: Wed, 26 Jul 2023 16:11:06 +0200 Subject: [PATCH 21/51] remove redundant translation --- messages/renderer/en.json | 4 ---- .../components/BackgroundMaps/SidePanel.js | 18 ++++++++---------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/messages/renderer/en.json b/messages/renderer/en.json index 08eae78d..92475225 100644 --- a/messages/renderer/en.json +++ b/messages/renderer/en.json @@ -43,10 +43,6 @@ "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" diff --git a/src/renderer/components/BackgroundMaps/SidePanel.js b/src/renderer/components/BackgroundMaps/SidePanel.js index 56eac5f2..fb7ca392 100644 --- a/src/renderer/components/BackgroundMaps/SidePanel.js +++ b/src/renderer/components/BackgroundMaps/SidePanel.js @@ -11,10 +11,8 @@ import { MapCard } from './MapCard' const m = defineMessages({ // Button to add map background addMap: 'Add Map Background', - // Button to create an offline area for a map backgroun - createOfflineMap: 'Create Offline Map', // button to go back to settings - backToSettings: 'Back to Settings', + backToSettings: 'Back to Settings' }) /** * @typedef SidePanelProps @@ -75,19 +73,19 @@ const useStyles = makeStyles({ display: 'flex', flexDirection: 'column', alignItems: 'center', - minWidth: '35%', + minWidth: '35%' }, buttonContainer: { display: 'flex', justifyContent: 'space-between', - padding: 20, + padding: 20 }, button: { textTransform: 'none', - fontSize: 12, + fontSize: 12 }, firstButton: { - marginRight: 10, + marginRight: 10 }, backHeader: { justifyContent: 'flex-start', @@ -99,7 +97,7 @@ const useStyles = makeStyles({ display: 'flex', textTransform: 'none', '& :first-child': { - marginRight: 20, - }, - }, + marginRight: 20 + } + } }) From f46cd698a658fe37a61e7c67dee6a531fbacba24 Mon Sep 17 00:00:00 2001 From: lightlii <32508751+lightlii@users.noreply.github.com> Date: Wed, 26 Jul 2023 16:40:48 +0200 Subject: [PATCH 22/51] chore: add mapstyle deletion --- .../BackgroundMaps/BackgroundMapInfo.js | 58 ++++++++++++------- 1 file changed, 36 insertions(+), 22 deletions(-) diff --git a/src/renderer/components/BackgroundMaps/BackgroundMapInfo.js b/src/renderer/components/BackgroundMaps/BackgroundMapInfo.js index 03cc6efc..69206c43 100644 --- a/src/renderer/components/BackgroundMaps/BackgroundMapInfo.js +++ b/src/renderer/components/BackgroundMaps/BackgroundMapInfo.js @@ -8,6 +8,7 @@ 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 @@ -23,7 +24,7 @@ const m = defineMessages({ // Zoom Level Title zoomLevel: 'Zoom Level: {zoom}', // abbreviation for megabyte - mb: 'MB', + mb: 'MB' }) /** @@ -47,23 +48,34 @@ export const BackgroundMapInfo = ({ id, unsetMapValue, url, size }) => { flex: 1, width: '100%', height: '100%', - padding: !data ? 40 : 0, + padding: !data ? 40 : 0 }} > {!data ? ( ) : ( - - + <> + {/* Text */}
{data.name} - {data.zoom && {t(m.zoomLevel, { zoom: data.zoom })}} - {`${Math.round(convertKbToMb(size))} ${t(m.mb)}`} + {data.zoom && ( + + {t(m.zoomLevel, { zoom: data.zoom })} + + )} + {`${Math.round( + convertKbToMb(size) + )} ${t(m.mb)}`}
-
+ )} @@ -84,22 +96,20 @@ const MapInfo = ({ name, id, unsetMapValue, url }) => { const { formatMessage: t } = useIntl() - /** - * - * @param {string} mapId - */ + const mutation = useMapServerMutation('delete', `/styles/${id}`) - // To Do, useMapServerMutation.mutate() - function deleteMap (mapId) {} + async function deleteMap () { + await mutation.mutateAsync(null) // tc complains if no arg is passed... + } return ( - + <> {/* Banner */} {name}
-
- setOpen(false)} /> -
+ setOpen(false)} + refetch={refetch} + /> + ) } diff --git a/src/renderer/components/SettingsView/BackgroundMaps.js b/src/renderer/components/SettingsView/BackgroundMaps.js index 338e2bc0..a6167234 100644 --- a/src/renderer/components/SettingsView/BackgroundMaps.js +++ b/src/renderer/components/SettingsView/BackgroundMaps.js @@ -9,7 +9,7 @@ import { useMapServerQuery } from '../../hooks/useMapServerQuery' const m = defineMessages({ // Title for description of offline maps - mapBackgroundTitle: 'Managing Map Backgrounds and Offline Areas', + mapBackgroundTitle: 'Managing Map Backgrounds and Offline Areas' }) /** @typedef {import('../../hooks/useMapServerQuery').MapServerStyleInfo} MapServerStyleInfo */ @@ -34,22 +34,31 @@ export const BackgroundMaps = ({ returnToSettings }) => { setMapValue(false) } - const offlineMap = React.useMemo(() => data && data.find(m => m.id === mapValue), [data, mapValue]) + const offlineMap = React.useMemo( + () => data && data.find(m => m.id === mapValue), + [data, mapValue] + ) return ( - - + <> + {!mapValue || !data ? (
{t(m.mapBackgroundTitle)} - Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut - labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris - nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit - esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt - in culpa qui officia deserunt mollit anim id est laborum. + Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do + eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim + ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut + aliquip ex ea commodo consequat. Duis aute irure dolor in + reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla + pariatur. Excepteur sint occaecat cupidatat non proident, sunt in + culpa qui officia deserunt mollit anim id est laborum.
@@ -62,7 +71,7 @@ export const BackgroundMaps = ({ returnToSettings }) => { url={offlineMap.url} /> ) : null} -
+ ) } diff --git a/src/renderer/components/dialogs/ImportMapStyle.js b/src/renderer/components/dialogs/ImportMapStyle.js index 0d182dd3..a71fe373 100644 --- a/src/renderer/components/dialogs/ImportMapStyle.js +++ b/src/renderer/components/dialogs/ImportMapStyle.js @@ -37,10 +37,11 @@ const m = defineMessages({ * @typedef ImportMapStyleDialogProps * @prop {boolean} open * @prop {()=>void} close + * @prop {()=>void} refetch */ /** @param {ImportMapStyleDialogProps} importMapStyleDialogProps */ -export const ImportMapStyleDialog = ({ open, close }) => { +export const ImportMapStyleDialog = ({ open, close, refetch }) => { const { formatMessage: t } = useIntl() const mutation = useMapServerMutation('post', '/tilesets/import') @@ -57,6 +58,7 @@ export const ImportMapStyleDialog = ({ open, close }) => { await mutation.mutateAsync({ filePath }) close() + refetch() } catch (err) { close() onError(err) From ffb723ae54ef46b5a9f0b7588416e10332f4f15c Mon Sep 17 00:00:00 2001 From: lightlii <32508751+lightlii@users.noreply.github.com> Date: Thu, 27 Jul 2023 14:23:28 +0200 Subject: [PATCH 26/51] chore: add error handling when importing map style --- src/main/ipc.js | 4 ++++ src/renderer/components/dialogs/ImportMapStyle.js | 10 +++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main/ipc.js b/src/main/ipc.js index 9a4cec99..d4bb341f 100644 --- a/src/main/ipc.js +++ b/src/main/ipc.js @@ -104,6 +104,10 @@ module.exports = function (ipcSend) { 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' diff --git a/src/renderer/components/dialogs/ImportMapStyle.js b/src/renderer/components/dialogs/ImportMapStyle.js index a71fe373..d69e1d60 100644 --- a/src/renderer/components/dialogs/ImportMapStyle.js +++ b/src/renderer/components/dialogs/ImportMapStyle.js @@ -28,7 +28,7 @@ const m = defineMessages({ importErrorTitle: 'Background Maps Import Error', // Description of map import error importErrorDescription: - 'There was an error importing the background maps. Please try again.', + 'There was an error importing the background maps. Please try again. Error message:', // Label of 'Import File' button importFile: 'Import File' }) @@ -64,9 +64,13 @@ export const ImportMapStyleDialog = ({ open, close, refetch }) => { onError(err) } - function onError (err) { + async function onError (err) { console.log({ err }) - // remote.dialog.showErrorBox(t(m.importErrorTitle), t(m.importErrorDescription) + ': ' + err) + ipcRenderer.send( + 'show-error-dialog', + t(m.importErrorTitle), + `${t(m.importErrorDescription)} ${err}` + ) } } From 2ea6977acc27bce05eeab8998288ab1088f9f88d Mon Sep 17 00:00:00 2001 From: lightlii <32508751+lightlii@users.noreply.github.com> Date: Thu, 27 Jul 2023 14:23:49 +0200 Subject: [PATCH 27/51] chore: auto-gen translation file --- messages/renderer/en.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/messages/renderer/en.json b/messages/renderer/en.json index 4ff89649..a5ae6624 100644 --- a/messages/renderer/en.json +++ b/messages/renderer/en.json @@ -712,7 +712,7 @@ }, "renderer.components.dialogs.ImportMapStyle.importErrorDescription": { "description": "Description of map import error", - "message": "There was an error importing the background maps. Please try again." + "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,", From 5c1ac88ab5f6bc3a08a482f5ddf5358fd280e899 Mon Sep 17 00:00:00 2001 From: lightlii <32508751+lightlii@users.noreply.github.com> Date: Thu, 27 Jul 2023 14:42:01 +0200 Subject: [PATCH 28/51] fix: remove merge-duplication --- .../components/SettingsView/SettingsMenu.js | 56 +++++++++---------- 1 file changed, 25 insertions(+), 31 deletions(-) diff --git a/src/renderer/components/SettingsView/SettingsMenu.js b/src/renderer/components/SettingsView/SettingsMenu.js index 09ff57ba..5a85b0be 100644 --- a/src/renderer/components/SettingsView/SettingsMenu.js +++ b/src/renderer/components/SettingsView/SettingsMenu.js @@ -29,7 +29,7 @@ export const SettingsMenu = ({ tabs, currentTab, onTabChange }) => { height: '100vh', borderRadius: 0, zIndex: 1, - position: 'relative', + position: 'relative' }} > { value={currentTab} onChange={(e, newValue) => onTabChange(newValue)} > - { - tabs.map(tab => ( - - )) - } - - + {tabs.map(tab => ( + + ))} + + ) } @@ -62,21 +60,17 @@ export const SettingsMenu = ({ tabs, currentTab, onTabChange }) => { * @prop {(e: React.Dispatch) => number} onTabChange */ /** @param {RenderTabProps} props */ -export const RenderTab = React.forwardRef(({ tab: { icon, label, subtitle, type }, ...rest }, ref) => ( - -)) - -const StyledTabs = styled(Tabs)` - height: 100vh; - padding-top: 1em; - & .MuiTabs-indicator { - display: none; - } - - & .MuiTab-root { - max-width: 100%; - } -` +export const RenderTab = React.forwardRef( + ({ tab: { icon, label, subtitle, type }, ...rest }, ref) => ( + + ) +) const StyledTabs = styled(Tabs)` height: 100vh; From 9fd494ec90932edd5d9d4d5c85bdf0caa765da1f Mon Sep 17 00:00:00 2001 From: lightlii <32508751+lightlii@users.noreply.github.com> Date: Thu, 27 Jul 2023 14:42:18 +0200 Subject: [PATCH 29/51] chore: auto-gen translation file --- messages/renderer/en.json | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/messages/renderer/en.json b/messages/renderer/en.json index a5ae6624..b1d12195 100644 --- a/messages/renderer/en.json +++ b/messages/renderer/en.json @@ -525,6 +525,12 @@ "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" }, From 4fd671f9e4eeaca21e1c7c4852e3dd0e4bfe5dbe Mon Sep 17 00:00:00 2001 From: lightlii <32508751+lightlii@users.noreply.github.com> Date: Thu, 10 Aug 2023 15:07:09 +0200 Subject: [PATCH 30/51] feat: add button to select current map --- .../BackgroundMaps/BackgroundMapInfo.js | 50 ++++++++++++-- .../components/BackgroundMaps/MapCard.js | 65 +++++++++++++++---- .../SettingsView/ExperimentsMenu.js | 24 ++++--- src/renderer/components/SettingsView/index.js | 42 ++++++------ 4 files changed, 131 insertions(+), 50 deletions(-) diff --git a/src/renderer/components/BackgroundMaps/BackgroundMapInfo.js b/src/renderer/components/BackgroundMaps/BackgroundMapInfo.js index 69206c43..62ada0d5 100644 --- a/src/renderer/components/BackgroundMaps/BackgroundMapInfo.js +++ b/src/renderer/components/BackgroundMaps/BackgroundMapInfo.js @@ -3,12 +3,14 @@ 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 Loading from '../Loading' import { useMapServerQuery } from '../../hooks/useMapServerQuery' import { MapboxPrevOnly } from './MapCard' import { convertKbToMb } from '../SettingsView/BackgroundMaps' import { useMapServerMutation } from '../../hooks/useMapServerMutation' +import { useBackgroundMapStore } from '../../hooks/store' const m = defineMessages({ // Title for Offline Areas @@ -24,7 +26,11 @@ const m = defineMessages({ // Zoom Level Title zoomLevel: 'Zoom Level: {zoom}', // abbreviation for megabyte - mb: 'MB' + mb: 'MB', + // Button text for 'Use Map' button + useMap: 'Use Map', + // Button text for 'Use Map' button when map is selected + currentMap: 'Current Map' }) /** @@ -39,7 +45,15 @@ const m = defineMessages({ export const BackgroundMapInfo = ({ id, unsetMapValue, url, size }) => { const { formatMessage: t } = useIntl() + const [mapStyle, setMapStyle] = useBackgroundMapStore(store => [ + store.mapStyle, + store.setMapStyle + ]) + const { data } = useMapServerQuery(`/styles/${id}`) + const classes = useStyles() + + const isCurrentMap = mapStyle === id return ( @@ -62,7 +76,7 @@ export const BackgroundMapInfo = ({ id, unsetMapValue, url, size }) => { url={url} /> {/* Text */} -
+
{data.name} @@ -74,6 +88,21 @@ export const BackgroundMapInfo = ({ id, unsetMapValue, url, size }) => { {`${Math.round( convertKbToMb(size) )} ${t(m.mb)}`} +
)} @@ -110,7 +139,7 @@ const MapInfo = ({ name, id, unsetMapValue, url }) => {
) @@ -67,19 +98,19 @@ const useStyles = makeStyles({ textTransform: 'none', padding: 0, '& .MuiButton-root': { - padding: 0, + padding: 0 }, '& .MuiButton-outlined': { - padding: 0, + padding: 0 }, '& .MuiButton-label': { - height: '100%', - }, + height: '100%' + } }, inner: { display: 'flex', flex: 1, - height: '100%', + height: '100%' }, text: { alignItems: 'flex-start', @@ -88,6 +119,14 @@ const useStyles = makeStyles({ justifyContent: 'center', flex: 1, height: '100%', - marginLeft: 10, + marginLeft: 10 }, + detail: { + alignItems: 'flex-end', + display: 'flex', + flexDirection: 'column', + height: '100%', + justifyContent: 'flex-end', + padding: 8 + } }) diff --git a/src/renderer/components/SettingsView/ExperimentsMenu.js b/src/renderer/components/SettingsView/ExperimentsMenu.js index d2ec1c86..5d0ae713 100644 --- a/src/renderer/components/SettingsView/ExperimentsMenu.js +++ b/src/renderer/components/SettingsView/ExperimentsMenu.js @@ -2,23 +2,21 @@ import React from 'react' import { defineMessages } from 'react-intl' import { Map as MapIcon } from '@material-ui/icons' import { SettingsList } from './SettingsList' +import { useExperimentsFlagsStore } from '../../hooks/store' const m = defineMessages({ - backgroundMaps: 'Background Maps', + backgroundMaps: 'Background Maps' }) -/** - * @typedef ExperiementsMenuProps - * @prop {boolean} backgroundMaps - * @prop {(e: React.Dispatch) => number} setBackgroundMaps - */ +export const ExperiementsMenu = () => { + const [backgroundMaps, setBackgroundMaps] = useExperimentsFlagsStore( + store => [store.backgroundMaps, store.setBackgroundMapsFlag] + ) + + console.log({ backgroundMaps, setBackgroundMaps }) -/** @param {ExperiementsMenuProps} props */ -export const ExperiementsMenu = ({ backgroundMaps, setBackgroundMaps }) => { const toggleBackgroundMaps = () => { - setBackgroundMaps(prevState => { - return !prevState - }) + setBackgroundMaps(!backgroundMaps) } /** @type {import('./SettingsList').option[]} */ @@ -29,8 +27,8 @@ export const ExperiementsMenu = ({ backgroundMaps, setBackgroundMaps }) => { label: m.backgroundMaps, checked: backgroundMaps, onClick: toggleBackgroundMaps, - type: 'toggle', - }, + type: 'toggle' + } ] return diff --git a/src/renderer/components/SettingsView/index.js b/src/renderer/components/SettingsView/index.js index 9a0f01df..060ce159 100644 --- a/src/renderer/components/SettingsView/index.js +++ b/src/renderer/components/SettingsView/index.js @@ -7,7 +7,7 @@ import { defineMessages } from 'react-intl' import { AboutMapeoMenu } from './AboutMapeo' import styled from 'styled-components' import { ExperiementsMenu } from './ExperimentsMenu' -import createPersistedState from '../../hooks/createPersistedState' +import { useExperimentsFlagsStore } from '../../hooks/store' import { BackgroundMaps } from './BackgroundMaps' const m = defineMessages({ @@ -15,35 +15,33 @@ const m = defineMessages({ aboutMapeoSubtitle: 'Version and build number', experiments: 'Experiments', experimentsSubtitle: 'Turn on experimental new features', - backgroundMaps: 'Background maps', + backgroundMaps: 'Background maps' }) -const useExperimentsFlagsState = createPersistedState('experimentsFlags') - export const SettingsView = () => { - const [backgroundMaps, setBackgroundMaps] = useExperimentsFlagsState(false) - const tabs = /** @type {import('./SettingsMenu').tabs} */[ + const backgroundMaps = useExperimentsFlagsStore(store => store.backgroundMaps) + const tabs = /** @type {import('./SettingsMenu').tabs} */ [ { tabId: 'AboutMapeo', icon: InfoIcon, label: m.aboutMapeo, - subtitle: m.aboutMapeoSubtitle, + subtitle: m.aboutMapeoSubtitle }, { tabId: 'Experiments', icon: FlagIcon, label: m.experiments, - subtitle: m.experimentsSubtitle, + subtitle: m.experimentsSubtitle }, ...(backgroundMaps ? [ - { - tabId: 'BackgroundMaps', - icon: MapIcon, - label: m.backgroundMaps, - }, - ] - : []), + { + tabId: 'BackgroundMaps', + icon: MapIcon, + label: m.backgroundMaps + } + ] + : []) ] const initialMenuState = /** {null | number} */ null const [menuItem, setMenuItem] = useState(initialMenuState) @@ -51,14 +49,18 @@ export const SettingsView = () => { return ( {menuItem === 'BackgroundMaps' ? ( - setMenuItem(initialMenuState)} /> + setMenuItem(initialMenuState)} + /> ) : ( <> - + {menuItem === 'AboutMapeo' && } - {menuItem === 'Experiments' && ( - - )} + {menuItem === 'Experiments' && } )} From 35472d3133df3322294b3a0da64f5ccfa78aed9c Mon Sep 17 00:00:00 2001 From: lightlii <32508751+lightlii@users.noreply.github.com> Date: Thu, 10 Aug 2023 17:37:47 +0200 Subject: [PATCH 31/51] wip: add backgroundMap selector component to Observations view --- messages/renderer/en.json | 24 ++++++ .../MapView/BackgroundMapSelector.js | 66 ++++++++++++++ .../components/MapFilter/MapView/MapView.js | 85 ++++++++++++++----- 3 files changed, 155 insertions(+), 20 deletions(-) create mode 100644 src/renderer/components/MapFilter/MapView/BackgroundMapSelector.js diff --git a/messages/renderer/en.json b/messages/renderer/en.json index b1d12195..3fbfe8a4 100644 --- a/messages/renderer/en.json +++ b/messages/renderer/en.json @@ -3,6 +3,10 @@ "description": "Button to create an offline area", "message": "Create Offline Area" }, + "renderer.components.BackgroundMaps.BackgroundMapInfo.currentMap": { + "description": "Button text for 'Use Map' button when map is selected", + "message": "Current Map" + }, "renderer.components.BackgroundMaps.BackgroundMapInfo.deleteErrorDescription": { "description": "Description for error message when deleting style,", "message": "There was an error deleting the style" @@ -23,6 +27,10 @@ "description": "Title for Offline Areas", "message": "Offline Areas" }, + "renderer.components.BackgroundMaps.BackgroundMapInfo.useMap": { + "description": "Button text for 'Use Map' button", + "message": "Use Map" + }, "renderer.components.BackgroundMaps.BackgroundMapInfo.zoomLevel": { "description": "Zoom Level Title", "message": "Zoom Level: {zoom}" @@ -31,6 +39,10 @@ "description": "indicates how many offline areas", "message": "offline areas" }, + "renderer.components.BackgroundMaps.MapCard.currentMap": { + "description": "Label to indicate when map is selected", + "message": "Current Map" + }, "renderer.components.BackgroundMaps.MapCard.mb": { "description": "Abbreviation for megabytes", "message": "MB" @@ -383,6 +395,18 @@ "renderer.components.MapFilter.MapFilter.errorTitle": { "message": "Oh dear! An error has occurred" }, + "renderer.components.MapFilter.MapView.BackgroundMapSelector.close": { + "description": "Label for dismiss button", + "message": "Close" + }, + "renderer.components.MapFilter.MapView.BackgroundMapSelector.manageMapsLink": { + "description": "Label for link to manage maps", + "message": "Manage Maps" + }, + "renderer.components.MapFilter.MapView.BackgroundMapSelector.title": { + "description": "Title for background maps overlay", + "message": "Background Maps" + }, "renderer.components.MapFilter.ObservationDialog.ObservationDialog.additionalHeader": { "description": "Header for section with additional fields that are not defined in the preset", "message": "Additional data" diff --git a/src/renderer/components/MapFilter/MapView/BackgroundMapSelector.js b/src/renderer/components/MapFilter/MapView/BackgroundMapSelector.js new file mode 100644 index 00000000..f5aeb394 --- /dev/null +++ b/src/renderer/components/MapFilter/MapView/BackgroundMapSelector.js @@ -0,0 +1,66 @@ +import React from 'react' +import { + Box, + Button, + Paper, + Slide, + Typography, + makeStyles +} from '@material-ui/core' +import { defineMessages, useIntl } from 'react-intl' +import { Close } from '@material-ui/icons' + +const m = defineMessages({ + // Title for background maps overlay + title: 'Background Maps', + // Label for dismiss button + close: 'Close', + // Label for link to manage maps + manageMapsLink: 'Manage Maps' +}) + +export const BackgroundMapSelector = ({ active, dismiss }) => { + const classes = useStyles() + const { formatMessage: t } = useIntl() + + return ( + + + + + {t(m.title)} + + + + + + ) +} + +const useStyles = makeStyles(theme => ({ + container: { + borderRadius: '10px 10px 0px 0px', + width: '100%', + height: '50vh', + position: 'absolute', + bottom: 0, + left: 0, + right: 0, + zIndex: 2 + }, + header: { + padding: '16px 22px', + display: 'flex', + justifyContent: 'space-between', + borderBottom: '1px solid rgba(0, 0, 0, 0.12)', + alignItems: 'center' + }, + title: { + fontSize: 22, + fontWeight: 500, + marginRight: 5 + } +})) diff --git a/src/renderer/components/MapFilter/MapView/MapView.js b/src/renderer/components/MapFilter/MapView/MapView.js index c18d7d6c..6a3e1acf 100644 --- a/src/renderer/components/MapFilter/MapView/MapView.js +++ b/src/renderer/components/MapFilter/MapView/MapView.js @@ -1,7 +1,10 @@ -import React from 'react' +import React, { useState } from 'react' import MapViewContent from './MapViewContent' import ViewWrapper from '../ViewWrapper' +import { Avatar, makeStyles } from '@material-ui/core' +import { LayersOutlined } from '@material-ui/icons' +import { BackgroundMapSelector } from './BackgroundMapSelector' const MapView = ( { @@ -15,27 +18,69 @@ const MapView = ( }, ref ) => { + const [backgroundMapSelectorOpen, setBackgroundMapSelectorOpen] = useState( + false + ) + return ( + <> + + setBackgroundMapSelectorOpen(selectorWasOpen => !selectorWasOpen) + } + /> + + {({ + onClickObservation, + filteredObservations, + getPreset, + getMedia + }) => ( + + )} + + setBackgroundMapSelectorOpen(false)} + /> + + ) +} + +const useStyles = makeStyles(theme => ({ + avatar: { + backgroundColor: theme.palette.background.paper, + cursor: 'pointer' + }, + icon: { + color: theme.palette.common.black + } +})) + +const MapLayerButton = ({ onClick }) => { + const classes = useStyles() return ( - - {({ onClickObservation, filteredObservations, getPreset, getMedia }) => ( - - )} - + + ) } From 8494d0ef9818b479fd2963eded35451f9300c30b Mon Sep 17 00:00:00 2001 From: lightlii <32508751+lightlii@users.noreply.github.com> Date: Mon, 14 Aug 2023 18:28:50 +0200 Subject: [PATCH 32/51] chore: add background maps selector component. Currently with hardcoded data... --- .../MapView/BackgroundMapSelector.js | 57 +++++++++++++- .../MapFilter/MapView/MapPreviewCard.js | 75 +++++++++++++++++++ 2 files changed, 130 insertions(+), 2 deletions(-) create mode 100644 src/renderer/components/MapFilter/MapView/MapPreviewCard.js diff --git a/src/renderer/components/MapFilter/MapView/BackgroundMapSelector.js b/src/renderer/components/MapFilter/MapView/BackgroundMapSelector.js index f5aeb394..d692707d 100644 --- a/src/renderer/components/MapFilter/MapView/BackgroundMapSelector.js +++ b/src/renderer/components/MapFilter/MapView/BackgroundMapSelector.js @@ -1,4 +1,4 @@ -import React from 'react' +import * as React from 'react' import { Box, Button, @@ -9,6 +9,23 @@ import { } from '@material-ui/core' import { defineMessages, useIntl } from 'react-intl' import { Close } from '@material-ui/icons' +import { MapPreviewCard } from './MapPreviewCard' +import { useBackgroundMapStore } from '../../../hooks/store' + +const STYLES = [ + { + id: '7p2524cknfdg2pqntxv2qs592nd6x6xt', + name: 'trails-with-a-name', + bytesStored: 969515, + url: 'http://127.0.0.1:5300/styles/7p2524cknfdg2pqntxv2qs592nd6x6xt' + }, + { + id: 'xhe52hsmq65w15emmr2zehw3d6jjtha0', + name: 'other-map-with-another-name', + bytesStored: 969515, + url: 'mapbox://styles/mapbox/streets-v12' + } +] const m = defineMessages({ // Title for background maps overlay @@ -22,10 +39,15 @@ const m = defineMessages({ export const BackgroundMapSelector = ({ active, dismiss }) => { const classes = useStyles() const { formatMessage: t } = useIntl() + const [mapStyle, setMapStyle] = useBackgroundMapStore(store => [ + store.mapStyle, + store.setMapStyle + ]) return ( + {/* HEADER */} {t(m.title)} @@ -35,6 +57,30 @@ export const BackgroundMapSelector = ({ active, dismiss }) => { + {/* MAP STYLES ROW */} + + {STYLES.filter(({ isImporting }) => !isImporting).map( + ({ id, url, name }) => { + const isSelected = mapStyle === id + return ( + <> +
+ { + if (isSelected) return + dismiss() + setMapStyle(id) + }} + selected={isSelected} + styleUrl={url} + title={name} + /> +
+ + ) + } + )} +
) @@ -44,7 +90,7 @@ const useStyles = makeStyles(theme => ({ container: { borderRadius: '10px 10px 0px 0px', width: '100%', - height: '50vh', + minHeight: '40vh', position: 'absolute', bottom: 0, left: 0, @@ -62,5 +108,12 @@ const useStyles = makeStyles(theme => ({ fontSize: 22, fontWeight: 500, marginRight: 5 + }, + styleRow: { + display: 'flex', + padding: 22 + }, + mapCardWrapper: { + marginRight: 32 } })) diff --git a/src/renderer/components/MapFilter/MapView/MapPreviewCard.js b/src/renderer/components/MapFilter/MapView/MapPreviewCard.js new file mode 100644 index 00000000..96f90000 --- /dev/null +++ b/src/renderer/components/MapFilter/MapView/MapPreviewCard.js @@ -0,0 +1,75 @@ +import { Box, Typography, makeStyles, useTheme } from '@material-ui/core' +import React from 'react' +import ReactMapboxGl from 'react-mapbox-gl' + +import { MAPBOX_ACCESS_TOKEN } from '../../../../../config' + +export const MapboxPreview = ReactMapboxGl({ + accessToken: MAPBOX_ACCESS_TOKEN, + dragRotate: false, + pitchWithRotate: false, + attributionControl: false, + injectCSS: false +}) + +export const MapPreviewCard = ({ onClick, selected, styleUrl, title }) => { + const classes = useStyles() + const theme = useTheme() + + return ( + <> + + + ) +} + +const useStyles = makeStyles(theme => ({ + container: { + alignItems: 'center', + display: 'flex', + flexDirection: 'column', + cursor: 'pointer', + backgroundColor: 'transparent', + border: 'none' + }, + inner: { + borderRadius: 12, + borderStyle: 'solid', + marginBottom: 10, + borderWidth: 4, + overflow: 'hidden' + }, + thumbnail: { + height: 80, + width: 80, + cursor: 'pointer', + '& .mapboxgl-control-container': { + display: 'none' + } + }, + title: { + textAlign: 'center', + fontSize: 16, + maxWidth: 80 + } +})) From be8a4d0ae8647d27c3ab94ff765374cf3af1e873 Mon Sep 17 00:00:00 2001 From: lightlii <32508751+lightlii@users.noreply.github.com> Date: Mon, 14 Aug 2023 18:40:53 +0200 Subject: [PATCH 33/51] chore: remove hardcoded value (still WIP) --- .../MapView/BackgroundMapSelector.js | 27 ++++++------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/src/renderer/components/MapFilter/MapView/BackgroundMapSelector.js b/src/renderer/components/MapFilter/MapView/BackgroundMapSelector.js index d692707d..8b86e24e 100644 --- a/src/renderer/components/MapFilter/MapView/BackgroundMapSelector.js +++ b/src/renderer/components/MapFilter/MapView/BackgroundMapSelector.js @@ -11,21 +11,7 @@ import { defineMessages, useIntl } from 'react-intl' import { Close } from '@material-ui/icons' import { MapPreviewCard } from './MapPreviewCard' import { useBackgroundMapStore } from '../../../hooks/store' - -const STYLES = [ - { - id: '7p2524cknfdg2pqntxv2qs592nd6x6xt', - name: 'trails-with-a-name', - bytesStored: 969515, - url: 'http://127.0.0.1:5300/styles/7p2524cknfdg2pqntxv2qs592nd6x6xt' - }, - { - id: 'xhe52hsmq65w15emmr2zehw3d6jjtha0', - name: 'other-map-with-another-name', - bytesStored: 969515, - url: 'mapbox://styles/mapbox/streets-v12' - } -] +import { useMapServerQuery } from '../../../hooks/useMapServerQuery' const m = defineMessages({ // Title for background maps overlay @@ -44,6 +30,9 @@ export const BackgroundMapSelector = ({ active, dismiss }) => { store.setMapStyle ]) + // will use new hook once merged + const { data: mapStyles, isLoading } = useMapServerQuery('/styles', false) + return ( @@ -59,8 +48,9 @@ export const BackgroundMapSelector = ({ active, dismiss }) => { {/* MAP STYLES ROW */} - {STYLES.filter(({ isImporting }) => !isImporting).map( - ({ id, url, name }) => { + {mapStyles + .filter(({ isImporting }) => !isImporting) + .map(({ id, url, name }) => { const isSelected = mapStyle === id return ( <> @@ -78,8 +68,7 @@ export const BackgroundMapSelector = ({ active, dismiss }) => {
) - } - )} + })} From b434580eeaa134a544290c9b89fee8d96095d045 Mon Sep 17 00:00:00 2001 From: lightlii <32508751+lightlii@users.noreply.github.com> Date: Thu, 17 Aug 2023 19:09:37 +0200 Subject: [PATCH 34/51] fix: restore setting persisted storage async --- src/renderer/hooks/store.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/renderer/hooks/store.js b/src/renderer/hooks/store.js index 0a6d47bd..16bf68a1 100644 --- a/src/renderer/hooks/store.js +++ b/src/renderer/hooks/store.js @@ -9,10 +9,11 @@ import store from '../../persist-store' const storage = { /** * @param {string} key - A string key to reference the stored item by. - * @returns {string | null} + * @returns {Promise} */ - getItem: key => { - return /** @type {string | null} */ (store.get(key)) || null + getItem: async key => { + const item = await store.get(key) + return typeof item === 'string' ? item : null }, /** * @param {string} key - A string key to reference the stored item by. @@ -20,7 +21,7 @@ const storage = { * @returns {void} */ setItem: (key, state) => { - store.set(key, JSON.parse(state)) + store.set(key, state) }, /** * @param {string} key - A string key to reference the stored item to be removed. From 06c68b8bf20fb55a504f528734bff9f2432f1ef0 Mon Sep 17 00:00:00 2001 From: lightlii <32508751+lightlii@users.noreply.github.com> Date: Thu, 17 Aug 2023 19:35:39 +0200 Subject: [PATCH 35/51] fix: make saved types in config consistent --- src/renderer/hooks/store.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/renderer/hooks/store.js b/src/renderer/hooks/store.js index 16bf68a1..c98057d6 100644 --- a/src/renderer/hooks/store.js +++ b/src/renderer/hooks/store.js @@ -13,7 +13,7 @@ const storage = { */ getItem: async key => { const item = await store.get(key) - return typeof item === 'string' ? item : null + return item ? JSON.stringify(item) : null }, /** * @param {string} key - A string key to reference the stored item by. @@ -21,7 +21,11 @@ const storage = { * @returns {void} */ setItem: (key, state) => { - store.set(key, state) + if (typeof state === 'string') { + store.set(key, JSON.parse(state)) + } else { + store.set(key, state) + } }, /** * @param {string} key - A string key to reference the stored item to be removed. From c8c0848c2f61dd458c9615012b224ee4e8afb1a8 Mon Sep 17 00:00:00 2001 From: lightlii <32508751+lightlii@users.noreply.github.com> Date: Thu, 17 Aug 2023 19:57:27 +0200 Subject: [PATCH 36/51] fix: revert async await again (??) problem appears to be the format that's being saved (JSON or string) --- src/renderer/hooks/store.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/renderer/hooks/store.js b/src/renderer/hooks/store.js index c98057d6..0151c3bd 100644 --- a/src/renderer/hooks/store.js +++ b/src/renderer/hooks/store.js @@ -9,10 +9,10 @@ import store from '../../persist-store' const storage = { /** * @param {string} key - A string key to reference the stored item by. - * @returns {Promise} + * @returns {string | null} */ - getItem: async key => { - const item = await store.get(key) + getItem: key => { + const item = store.get(key) return item ? JSON.stringify(item) : null }, /** From 6aa6578c651537d7b36cd95e9f19c98937f10250 Mon Sep 17 00:00:00 2001 From: lightlii <32508751+lightlii@users.noreply.github.com> Date: Fri, 18 Aug 2023 13:07:51 +0200 Subject: [PATCH 37/51] fix: revert zustand serialisation stuf... persisted store working correctly now --- src/renderer/hooks/store.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/renderer/hooks/store.js b/src/renderer/hooks/store.js index 0151c3bd..85247095 100644 --- a/src/renderer/hooks/store.js +++ b/src/renderer/hooks/store.js @@ -12,8 +12,11 @@ const storage = { * @returns {string | null} */ getItem: key => { - const item = store.get(key) - return item ? JSON.stringify(item) : null + /** + * @type {string | null} + */ + + return store.get(key, null) }, /** * @param {string} key - A string key to reference the stored item by. @@ -21,11 +24,7 @@ const storage = { * @returns {void} */ setItem: (key, state) => { - if (typeof state === 'string') { - store.set(key, JSON.parse(state)) - } else { - store.set(key, state) - } + store.set(key, state) }, /** * @param {string} key - A string key to reference the stored item to be removed. From 879bfb3debd3a821078e5fa703862ef8d8c175bb Mon Sep 17 00:00:00 2001 From: lightlii <32508751+lightlii@users.noreply.github.com> Date: Fri, 18 Aug 2023 19:55:32 +0200 Subject: [PATCH 38/51] feat: implement map selection --- .../MapView/BackgroundMapSelector.js | 120 +++++++++++++----- .../components/MapFilter/MapView/MapView.js | 22 +++- .../SettingsView/ExperimentsMenu.js | 2 - src/renderer/hooks/useMapStylesQuery.js | 42 ++++-- 4 files changed, 138 insertions(+), 48 deletions(-) diff --git a/src/renderer/components/MapFilter/MapView/BackgroundMapSelector.js b/src/renderer/components/MapFilter/MapView/BackgroundMapSelector.js index 8b86e24e..158e67ea 100644 --- a/src/renderer/components/MapFilter/MapView/BackgroundMapSelector.js +++ b/src/renderer/components/MapFilter/MapView/BackgroundMapSelector.js @@ -2,6 +2,7 @@ import * as React from 'react' import { Box, Button, + Link, Paper, Slide, Typography, @@ -10,8 +11,16 @@ import { import { defineMessages, useIntl } from 'react-intl' import { Close } from '@material-ui/icons' import { MapPreviewCard } from './MapPreviewCard' -import { useBackgroundMapStore } from '../../../hooks/store' -import { useMapServerQuery } from '../../../hooks/useMapServerQuery' +import { + useBackgroundMapStore, + useExperimentsFlagsStore, + usePersistedUiStore +} from '../../../hooks/store' +import { + useDefaultMapStyle, + useMapStylesQuery +} from '../../../hooks/useMapStylesQuery' +import Loader from '../../Loader' const m = defineMessages({ // Title for background maps overlay @@ -30,51 +39,87 @@ export const BackgroundMapSelector = ({ active, dismiss }) => { store.setMapStyle ]) - // will use new hook once merged - const { data: mapStyles, isLoading } = useMapServerQuery('/styles', false) + const setTabIndex = usePersistedUiStore(store => store.setTabIndex) + + const navigateToBackgroundMaps = () => { + setTabIndex(3) // TODO: Set from an ID rather than hardcoded index + } + + const backgroundMapsEnabled = useExperimentsFlagsStore( + store => store.backgroundMaps + ) + + const defaultMapStyle = useDefaultMapStyle() + const { isLoading, data } = useMapStylesQuery() + + const mapStyles = + backgroundMapsEnabled && data ? [defaultMapStyle, ...data] : data return ( {/* HEADER */} - - {t(m.title)} - + + + {t(m.title)} + + + {t(m.manageMapsLink)} + + {/* MAP STYLES ROW */} - - {mapStyles - .filter(({ isImporting }) => !isImporting) - .map(({ id, url, name }) => { - const isSelected = mapStyle === id - return ( - <> -
- { - if (isSelected) return - dismiss() - setMapStyle(id) - }} - selected={isSelected} - styleUrl={url} - title={name} - /> -
- - ) - })} -
+ {isLoading ? ( + + ) : ( + + {mapStyles + .filter(({ isImporting }) => !isImporting) + .map(({ id, url, name }) => { + const isSelected = mapStyle === id + return ( + <> +
+ { + if (isSelected) return + dismiss() + setMapStyle(id) + }} + selected={isSelected} + styleUrl={url} + title={name} + /> +
+ + ) + })} +
+ )}
) } +const Loading = () => { + const classes = useStyles() + + return ( + + + + ) +} + const useStyles = makeStyles(theme => ({ container: { borderRadius: '10px 10px 0px 0px', @@ -98,11 +143,26 @@ const useStyles = makeStyles(theme => ({ fontWeight: 500, marginRight: 5 }, + row: { + display: 'flex', + flexDirection: 'row', + alignItems: 'center' + }, styleRow: { display: 'flex', padding: 22 }, + link: { + cursor: 'pointer' + }, mapCardWrapper: { marginRight: 32 + }, + loaderContainer: { + width: '100%', + marginTop: '10%', + display: 'flex', + justifyContent: 'center', + alignItems: 'center' } })) diff --git a/src/renderer/components/MapFilter/MapView/MapView.js b/src/renderer/components/MapFilter/MapView/MapView.js index 6a3e1acf..507180db 100644 --- a/src/renderer/components/MapFilter/MapView/MapView.js +++ b/src/renderer/components/MapFilter/MapView/MapView.js @@ -5,6 +5,8 @@ import ViewWrapper from '../ViewWrapper' import { Avatar, makeStyles } from '@material-ui/core' import { LayersOutlined } from '@material-ui/icons' import { BackgroundMapSelector } from './BackgroundMapSelector' +import { useSelectedMapStyle } from '../../../hooks/useMapStylesQuery' +import { useExperimentsFlagsStore } from '../../../hooks/store' const MapView = ( { @@ -21,13 +23,20 @@ const MapView = ( const [backgroundMapSelectorOpen, setBackgroundMapSelectorOpen] = useState( false ) + const backgroundMapsFlag = useExperimentsFlagsStore( + store => store.backgroundMaps + ) + const selectedMapStyle = useSelectedMapStyle() + return ( <> - - setBackgroundMapSelectorOpen(selectorWasOpen => !selectorWasOpen) - } - /> + {backgroundMapsFlag ? ( + + setBackgroundMapSelectorOpen(selectorWasOpen => !selectorWasOpen) + } + /> + ) : null} )} setBackgroundMapSelectorOpen(false)} /> diff --git a/src/renderer/components/SettingsView/ExperimentsMenu.js b/src/renderer/components/SettingsView/ExperimentsMenu.js index 5d0ae713..6c2920e6 100644 --- a/src/renderer/components/SettingsView/ExperimentsMenu.js +++ b/src/renderer/components/SettingsView/ExperimentsMenu.js @@ -13,8 +13,6 @@ export const ExperiementsMenu = () => { store => [store.backgroundMaps, store.setBackgroundMapsFlag] ) - console.log({ backgroundMaps, setBackgroundMaps }) - const toggleBackgroundMaps = () => { setBackgroundMaps(!backgroundMaps) } diff --git a/src/renderer/hooks/useMapStylesQuery.js b/src/renderer/hooks/useMapStylesQuery.js index 70e851c8..9b63264b 100644 --- a/src/renderer/hooks/useMapStylesQuery.js +++ b/src/renderer/hooks/useMapStylesQuery.js @@ -1,5 +1,5 @@ // @ts-check -import { useExperimentsFlagsStore } from './store' +import { useBackgroundMapStore, useExperimentsFlagsStore } from './store' import { useMapServerQuery } from './useMapServerQuery' import { useQuery } from '@tanstack/react-query' import api from '../new-api' @@ -34,6 +34,7 @@ export const useMapStylesQuery = () => { export const useLegacyMapStyleQuery = enabled => { const { formatMessage: t } = useIntl() + const defaultMapStyle = useDefaultMapStyle() const queryResult = useQuery({ queryKey: ['getLegacyMapStyle'], @@ -51,15 +52,7 @@ export const useLegacyMapStyleQuery = enabled => { } ] } catch { - return [ - { - id: DEFAULT_MAP_ID, - url: ONLINE_STYLE_URL, - bytesStored: 0, - name: t(m.defaultBackgroundMapName), - isImporting: false - } - ] + return [defaultMapStyle] } }, enabled @@ -67,3 +60,32 @@ export const useLegacyMapStyleQuery = enabled => { return queryResult } + +export const useDefaultMapStyle = () => { + const { formatMessage: t } = useIntl() + + return { + id: DEFAULT_MAP_ID, + url: ONLINE_STYLE_URL, + bytesStored: 0, + name: t(m.defaultBackgroundMapName), + isImporting: false + } +} + +export const useSelectedMapStyle = () => { + const backgroundMapsFlag = useExperimentsFlagsStore( + store => store.backgroundMaps + ) + const backgroundMapStyleId = useBackgroundMapStore(store => store.mapStyle) + const defaultMapStyle = useDefaultMapStyle() + + const { data: mapStyles, isLoading } = useMapStylesQuery() + + if (isLoading || !mapStyles) return defaultMapStyle + + return backgroundMapsFlag + ? mapStyles?.find(style => style.id === backgroundMapStyleId) || + defaultMapStyle + : mapStyles && mapStyles[0] +} From 70e37262387ee5d95852faf9e78ccb5867cd94aa Mon Sep 17 00:00:00 2001 From: lightlii <32508751+lightlii@users.noreply.github.com> Date: Tue, 22 Aug 2023 10:08:42 +0200 Subject: [PATCH 39/51] fix: add key to Fragment in map --- .../components/MapFilter/MapView/BackgroundMapSelector.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/renderer/components/MapFilter/MapView/BackgroundMapSelector.js b/src/renderer/components/MapFilter/MapView/BackgroundMapSelector.js index 158e67ea..86b6c2f5 100644 --- a/src/renderer/components/MapFilter/MapView/BackgroundMapSelector.js +++ b/src/renderer/components/MapFilter/MapView/BackgroundMapSelector.js @@ -87,8 +87,8 @@ export const BackgroundMapSelector = ({ active, dismiss }) => { .map(({ id, url, name }) => { const isSelected = mapStyle === id return ( - <> -
+ +
{ if (isSelected) return @@ -100,7 +100,7 @@ export const BackgroundMapSelector = ({ active, dismiss }) => { title={name} />
- +
) })} From 610e745dbcdf95d085052de461d4c7080a11e98f Mon Sep 17 00:00:00 2001 From: lightlii <32508751+lightlii@users.noreply.github.com> Date: Tue, 22 Aug 2023 11:03:38 +0200 Subject: [PATCH 40/51] fix: remove unused inports --- .../MapFilter/MapView/MapPreviewCard.js | 2 +- .../components/SettingsView/SettingsItem.js | 24 ++++++++++++------- src/renderer/components/SettingsView/index.js | 7 ------ 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/renderer/components/MapFilter/MapView/MapPreviewCard.js b/src/renderer/components/MapFilter/MapView/MapPreviewCard.js index 96f90000..bdac17e3 100644 --- a/src/renderer/components/MapFilter/MapView/MapPreviewCard.js +++ b/src/renderer/components/MapFilter/MapView/MapPreviewCard.js @@ -1,4 +1,4 @@ -import { Box, Typography, makeStyles, useTheme } from '@material-ui/core' +import { Typography, makeStyles, useTheme } from '@material-ui/core' import React from 'react' import ReactMapboxGl from 'react-mapbox-gl' diff --git a/src/renderer/components/SettingsView/SettingsItem.js b/src/renderer/components/SettingsView/SettingsItem.js index de36d50a..05fef594 100644 --- a/src/renderer/components/SettingsView/SettingsItem.js +++ b/src/renderer/components/SettingsView/SettingsItem.js @@ -1,4 +1,4 @@ -import React, { useEffect } from 'react' +import React from 'react' import { Typography, useTheme } from '@material-ui/core' import ChevronRightIcon from '@material-ui/icons/ChevronRight' @@ -8,7 +8,7 @@ import styled from 'styled-components' const m = defineMessages({ on: 'On', - off: 'Off', + off: 'Off' }) export const SettingsItem = React.forwardRef( @@ -18,7 +18,9 @@ export const SettingsItem = React.forwardRef( return ( - {Icon ? : null} + + {Icon ? : null} + {typeof label === 'string' ? label : t(label)} @@ -38,16 +40,22 @@ export const SettingsItem = React.forwardRef( textTransform: 'none', textAlign: 'left', cursor: 'pointer', - color: theme.palette.grey['700'], + color: theme.palette.grey['700'] }} > - {type === 'toggle' ? : } + {type === 'toggle' ? ( + + ) : ( + + )} - {type === 'menuItem' && } + {type === 'menuItem' && ( + + )} ) - }, + } ) const Subtitle = ({ label }) => { diff --git a/src/renderer/components/SettingsView/index.js b/src/renderer/components/SettingsView/index.js index 060ce159..e257e889 100644 --- a/src/renderer/components/SettingsView/index.js +++ b/src/renderer/components/SettingsView/index.js @@ -72,10 +72,3 @@ const Container = styled.div` display: flex; height: 100%; ` - -const Boc = styled.div` - -background-color: red -height: 200px; -width:100px; -` From 99d74509d801989c664e4bc6ef4e66909f1ebc8c Mon Sep 17 00:00:00 2001 From: lightlii <32508751+lightlii@users.noreply.github.com> Date: Tue, 29 Aug 2023 14:00:54 +0200 Subject: [PATCH 41/51] fix: use fuill screen dialog for BackgroundMapSelector and fix overflow --- .../MapView/BackgroundMapSelector.js | 125 ++++++++++-------- 1 file changed, 68 insertions(+), 57 deletions(-) diff --git a/src/renderer/components/MapFilter/MapView/BackgroundMapSelector.js b/src/renderer/components/MapFilter/MapView/BackgroundMapSelector.js index 86b6c2f5..3cd73ede 100644 --- a/src/renderer/components/MapFilter/MapView/BackgroundMapSelector.js +++ b/src/renderer/components/MapFilter/MapView/BackgroundMapSelector.js @@ -2,14 +2,15 @@ import * as React from 'react' import { Box, Button, + Dialog, Link, - Paper, Slide, Typography, makeStyles } from '@material-ui/core' import { defineMessages, useIntl } from 'react-intl' import { Close } from '@material-ui/icons' + import { MapPreviewCard } from './MapPreviewCard' import { useBackgroundMapStore, @@ -22,6 +23,8 @@ import { } from '../../../hooks/useMapStylesQuery' import Loader from '../../Loader' +const MAPEO_BLUE = '#2469f6' + const m = defineMessages({ // Title for background maps overlay title: 'Background Maps', @@ -42,6 +45,7 @@ export const BackgroundMapSelector = ({ active, dismiss }) => { const setTabIndex = usePersistedUiStore(store => store.setTabIndex) const navigateToBackgroundMaps = () => { + dismiss() setTabIndex(3) // TODO: Set from an ID rather than hardcoded index } @@ -56,57 +60,57 @@ export const BackgroundMapSelector = ({ active, dismiss }) => { backgroundMapsEnabled && data ? [defaultMapStyle, ...data] : data return ( - - - {/* HEADER */} - - - - {t(m.title)} - - - {t(m.manageMapsLink)} - - - + + {/* HEADER */} + + + + {t(m.title)} + + + {t(m.manageMapsLink)} + + + + + {/* MAP STYLES ROW */} + {isLoading ? ( + + ) : ( + + {mapStyles + .filter(({ isImporting }) => !isImporting) + .map(({ id, url, name }) => { + const isSelected = mapStyle === id + return ( + { + if (isSelected) return + dismiss() + setMapStyle(id) + }} + selected={isSelected} + styleUrl={url} + title={name} + key={id} + /> + ) + })} - {/* MAP STYLES ROW */} - {isLoading ? ( - - ) : ( - - {mapStyles - .filter(({ isImporting }) => !isImporting) - .map(({ id, url, name }) => { - const isSelected = mapStyle === id - return ( - -
- { - if (isSelected) return - dismiss() - setMapStyle(id) - }} - selected={isSelected} - styleUrl={url} - title={name} - /> -
-
- ) - })} -
- )} -
-
+ )} + ) } @@ -120,6 +124,10 @@ const Loading = () => { ) } +const Transition = React.forwardRef((props, ref) => ( + +)) + const useStyles = makeStyles(theme => ({ container: { borderRadius: '10px 10px 0px 0px', @@ -141,7 +149,7 @@ const useStyles = makeStyles(theme => ({ title: { fontSize: 22, fontWeight: 500, - marginRight: 5 + marginRight: 10 }, row: { display: 'flex', @@ -150,13 +158,13 @@ const useStyles = makeStyles(theme => ({ }, styleRow: { display: 'flex', - padding: 22 + padding: 22, + flexWrap: 'wrap', + gap: '40px 20px ' }, link: { - cursor: 'pointer' - }, - mapCardWrapper: { - marginRight: 32 + cursor: 'pointer', + color: MAPEO_BLUE }, loaderContainer: { width: '100%', @@ -164,5 +172,8 @@ const useStyles = makeStyles(theme => ({ display: 'flex', justifyContent: 'center', alignItems: 'center' + }, + closeButton: { + color: MAPEO_BLUE } })) From 0cc01473f07cb9a08a48b17e0accdf0be4dbdb73 Mon Sep 17 00:00:00 2001 From: lightlii <32508751+lightlii@users.noreply.github.com> Date: Tue, 29 Aug 2023 14:35:32 +0200 Subject: [PATCH 42/51] fix: make style list in background maps screen scrollable --- .../components/BackgroundMaps/MapCard.js | 4 +- .../components/BackgroundMaps/SidePanel.js | 58 +++++++++++-------- .../components/SettingsView/BackgroundMaps.js | 8 +-- 3 files changed, 40 insertions(+), 30 deletions(-) diff --git a/src/renderer/components/BackgroundMaps/MapCard.js b/src/renderer/components/BackgroundMaps/MapCard.js index f456d2c2..1953c77e 100644 --- a/src/renderer/components/BackgroundMaps/MapCard.js +++ b/src/renderer/components/BackgroundMaps/MapCard.js @@ -30,7 +30,7 @@ export const MapboxPrevOnly = ReactMapboxGl({ /** * @typedef MapCardProps * @prop {import('../SettingsView/BackgroundMaps').MapServerStyleInfo} offlineMap - * @prop {React.Dispatch>} setMap + * @prop {React.Dispatch>} setMap * @prop {boolean } isBeingViewed */ @@ -92,7 +92,7 @@ export const MapCard = ({ offlineMap, setMap, isBeingViewed }) => { const useStyles = makeStyles({ root: { - height: 90, + minHeight: '90px', width: '90%', marginBottom: 20, textTransform: 'none', diff --git a/src/renderer/components/BackgroundMaps/SidePanel.js b/src/renderer/components/BackgroundMaps/SidePanel.js index 8ae3a7fc..d15f50c6 100644 --- a/src/renderer/components/BackgroundMaps/SidePanel.js +++ b/src/renderer/components/BackgroundMaps/SidePanel.js @@ -17,8 +17,8 @@ const m = defineMessages({ /** * @typedef SidePanelProps * @prop {()=>void} openSettings - * @prop {string|false} mapValue - * @prop {React.Dispatch>} setMapValue + * @prop {string|null} mapValue + * @prop {React.Dispatch>} setMapValue */ /** @param {SidePanelProps} param */ @@ -37,28 +37,32 @@ export const SidePanel = ({ openSettings, mapValue, setMapValue }) => { {t(m.backToSettings)} -
- -
+
+
+ +
- {isLoading ? ( - - ) : data ? ( - data.map(offlineMap => ( - - )) - ) : null} + {isLoading ? ( + + ) : data ? ( + data.map(offlineMap => ( + <> + + + )) + ) : null} +
{ const { formatMessage: t } = useIntl() - /** @type {MapServerStyleInfo['id']|false} */ - const initialMapId = /** {const} */ false + /** @type {MapServerStyleInfo['id']|null} */ + const initialMapId = /** {const} */ null const [mapValue, setMapValue] = React.useState(initialMapId) const { data } = useMapServerQuery('/styles') - function unsetMapValue() { - setMapValue(false) + function unsetMapValue () { + setMapValue(null) } const offlineMap = React.useMemo( From d07b385f67a7bca1d20180b00083d0371820b1d6 Mon Sep 17 00:00:00 2001 From: lightlii <32508751+lightlii@users.noreply.github.com> Date: Tue, 29 Aug 2023 17:25:51 +0200 Subject: [PATCH 43/51] fix: refactor hooks to simplify where styles data is coming from --- .../components/BackgroundMaps/SidePanel.js | 4 +- .../MapView/BackgroundMapSelector.js | 15 +----- .../components/SettingsView/BackgroundMaps.js | 3 +- src/renderer/hooks/useMapStylesQuery.js | 49 ++++++++++++------- 4 files changed, 37 insertions(+), 34 deletions(-) diff --git a/src/renderer/components/BackgroundMaps/SidePanel.js b/src/renderer/components/BackgroundMaps/SidePanel.js index d15f50c6..be6a07c2 100644 --- a/src/renderer/components/BackgroundMaps/SidePanel.js +++ b/src/renderer/components/BackgroundMaps/SidePanel.js @@ -3,10 +3,10 @@ import { Button, makeStyles } from '@material-ui/core' import ChevronLeft from '@material-ui/icons/ChevronLeft' import * as React from 'react' import { defineMessages, useIntl } from 'react-intl' -import { useMapServerQuery } from '../../hooks/useMapServerQuery' import { ImportMapStyleDialog } from '../dialogs/ImportMapStyle' import Loader from '../Loader' import { MapCard } from './MapCard' +import { useMapStylesQuery } from '../../hooks/useMapStylesQuery' const m = defineMessages({ // Button to add map background @@ -28,7 +28,7 @@ export const SidePanel = ({ openSettings, mapValue, setMapValue }) => { const classes = useStyles() const [open, setOpen] = React.useState(false) - const { data, isLoading, refetch } = useMapServerQuery('/styles', false) + const { data, isLoading, refetch } = useMapStylesQuery(false) return ( <> diff --git a/src/renderer/components/MapFilter/MapView/BackgroundMapSelector.js b/src/renderer/components/MapFilter/MapView/BackgroundMapSelector.js index 3cd73ede..ffa2c627 100644 --- a/src/renderer/components/MapFilter/MapView/BackgroundMapSelector.js +++ b/src/renderer/components/MapFilter/MapView/BackgroundMapSelector.js @@ -17,10 +17,7 @@ import { useExperimentsFlagsStore, usePersistedUiStore } from '../../../hooks/store' -import { - useDefaultMapStyle, - useMapStylesQuery -} from '../../../hooks/useMapStylesQuery' +import { useMapStylesQuery } from '../../../hooks/useMapStylesQuery' import Loader from '../../Loader' const MAPEO_BLUE = '#2469f6' @@ -49,15 +46,7 @@ export const BackgroundMapSelector = ({ active, dismiss }) => { setTabIndex(3) // TODO: Set from an ID rather than hardcoded index } - const backgroundMapsEnabled = useExperimentsFlagsStore( - store => store.backgroundMaps - ) - - const defaultMapStyle = useDefaultMapStyle() - const { isLoading, data } = useMapStylesQuery() - - const mapStyles = - backgroundMapsEnabled && data ? [defaultMapStyle, ...data] : data + const { isLoading, data: mapStyles } = useMapStylesQuery() return ( { const [mapValue, setMapValue] = React.useState(initialMapId) - const { data } = useMapServerQuery('/styles') + const { data } = useMapStylesQuery() function unsetMapValue () { setMapValue(null) diff --git a/src/renderer/hooks/useMapStylesQuery.js b/src/renderer/hooks/useMapStylesQuery.js index 9b63264b..55f15fc4 100644 --- a/src/renderer/hooks/useMapStylesQuery.js +++ b/src/renderer/hooks/useMapStylesQuery.js @@ -18,21 +18,39 @@ const m = defineMessages({ offlineBackgroundMapName: 'Offline Map' }) -export const useMapStylesQuery = () => { +export const useMapStylesQuery = (enabled = true) => { const backgroundMapsEnabled = useExperimentsFlagsStore( store => store.backgroundMaps ) - const legacyStyleQueryResult = useLegacyMapStyleQuery(!backgroundMapsEnabled) + const legacyStyleQueryResult = useLegacyMapStyleQuery( + !backgroundMapsEnabled && enabled + ) const mapStylesQueryResult = useMapServerQuery( '/styles', - backgroundMapsEnabled + backgroundMapsEnabled && enabled ) + const defaultMapStyle = useDefaultMapStyle() + + const queryResult = backgroundMapsEnabled + ? { + data: [ + defaultMapStyle, + ...(mapStylesQueryResult?.data ? mapStylesQueryResult?.data : []) + ], + isLoading: mapStylesQueryResult.isLoading, + refetch: mapStylesQueryResult.refetch + } + : { + data: legacyStyleQueryResult.data, + isLoading: legacyStyleQueryResult.isLoading, + refetch: legacyStyleQueryResult.refetch + } - return backgroundMapsEnabled ? mapStylesQueryResult : legacyStyleQueryResult + return queryResult } -export const useLegacyMapStyleQuery = enabled => { +const useLegacyMapStyleQuery = enabled => { const { formatMessage: t } = useIntl() const defaultMapStyle = useDefaultMapStyle() @@ -61,7 +79,7 @@ export const useLegacyMapStyleQuery = enabled => { return queryResult } -export const useDefaultMapStyle = () => { +const useDefaultMapStyle = () => { const { formatMessage: t } = useIntl() return { @@ -69,23 +87,18 @@ export const useDefaultMapStyle = () => { url: ONLINE_STYLE_URL, bytesStored: 0, name: t(m.defaultBackgroundMapName), - isImporting: false + isImporting: false, + isDefault: true } } export const useSelectedMapStyle = () => { - const backgroundMapsFlag = useExperimentsFlagsStore( - store => store.backgroundMaps - ) const backgroundMapStyleId = useBackgroundMapStore(store => store.mapStyle) - const defaultMapStyle = useDefaultMapStyle() - const { data: mapStyles, isLoading } = useMapStylesQuery() + const { data: mapStyles } = useMapStylesQuery() - if (isLoading || !mapStyles) return defaultMapStyle - - return backgroundMapsFlag - ? mapStyles?.find(style => style.id === backgroundMapStyleId) || - defaultMapStyle - : mapStyles && mapStyles[0] + return ( + mapStyles?.find(style => style.id === backgroundMapStyleId) || + (mapStyles && mapStyles[0]) + ) } From 472cfa18d9831b668a04d986536a3ba1bee35f04 Mon Sep 17 00:00:00 2001 From: lightlii <32508751+lightlii@users.noreply.github.com> Date: Tue, 29 Aug 2023 17:30:20 +0200 Subject: [PATCH 44/51] fix: clean up unused variables --- .../components/MapFilter/MapView/BackgroundMapSelector.js | 1 - src/renderer/components/SettingsView/BackgroundMaps.js | 1 - 2 files changed, 2 deletions(-) diff --git a/src/renderer/components/MapFilter/MapView/BackgroundMapSelector.js b/src/renderer/components/MapFilter/MapView/BackgroundMapSelector.js index ffa2c627..1668e409 100644 --- a/src/renderer/components/MapFilter/MapView/BackgroundMapSelector.js +++ b/src/renderer/components/MapFilter/MapView/BackgroundMapSelector.js @@ -14,7 +14,6 @@ import { Close } from '@material-ui/icons' import { MapPreviewCard } from './MapPreviewCard' import { useBackgroundMapStore, - useExperimentsFlagsStore, usePersistedUiStore } from '../../../hooks/store' import { useMapStylesQuery } from '../../../hooks/useMapStylesQuery' diff --git a/src/renderer/components/SettingsView/BackgroundMaps.js b/src/renderer/components/SettingsView/BackgroundMaps.js index c9443cfa..b447acda 100644 --- a/src/renderer/components/SettingsView/BackgroundMaps.js +++ b/src/renderer/components/SettingsView/BackgroundMaps.js @@ -5,7 +5,6 @@ import Typography from '@material-ui/core/Typography' import { BackgroundMapInfo } from '../BackgroundMaps/BackgroundMapInfo' import { SidePanel } from '../BackgroundMaps/SidePanel' -import { useMapServerQuery } from '../../hooks/useMapServerQuery' import { useMapStylesQuery } from '../../hooks/useMapStylesQuery' const m = defineMessages({ From 0f155562bf715d6f5fc6ab03ad3ba896f0968c61 Mon Sep 17 00:00:00 2001 From: lightlii <32508751+lightlii@users.noreply.github.com> Date: Wed, 30 Aug 2023 14:52:46 +0200 Subject: [PATCH 45/51] fix: save full map style in store and get rid of lookp hook + more tidying up --- .../BackgroundMaps/BackgroundMapInfo.js | 73 +++++++++++-------- .../components/BackgroundMaps/MapCard.js | 27 +++---- .../components/BackgroundMaps/SidePanel.js | 8 +- .../MapView/BackgroundMapSelector.js | 12 +-- .../MapFilter/MapView/MapPreviewCard.js | 2 +- .../components/MapFilter/MapView/MapView.js | 7 +- .../components/SettingsView/BackgroundMaps.js | 33 ++++----- src/renderer/hooks/store.js | 10 ++- src/renderer/hooks/useMapStylesQuery.js | 13 +--- 9 files changed, 95 insertions(+), 90 deletions(-) diff --git a/src/renderer/components/BackgroundMaps/BackgroundMapInfo.js b/src/renderer/components/BackgroundMaps/BackgroundMapInfo.js index 62ada0d5..85ef795c 100644 --- a/src/renderer/components/BackgroundMaps/BackgroundMapInfo.js +++ b/src/renderer/components/BackgroundMaps/BackgroundMapInfo.js @@ -4,14 +4,22 @@ 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 { useMapServerQuery } from '../../hooks/useMapServerQuery' -import { MapboxPrevOnly } from './MapCard' import { convertKbToMb } from '../SettingsView/BackgroundMaps' import { useMapServerMutation } from '../../hooks/useMapServerMutation' import { useBackgroundMapStore } from '../../hooks/store' +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', @@ -34,15 +42,14 @@ const m = defineMessages({ }) /** + * @typedef {import('../../hooks/useMapServerQuery').MapServerStyleInfo & { isDefault?: boolean }} BackgroundMapInfo * @typedef BackgroundMapInfoProps - * @prop {string} id - * @prop {string} url - * @prop {number} size + * @prop {BackgroundMapInfo} map * @prop {()=>void} unsetMapValue */ /** @param {BackgroundMapInfoProps} props */ -export const BackgroundMapInfo = ({ id, unsetMapValue, url, size }) => { +export const BackgroundMapInfo = ({ map, unsetMapValue }) => { const { formatMessage: t } = useIntl() const [mapStyle, setMapStyle] = useBackgroundMapStore(store => [ @@ -50,10 +57,11 @@ export const BackgroundMapInfo = ({ id, unsetMapValue, url, size }) => { store.setMapStyle ]) - const { data } = useMapServerQuery(`/styles/${id}`) const classes = useStyles() - const isCurrentMap = mapStyle === id + const isCurrentMap = mapStyle?.id === map.id + + console.log({ map }) return ( @@ -62,38 +70,36 @@ export const BackgroundMapInfo = ({ id, unsetMapValue, url, size }) => { flex: 1, width: '100%', height: '100%', - padding: !data ? 40 : 0 + padding: !map ? 40 : 0 }} > - {!data ? ( + {!map ? ( ) : ( <> {/* Text */}
- {data.name} + {map.name} - {data.zoom && ( - - {t(m.zoomLevel, { zoom: data.zoom })} - - )} - {`${Math.round( - convertKbToMb(size) - )} ${t(m.mb)}`} + {!map.isDefault ? ( + {`${Math.round( + convertKbToMb(map.bytesStored) + )} ${t(m.mb)}`} + ) : null} + {!isDefault && ( + + )}
diff --git a/src/renderer/components/BackgroundMaps/MapCard.js b/src/renderer/components/BackgroundMaps/MapCard.js index 1953c77e..ea36c6be 100644 --- a/src/renderer/components/BackgroundMaps/MapCard.js +++ b/src/renderer/components/BackgroundMaps/MapCard.js @@ -21,23 +21,21 @@ const m = defineMessages({ export const MapboxPrevOnly = ReactMapboxGl({ accessToken: MAPBOX_ACCESS_TOKEN, - dragRotate: false, - pitchWithRotate: false, - attributionControl: false, + interactive: false, injectCSS: false }) /** * @typedef MapCardProps - * @prop {import('../SettingsView/BackgroundMaps').MapServerStyleInfo} offlineMap + * @prop {import('../SettingsView/BackgroundMaps').MapServerStyleInfo & { isDefault?: boolean }} mapStyle * @prop {React.Dispatch>} setMap * @prop {boolean } isBeingViewed */ /** @param {MapCardProps} param */ -export const MapCard = ({ offlineMap, setMap, isBeingViewed }) => { +export const MapCard = ({ mapStyle, setMap, isBeingViewed }) => { const theme = useTheme() - const mapStyle = useBackgroundMapStore(store => store.mapStyle) + const selectedMapStyle = useBackgroundMapStore(store => store.mapStyle) const classes = useStyles() const { formatMessage: t } = useIntl() @@ -45,7 +43,7 @@ export const MapCard = ({ offlineMap, setMap, isBeingViewed }) => {