Skip to content

Commit

Permalink
app: make load tiles button work (#153)
Browse files Browse the repository at this point in the history
* app: make load tiles button work

* fix prettier
  • Loading branch information
bdon authored Oct 15, 2023
1 parent a713637 commit 0a6b861
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions app/src/MapViewComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { useEffect, useState, useRef, KeyboardEvent, useCallback } from "react";
import {
useEffect,
useState,
useRef,
KeyboardEvent,
FormEvent,
useCallback,
} from "react";
import layers from "../../styles/src/index.ts";
import maplibregl from "maplibre-gl";
import { StyleSpecification } from "maplibre-gl";
Expand Down Expand Up @@ -287,6 +294,15 @@ export default function MapViewComponent() {
}
};

const loadTiles = (event: FormEvent<HTMLFormElement>) => {
event.preventDefault();
const formData = new FormData(event.target as HTMLFormElement);
const tilesValue = formData.get("tiles");
if (typeof tilesValue === "string") {
setTiles(tilesValue);
}
};

const loadVersionsFromNpm = async () => {
const resp = await fetch(
"https://registry.npmjs.org/protomaps-themes-base",
Expand Down Expand Up @@ -324,8 +340,15 @@ export default function MapViewComponent() {
return (
<div className="map-container">
<nav>
<input defaultValue={tiles} style={{ width: "50%" }} />
<button>load</button>
<form onSubmit={loadTiles}>
<input
type="text"
name="tiles"
defaultValue={tiles}
style={{ width: "50%" }}
/>
<button type="submit">load</button>
</form>
<span {...getRootProps()}>Drop Zone</span>
<select onChange={(e) => setTheme(e.target.value)} value={theme}>
<option value="light">light</option>
Expand Down

0 comments on commit 0a6b861

Please sign in to comment.