Skip to content

Commit 8f185c8

Browse files
committed
chg: feedback for upload configuration
1 parent 519f54e commit 8f185c8

File tree

3 files changed

+27
-17
lines changed

3 files changed

+27
-17
lines changed

public/locales/en/translation.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
"download-configuration": "Download configuration",
4242
"upload-configuration": "Upload configuration",
4343
"drag-drop-config": "Drag 'n' drop a configuration, or click to select one",
44+
"config-loaded-success": "Configuration loaded successfully",
45+
"config-load-error": "Failed to load configuration. Please check the URL and try again.",
4446
"raster-cogtiff": "Raster (COGTiff)",
4547
"vector-pmtiles": "Vector (PMTiles)",
4648
"bands": "Bands",

public/locales/no/translation.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
"download-configuration": "Last ned konfigurasjon",
4242
"upload-configuration": "Last opp konfigurasjon",
4343
"drag-drop-config": "Dra og slipp en konfigurasjon, eller klikk for å velge en",
44+
"config-loaded-success": "Konfigurasjon lastet inn",
45+
"config-load-error": "Kunne ikke laste konfigurasjon. Vennligst sjekk URL-en og prøv igjen.",
4446
"raster-cogtiff": "Raster (COGTiff)",
4547
"vector-pmtiles": "Vektor (PMTiles)",
4648
"bands": "Bånd",

src/routes/editor/_layout/edit/settings.tsx

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import axios from 'axios';
33
import { useCallback, useState } from 'react';
44
import { useDropzone } from 'react-dropzone';
55
import { useTranslation } from 'react-i18next';
6+
import { toast } from 'react-toastify';
67
import { SettingsForm } from '../../../../components/forms/SettingsForm';
78
import { useAppActions, useAppStore } from '../../../../hooks/app';
89
import type { MapConfig } from '../../../../types';
@@ -46,31 +47,36 @@ function RouteComponent() {
4647
// TODO: set configurations in a safer way!
4748
useAppStore.setState(() => config);
4849
setConfigUrl('');
50+
toast.success(t('config-loaded-success'));
4951
} catch (error) {
5052
console.error('Failed to load config from URL:', error);
51-
alert('Failed to load configuration from URL. Please check the URL and try again.');
53+
toast.error(t('config-load-error'));
5254
} finally {
5355
setIsLoading(false);
5456
}
55-
}, [configUrl]);
57+
}, [configUrl, t]);
5658

57-
const onDrop = useCallback((acceptedFiles: File[]) => {
58-
acceptedFiles.forEach(file => {
59-
const reader = new FileReader();
59+
const onDrop = useCallback(
60+
(acceptedFiles: File[]) => {
61+
acceptedFiles.forEach(file => {
62+
const reader = new FileReader();
6063

61-
// TODO: improve logging and error management
62-
reader.onabort = () => console.warn('file reading was aborted');
63-
reader.onerror = () => console.error('file reading has failed');
64-
reader.onload = () => {
65-
const config = JSON.parse(reader.result as string) as MapConfig;
66-
console.debug(config);
64+
// TODO: improve logging and error management
65+
reader.onabort = () => console.warn('file reading was aborted');
66+
reader.onerror = () => console.error('file reading has failed');
67+
reader.onload = () => {
68+
const config = JSON.parse(reader.result as string) as MapConfig;
69+
console.debug(config);
6770

68-
// TODO: set configurations in a safer way!
69-
useAppStore.setState(() => config);
70-
};
71-
reader.readAsText(file);
72-
});
73-
}, []);
71+
// TODO: set configurations in a safer way!
72+
useAppStore.setState(() => config);
73+
toast.success(t('config-loaded-success'));
74+
};
75+
reader.readAsText(file);
76+
});
77+
},
78+
[t],
79+
);
7480

7581
const settings = useAppStore(store => store.config);
7682

0 commit comments

Comments
 (0)