Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: list styles, BG Map Management #678

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore: add map and list styles
ErikSin committed Dec 10, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit fd653ef2083f907aec9456471fc27127747a91ee
40 changes: 21 additions & 19 deletions src/renderer/components/BackgroundMaps/BackgroundMapInfo.js
Original file line number Diff line number Diff line change
@@ -28,11 +28,17 @@ const m = defineMessages({
* @typedef BackgroundMapInfoProps
* @prop {string} id
* @prop {string} idBeingViewed
* @prop {React.Dispatch<React.SetStateAction<string | false>>} setMapValue
* @prop {string} url
* @prop {()=>void} unsetMapValue
*/

/** @param {BackgroundMapInfoProps} props */
export const BackgroundMapInfo = ({ id, idBeingViewed, setMapValue }) => {
export const BackgroundMapInfo = ({
id,
idBeingViewed,
unsetMapValue,
url
}) => {
const shouldLoad = React.useMemo(() => id === idBeingViewed, [
id,
idBeingViewed
@@ -54,7 +60,12 @@ export const BackgroundMapInfo = ({ id, idBeingViewed, setMapValue }) => {
{!data ? (
<Loading />
) : (
<MapInfo backgroundMap={data} id={id} setMapValue={setMapValue} />
<MapInfo
backgroundMap={data}
id={id}
unsetMapValue={unsetMapValue}
url={url}
/>
)}
</Paper>
</Fade>
@@ -65,13 +76,13 @@ export const BackgroundMapInfo = ({ id, idBeingViewed, setMapValue }) => {
* @typedef MapInfoProps
* @prop {import('@mapeo/map-server/dist/lib/stylejson').StyleJSON} backgroundMap
* @prop {string} id
* @prop {React.Dispatch<React.SetStateAction<string | false>>} setMapValue
* @prop {()=>void} unsetMapValue
* @prop {string} url
*/

/** @param {MapInfoProps} props */
const MapInfo = ({ backgroundMap, id, setMapValue }) => {
const MapInfo = ({ backgroundMap, id, unsetMapValue, url }) => {
const { name } = backgroundMap
const mutation = useMapServerMutation('delete', `/styles/${id}`)

const classes = useStyles()

@@ -85,16 +96,10 @@ const MapInfo = ({ backgroundMap, id, setMapValue }) => {
*
* @param {string} mapId
*/

// To Do, useMapServerMutation.mutate()
function deleteMap (mapId) {
try {
// mutation.mutate(mapId)
// setMapValue(false)
} catch (err) {
remote.dialog.showErrorBox(
t(m.deleteErrorTitle),
t(m.deleteErrorDescription) + ': ' + err
)
}
return
}

return (
@@ -114,10 +119,7 @@ const MapInfo = ({ backgroundMap, id, setMapValue }) => {
</Paper>

{/* Map */}
<MapBox
style={'mapbox://styles/mapbox/streets-v11'}
containerStyle={{ height: '40%', width: '100%' }}
/>
<MapBox style={url} containerStyle={{ height: '40%', width: '100%' }} />

{/* Text under map: */}
<div style={{ padding: 40 }}>
2 changes: 1 addition & 1 deletion src/renderer/components/BackgroundMaps/MapCard.js
Original file line number Diff line number Diff line change
@@ -60,7 +60,7 @@ export const MapCard = ({ offlineMap, setMap, mapBeingViewed }) => {
height: '100%',
width: '100%'
}}
style='mapbox://styles/mapbox/streets-v11'
style={offlineMap.url}
/>
</div>
<div className={classes.text}>
128 changes: 0 additions & 128 deletions src/renderer/components/BackgroundMaps/OfflineAreaCard.js

This file was deleted.

23 changes: 7 additions & 16 deletions src/renderer/components/BackgroundMaps/SidePanel.js
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ import { remote } from 'electron'
import * as React from 'react'
import { defineMessages, useIntl } from 'react-intl'
import { useMapServerMutation } from '../../hooks/useMapServerMutation'
import { useMapServerQuery } from '../../hooks/useMapServerQuery'
import Loader from '../Loader'
import { MapCard } from './MapCard'

@@ -24,28 +25,18 @@ const m = defineMessages({
/**
* @typedef SidePanelProps
* @prop {()=>void} openSettings
* @prop {import('../Settings/BackgroundMaps').MapServerStyleInfo[]|false} offlineMaps
* @prop {string|false} mapValue
* @prop {boolean} isFetching
* @prop {React.Dispatch<React.SetStateAction<string | false>>} setMapValue
* @prop {unknown} error
*/

/** @param {SidePanelProps} param */
export const SidePanel = ({
openSettings,
offlineMaps,
mapValue,
setMapValue,
isFetching,
error
}) => {
export const SidePanel = ({ openSettings, mapValue, setMapValue }) => {
const { formatMessage: t } = useIntl()

if (error) console.log(error)

const classes = useStyles()

const { data, isLoading } = useMapServerQuery('/styles', true)

const mutation = useMapServerMutation('post', `/tilesets/import`)

async function selectMbTileFile () {
@@ -93,10 +84,10 @@ export const SidePanel = ({
</Button>
</div>

{isFetching ? (
{isLoading ? (
<Loader />
) : offlineMaps ? (
offlineMaps.map(offlineMap => (
) : data ? (
data.map(offlineMap => (
<MapCard
setMap={setMapValue}
key={offlineMap.id}
15 changes: 7 additions & 8 deletions src/renderer/components/Settings/BackgroundMaps.js
Original file line number Diff line number Diff line change
@@ -23,25 +23,23 @@ const m = defineMessages({
export const BackgroundMaps = ({ openSettings }) => {
const { formatMessage: t } = useIntl()

/** @type {MapServerStyleInfo[]|false} */
const initialMapState = /** {const} */ (false)

/** @type {MapServerStyleInfo['id']|false} */
const initialMapId = /** {const} */ (false)

const [mapValue, setMapValue] = React.useState(initialMapId)

const { data, isFetching, error } = useMapServerQuery('/styles')
const { data } = useMapServerQuery('/styles')

function unsetMapValue () {
setMapValue(false)
}

return (
<React.Fragment>
<SidePanel
mapValue={mapValue}
offlineMaps={data || false}
openSettings={openSettings}
setMapValue={setMapValue}
isFetching={isFetching}
error={error}
/>

{!mapValue || !data ? (
@@ -66,7 +64,8 @@ export const BackgroundMaps = ({ openSettings }) => {
key={offlineMap.id}
idBeingViewed={mapValue}
id={offlineMap.id}
setMapValue={setMapValue}
unsetMapValue={unsetMapValue}
url={offlineMap.url}
/>
))}
</React.Fragment>
3 changes: 2 additions & 1 deletion src/renderer/hooks/useMapServerMutation.js
Original file line number Diff line number Diff line change
@@ -18,9 +18,10 @@ export function useMapServerMutation (mutationType, resourcePath) {
return useMutation({
mutationFn: bodyFromMutation =>
kyFunction(MAP_SERVER_URL + resourcePath, bodyFromMutation),
onSuccess: () =>
onSuccess: () => {
queryClient.invalidateQueries({
queryKey: [`/${resourcePath.split('/')[1]}`]
})
}
})
}
3 changes: 1 addition & 2 deletions src/renderer/hooks/useMapServerQuery.js
Original file line number Diff line number Diff line change
@@ -9,7 +9,6 @@ const MAP_SERVER_URL = 'http://127.0.0.1:' + window.mapServerPort
export function useMapServerQuery (resourcePath, enabled) {
return useQuery({
queryKey: [resourcePath],
queryFn: () => ky.get(MAP_SERVER_URL + resourcePath).json(),
enabled
queryFn: () => ky.get(MAP_SERVER_URL + resourcePath).json()
})
}