@@ -17,7 +17,7 @@ import maputnikLogo from 'maputnik-design/logos/logo-color.svg?inline'
17
17
import { withTranslation , WithTranslation } from 'react-i18next' ;
18
18
import { supportedLanguages } from '../i18n' ;
19
19
20
- import Dropzone from 'react-dropzone' ;
20
+ import { default as Dropzone , FileRejection } from 'react-dropzone' ;
21
21
22
22
// This is required because of <https://stackoverflow.com/a/49846426>, there isn't another way to detect support that I'm aware of.
23
23
const browser = detect ( ) ;
@@ -142,6 +142,14 @@ class AppToolbarInternal extends React.Component<AppToolbarInternalProps> {
142
142
this . props . onLocalPMTilesSelected ( file ) ;
143
143
}
144
144
145
+ onFileRejected = ( r : FileRejection [ ] ) => {
146
+ const errorMessageLine = r . map ( e => {
147
+ return e . errors . map ( f => f . message ) . join ( "\n" )
148
+ } ) . join ( "\n" ) ;
149
+ console . error ( "Dropzone file rejected:" , errorMessageLine ) ;
150
+ alert ( errorMessageLine ) ;
151
+ }
152
+
145
153
render ( ) {
146
154
const t = this . props . t ;
147
155
const views = [
@@ -182,6 +190,10 @@ class AppToolbarInternal extends React.Component<AppToolbarInternalProps> {
182
190
} ,
183
191
] ;
184
192
193
+ const acceptedFileTypes = {
194
+ 'application/octet-stream' : [ ".pmtiles" ]
195
+ }
196
+
185
197
const currentView = views . find ( ( view ) => {
186
198
return view . id === this . props . mapState ;
187
199
} ) ;
@@ -298,7 +310,7 @@ class AppToolbarInternal extends React.Component<AppToolbarInternalProps> {
298
310
< IconText > { t ( "Help" ) } </ IconText >
299
311
</ ToolbarLink >
300
312
301
- < Dropzone onDrop = { this . onFileSelected } >
313
+ < Dropzone onDropAccepted = { this . onFileSelected } onDropRejected = { this . onFileRejected } accept = { acceptedFileTypes } >
302
314
{ ( { getRootProps, getInputProps} ) => (
303
315
< div { ...getRootProps ( { className : 'dropzone maputnik-toolbar-link' } ) } >
304
316
< input { ...getInputProps ( ) } />
0 commit comments