chore: direct import of the Alert class in modules

This commit is contained in:
David Larlet 2024-06-12 18:30:40 -04:00
parent cea2aee88f
commit 8400b55b9d
No known key found for this signature in database
GPG key ID: 3E2953A359E7E7BD
2 changed files with 10 additions and 6 deletions

View file

@ -1,5 +1,6 @@
import { DomUtil, DomEvent } from '../../vendors/leaflet/leaflet-src.esm.js'
import { translate } from './i18n.js'
import { uMapAlert as Alert } from '../components/alerts/alert.js'
export default class Importer {
constructor(map) {
@ -163,12 +164,14 @@ export default class Importer {
this.map.processFileToImport(file, layer, type)
}
} else {
if (!type) return U.Alert.error(L._('Please choose a format'))
if (!type) {
return Alert.error(L._('Please choose a format'))
}
if (this.rawInput.value && type === 'umap') {
try {
this.map.importRaw(this.rawInput.value, type)
} catch (e) {
U.Alert.error(L._('Invalid umap data'))
Alert.error(L._('Invalid umap data'))
console.error(e)
}
} else {

View file

@ -1,4 +1,5 @@
import { translate } from './i18n.js'
import { uMapAlert as Alert } from '../components/alerts/alert.js'
export class RequestError extends Error {}
@ -79,7 +80,7 @@ export class Request extends BaseRequest {
}
_onError(error) {
U.Alert.error(translate('Problem in the response'))
Alert.error(translate('Problem in the response'))
}
_onNOK(error) {
@ -125,9 +126,9 @@ export class ServerRequest extends Request {
try {
const data = await response.json()
if (data.info) {
U.Alert.info(data.info)
Alert.info(data.info)
} else if (data.error) {
U.Alert.error(data.error)
Alert.error(data.error)
return this._onError(new Error(data.error))
}
return [data, response, null]
@ -142,7 +143,7 @@ export class ServerRequest extends Request {
_onNOK(error) {
if (error.status === 403) {
U.Alert.error(error.message || translate('Action not allowed :('))
Alert.error(error.message || translate('Action not allowed :('))
}
return [{}, error.response, error]
}