TagSpaces is an offline, open source, document manager with tagging support
Fix crash empty map tile server list (#1435)
Stanimir24553e76d34a
diff --git a/app/components/EntryProperties.tsx b/app/components/EntryProperties.tsxindex 813081478..57352a76f 100644--- a/app/components/EntryProperties.tsx+++ b/app/components/EntryProperties.tsx@@ -86,6 +86,7 @@ import Marker2xIcon from '-/assets/icons/marker-icon-2x.png';import MarkerShadowIcon from '-/assets/icons/marker-shadow.png';import ConfirmDialog from '-/components/dialogs/ConfirmDialog';import { TS } from '-/tagspaces.namespace';+import NoTileServer from '-/components/NoTileServer';const ThumbnailChooserDialog =Pro && Pro.UI ? Pro.UI.ThumbnailChooserDialog : false;@@ -757,10 +758,14 @@ const EntryProperties = (props: Props) => {zoomControl={true}attributionControl={false}>- <TileLayer- attribution={props.tileServer.serverInfo}- url={props.tileServer.serverURL}- />+ {props.tileServer ? (+ <TileLayer+ attribution={props.tileServer.serverInfo}+ url={props.tileServer.serverURL}+ />+ ) : (+ <NoTileServer />+ )}<LayerGroup><Markericon={iconFileMarker}diff --git a/app/components/NoTileServer.tsx b/app/components/NoTileServer.tsxnew file mode 100644index 000000000..1d438c733--- /dev/null+++ b/app/components/NoTileServer.tsx@@ -0,0 +1,11 @@+import React from 'react';+import i18n from '-/services/i18n';++const NoTileServer = () => (+ <div style={{ textAlign: 'center' }}>+ <h1>{i18n.t('core:noTileServersTitle')}</h1>+ <h3>{i18n.t('core:addTileServersSettings')}</h3>+ </div>+);++export default NoTileServer;diff --git a/app/components/dialogs/settings/MapTileServerDialog.tsx b/app/components/dialogs/settings/MapTileServerDialog.tsxindex 76eec15fc..ed09ceb62 100644--- a/app/components/dialogs/settings/MapTileServerDialog.tsx+++ b/app/components/dialogs/settings/MapTileServerDialog.tsx@@ -173,35 +173,39 @@ const MapTileServerDialog = (props: Props) => {const renderActions = () => (<DialogActionsstyle={{- justifyContent: 'flex-end'+ justifyContent: props.tileServer.uuid ? 'space-between' : 'flex-end'}}>{props.tileServer.uuid && (<Button+ style={{+ marginLeft: 10+ }}data-tid="deleteTileServerTID"onClick={() => {props.deleteTileServer(props.tileServer.uuid);props.onClose();}}- color="secondary">{i18n.t('core:delete')}</Button>)}- <Button- data-tid="closeTileServerDialogTID"- onClick={props.onClose}- color="primary"- >- {i18n.t('core:closeButton')}- </Button>- <Button- data-tid="saveTileServerDialogTID"- onClick={saveTileServer}- color="primary"- >- {i18n.t('core:confirmSaveButton')}- </Button>+ <div>+ <Button+ data-tid="closeTileServerDialogTID"+ onClick={props.onClose}+ color="primary"+ >+ {i18n.t('core:closeButton')}+ </Button>+ <Button+ data-tid="saveTileServerDialogTID"+ onClick={saveTileServer}+ color="primary"+ >+ {i18n.t('core:confirmSaveButton')}+ </Button>+ </div></DialogActions>);diff --git a/app/components/dialogs/settings/SettingsGeneral.tsx b/app/components/dialogs/settings/SettingsGeneral.tsxindex 382432595..9a913055b 100644--- a/app/components/dialogs/settings/SettingsGeneral.tsx+++ b/app/components/dialogs/settings/SettingsGeneral.tsx@@ -42,7 +42,8 @@ import i18n from '-/services/i18n';import {actions as SettingsActions,getPersistTagsInSidecarFile,- getSettings+ getSettings,+ getMapTileServers} from '-/reducers/settings';import ColorPickerDialog from '../ColorPickerDialog';import TransparentBackground from '../../TransparentBackground';@@ -386,35 +387,44 @@ const SettingsGeneral = (props: Props) => {</IconButton></ListItemSecondaryAction></ListItem>- {props.tileServers.map((tileServer, index) => (- <ListItem key={tileServer.uuid} className={classes.listItem}>+ {props.tileServers.length > 0 ? (+ props.tileServers.map((tileServer, index) => (+ <ListItem key={tileServer.uuid} className={classes.listItem}>+ <ListItemText+ primary={tileServer.name}+ secondary={tileServer.serverURL}+ />+ <ListItemSecondaryAction>+ {index === 0 && (+ <Tooltip title={i18n.t('core:serverIsDefaultHelp')}>+ <CheckIcon+ data-tid="tileServerDefaultIndication"+ style={{ marginLeft: 10 }}+ />+ </Tooltip>+ )}+ <IconButton+ aria-label={i18n.t('core:options')}+ aria-haspopup="true"+ edge="end"+ data-tid={'tileServerEdit_' + tileServer.name}+ onClick={event =>+ handleEditTileServerClick(event, tileServer, index === 0)+ }+ >+ <EditIcon />+ </IconButton>+ </ListItemSecondaryAction>+ </ListItem>+ ))+ ) : (+ <ListItem key="noTileServers" className={classes.listItem}><ListItemText- primary={tileServer.name}- secondary={tileServer.serverURL}+ primary={i18n.t('core:noTileServersTitle')}+ secondary={i18n.t('core:addTileServersHelp')}/>- <ListItemSecondaryAction>- {index === 0 && (- <Tooltip title={i18n.t('core:serverIsDefaultHelp')}>- <CheckIcon- data-tid="startupIndication"- style={{ marginLeft: 10 }}- />- </Tooltip>- )}- <IconButton- aria-label={i18n.t('core:options')}- aria-haspopup="true"- edge="end"- data-tid={'locationMoreButton_' + tileServer.name}- onClick={event =>- handleEditTileServerClick(event, tileServer, index === 0)- }- >- <EditIcon />- </IconButton>- </ListItemSecondaryAction></ListItem>- ))}+ )}{/* <ListItem className={classes.listItem}><ListItemText primary={i18n.t('core:coloredFileExtensionsEnabled')} /><Switch@@ -475,7 +485,7 @@ function mapStateToProps(state) {return {settings: getSettings(state),persistTagsInSidecarFile: getPersistTagsInSidecarFile(state),- tileServers: state.settings.tileServers+ tileServers: getMapTileServers(state)};}diff --git a/app/config.ts b/app/config.tsindex 0d5e269e1..dc7333077 100644--- a/app/config.ts+++ b/app/config.ts@@ -122,6 +122,7 @@ export const AppConfig = {? window.ExtShowWelcomePanel: true,locationsReadOnly: window.ExtLocations !== undefined,+ mapTileServers: window.ExtMapTileServers || false,sidebarColor: window.ExtSidebarColor || '#2C001E', // '#00D1A1' // #008023sidebarSelectionColor: window.ExtSidebarSelectionColor || '#880E4F',lightThemeLightColor: window.ExtLightThemeLightColor || '#dcf3ec',diff --git a/app/locales/en/core.json b/app/locales/en/core.jsonindex 34c8dd787..aa1c162fd 100644--- a/app/locales/en/core.json+++ b/app/locales/en/core.json@@ -564,6 +564,9 @@"tileServerUrlTitle": "Server URL","tileServerUrlHelp": "Example: https://{s}.tile.osm.org/{z}/{x}/{y}.png","tileServerInfoTitle": "Copyright Information",- "serverIsDefaultHelp": "Default Map Tile Server",+ "serverIsDefaultHelp": "Set as Default Map Tile Server",+ "noTileServersTitle": "No map tile server!",+ "addTileServersHelp": "Further map tile servers can be found here: https://wiki.openstreetmap.org/wiki/Tile_servers",+ "addTileServersSettings": "In order to see the map, add at least one map tile server in the settings of the app","-": "-"}diff --git a/app/reducers/settings-default.ts b/app/reducers/settings-default.tsindex 0f7332115..f4a08ad5a 100644--- a/app/reducers/settings-default.ts+++ b/app/reducers/settings-default.ts@@ -25,28 +25,6 @@ if (window.ExtDisplayMode && window.ExtDisplayMode === 'mobile') {desktopMode = true;}-let tileServers;-if (window.ExtTileServers) {- tileServers = window.ExtTileServers;-} else {- tileServers = [- {- uuid: '1',- name: 'Standard',- serverURL: 'https://{s}.tile.osm.org/{z}/{x}/{y}.png',- serverInfo:- '<b>Leaflet</b> | Map data © <b>https://openstreetmap.org/copyright</b> contributors, <b>CC-BY-SA</b>, Imagery © <b>Mapbox</b>'- },- {- uuid: '2',- name: 'Topographic',- serverURL: 'https://{s}.tile.opentopomap.org/{z}/{x}/{y}.png',- serverInfo:- '<b>Leaflet</b> | Map data: © <b>https://openstreetmap.org/copyright</b> contributors, <b>http://viewfinderpanoramas.org</b> - SRTM | Map style: © <b>https://opentopomap.org</b> - OpenTopoMap (<b>https://creativecommons.org/licenses/by-sa/3.0/</b> - CC-BY-SA'- }- ];-}-export function findAvailableExtensions() {// TODO Search in users tagspaces folder// Search in the installation folder@@ -137,7 +115,6 @@ export function findAvailableExtensions() {}export default {- tileServers,settingsVersion: 3,isLoading: false,error: null,@@ -789,5 +766,21 @@ export default {viewer: '@tagspaces/spreadsheet-viewer',color: '#b2f30e'}+ ],+ mapTileServers: [+ {+ uuid: '1b25af5e-dd15-4415-83cb-7eb53d15e336',+ name: 'Standard',+ serverURL: 'https://{s}.tile.osm.org/{z}/{x}/{y}.png',+ serverInfo:+ '<b>Leaflet</b> | Map data: © <b>https://openstreetmap.org/copyright</b> contributors, <b>CC-BY-SA</b>, Imagery © <b>Mapbox</b>'+ },+ {+ uuid: '5b4be90f-3c7b-4157-8ee3-2c7a3e7cf827',+ name: 'Topographic',+ serverURL: 'https://{s}.tile.opentopomap.org/{z}/{x}/{y}.png',+ serverInfo:+ '<b>Leaflet</b> | Map data: © <b>https://openstreetmap.org/copyright</b> contributors, SRTM | Map style: © <b>https://opentopomap.org</b> - OpenTopoMap (<b>https://creativecommons.org/licenses/by-sa/3.0/</b> - CC-BY-SA'+ }]};diff --git a/app/reducers/settings.ts b/app/reducers/settings.tsindex 7d3806b22..fb84e92a2 100644--- a/app/reducers/settings.ts+++ b/app/reducers/settings.ts@@ -18,12 +18,11 @@import semver from 'semver';import uuidv1 from 'uuid';-import i18n from '../services/i18n';-// import AppConfig from '../config';+import i18n from '-/services/i18n';import defaultSettings from './settings-default';-import PlatformIO from '../services/platform-io';-import AppConfig from '../config';-import versionMeta from '../version.json';+import PlatformIO from '-/services/platform-io';+import AppConfig from '-/config';+import versionMeta from '-/version.json';import { actions as AppActions } from './app';import { TS } from '-/tagspaces.namespace';@@ -310,35 +309,35 @@ export default (state: any = defaultSettings, action: any) => {};}case types.ADD_MAPTILE_SERVER: {- let tileServers;+ let mapTileServers;if (action.isDefault) {- tileServers = [+ mapTileServers = [{ ...action.tileServer, uuid: uuidv1() },- ...state.tileServers+ ...state.mapTileServers];} else {- tileServers = [- ...state.tileServers,+ mapTileServers = [+ ...state.mapTileServers,{ ...action.tileServer, uuid: uuidv1() }];}return {...state,- tileServers+ mapTileServers};}case types.EDIT_MAPTILE_SERVER: {- let tileServers;+ let mapTileServers;if (action.isDefault) {- tileServers = [+ mapTileServers = [action.tileServer,- ...state.tileServers.filter(+ ...state.mapTileServers.filter(tileServer => tileServer.uuid !== action.tileServer.uuid)];} else {- tileServers = [- ...state.tileServers.filter(+ mapTileServers = [+ ...state.mapTileServers.filter(tileServer => tileServer.uuid !== action.tileServer.uuid),action.tileServer@@ -347,16 +346,16 @@ export default (state: any = defaultSettings, action: any) => {return {...state,- tileServers+ mapTileServers};}case types.DELETE_MAPTILE_SERVER: {- const tileServers = state.tileServers.filter(+ const mapTileServers = state.mapTileServers.filter(tileServer => tileServer.uuid !== action.uuid);return {...state,- tileServers+ mapTileServers};}default: {@@ -569,7 +568,11 @@ export function getLastVersionPromise(): Promise<string> {// Selectorsexport const getMapTileServer = (state: any): TS.MapTileServer =>- state.settings.tileServers[0];+ AppConfig.mapTileServers+ ? AppConfig.mapTileServers[0]+ : state.settings.mapTileServers[0];+export const getMapTileServers = (state: any): Array<TS.MapTileServer> =>+ AppConfig.mapTileServers || state.settings.mapTileServers;export const getSettings = (state: any) => state.settings;export const getDesktopMode = (state: any) => {if (typeof window.ExtDisplayMode === 'undefined') {diff --git a/app/tagspaces.d.ts b/app/tagspaces.d.tsindex 145c4b1b5..dd66266be 100644--- a/app/tagspaces.d.ts+++ b/app/tagspaces.d.ts@@ -27,7 +27,7 @@ declare module '*.xml';declare interface Window {// interface TSCustomWindow extends Window {- ExtTileServers?: Array<TS.MapTileServer>;+ ExtMapTileServers?: Array<TS.MapTileServer>;walkCanceled?: boolean;ExtLogoURL?: string;ExtDefaultVerticalPanel?: string;