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] 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 }) => {