From df52776c28c8758726b643262edcf5435c6b7828 Mon Sep 17 00:00:00 2001 From: franciszek Date: Tue, 5 Jan 2021 18:47:16 +0100 Subject: [PATCH] Uploading images and pining location --- src/app.tsx | 105 +++++++++++++++++++++++++++++++++++++++++--- src/styles/app.scss | 12 ++++- 2 files changed, 111 insertions(+), 6 deletions(-) diff --git a/src/app.tsx b/src/app.tsx index dee72b6..05808fb 100644 --- a/src/app.tsx +++ b/src/app.tsx @@ -1,19 +1,114 @@ -import * as React from "react"; +import React, { useState, useReducer } from "react"; import * as ReactDOM from "react-dom"; +import "regenerator-runtime/runtime"; +import { + MapContainer, + TileLayer, + Marker, + Popup, + useMapEvents, +} from "react-leaflet"; import "./styles/reset.css"; import "./styles/app.scss"; -const App = () => { +const App: React.FC = () => { + const [files, setFiles] = useState([]); + const [mapPin, setMapPin] = useState([52.39663, 16.89866]); + + const handleSubmit = async ( + event: React.FormEvent + ): Promise => { + event.preventDefault(); + }; + + const handleUpload = (e: React.ChangeEvent) => { + const files = e.target.files; + const newstate = []; + const readAndPreview = (file) => { + // Make sure `file.name` matches our extensions criteria + if (/\.(jpe?g|png|svg)$/i.test(file.name)) { + let reader = new FileReader(); + reader.addEventListener( + "load", + function () { + newstate.push(this.result); + setFiles([...newstate]); + }, + false + ); + reader.readAsDataURL(file); + } + }; + if (files) { + [].forEach.call(files, readAndPreview); + } + }; + const MapComponent = () => { + useMapEvents({ + click: (e) => { + setMapPin([e.latlng.lat, e.latlng.lng]); + console.log(mapPin); + }, + }); + return null; + }; return (
-

Photos

+

Zdjęcia

+
+ {files.map((file) => ( +
+ +
+ ))} +
+ handleUpload(e)} + />
-

Map

+

Mapa

+
+ + + + + +
-

Form

+

Formularz zgłoszeniowy

+
handleSubmit(e)} + > + + + + + + + +