moved Dropzone's onDrop handler to AppToolbar

This commit is contained in:
prusswan
2025-01-26 17:30:23 +08:00
parent d6067814a8
commit a2572c2f5b
2 changed files with 10 additions and 7 deletions
+3 -5
View File
@@ -884,11 +884,9 @@ export default class App extends React.Component<any, AppState> {
}); });
} }
onFileSelected = (e: File[]) => { onLocalPMTilesSelected = (file: File) => {
const file = e[0];
const pmt = new PMTiles(new FileSource(file));
this.setState({ this.setState({
localPMTiles: pmt localPMTiles: new PMTiles(new FileSource(file))
}) })
} }
@@ -906,7 +904,7 @@ export default class App extends React.Component<any, AppState> {
onStyleOpen={this.onStyleChanged} onStyleOpen={this.onStyleChanged}
onSetMapState={this.setMapState} onSetMapState={this.setMapState}
onToggleModal={this.toggleModal.bind(this)} onToggleModal={this.toggleModal.bind(this)}
onFileSelected={this.onFileSelected} onLocalPMTilesSelected={this.onLocalPMTilesSelected}
/> />
const layerList = <LayerList const layerList = <LayerList
+7 -2
View File
@@ -105,7 +105,7 @@ type AppToolbarInternalProps = {
onSetMapState(mapState: MapState): unknown onSetMapState(mapState: MapState): unknown
mapState?: MapState mapState?: MapState
renderer?: string renderer?: string
onFileSelected(...args: unknown[]): unknown onLocalPMTilesSelected(file: File): unknown
} & WithTranslation; } & WithTranslation;
class AppToolbarInternal extends React.Component<AppToolbarInternalProps> { class AppToolbarInternal extends React.Component<AppToolbarInternalProps> {
@@ -137,6 +137,11 @@ class AppToolbarInternal extends React.Component<AppToolbarInternalProps> {
} }
} }
onFileSelected = (e: File[]) => {
const file = e[0];
this.props.onLocalPMTilesSelected(file);
}
render() { render() {
const t = this.props.t; const t = this.props.t;
const views = [ const views = [
@@ -293,7 +298,7 @@ class AppToolbarInternal extends React.Component<AppToolbarInternalProps> {
<IconText>{t("Help")}</IconText> <IconText>{t("Help")}</IconText>
</ToolbarLink> </ToolbarLink>
<Dropzone onDrop={this.props.onFileSelected}> <Dropzone onDrop={this.onFileSelected}>
{({getRootProps, getInputProps}) => ( {({getRootProps, getInputProps}) => (
<div {...getRootProps({className: 'dropzone maputnik-toolbar-link'})}> <div {...getRootProps({className: 'dropzone maputnik-toolbar-link'})}>
<input {...getInputProps()} /> <input {...getInputProps()} />