-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
212 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
lint: | ||
make -C backend lint | ||
make -C frontend lint |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
install: | ||
npm install | ||
|
||
lint: | ||
npm run lint | ||
|
||
serve: | ||
npm run dev |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
import { useState } from 'react' | ||
|
||
import { Map } from "./components/Map"; | ||
|
||
function App() { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,27 @@ | ||
import { MapContainer, TileLayer, Marker, Popup } from "react-leaflet"; | ||
|
||
import { useMarkers } from "./hooks"; | ||
|
||
import "./styles.css"; | ||
|
||
export const Map = () => { | ||
const { center, markers } = useMarkers(); | ||
|
||
return ( | ||
<MapContainer center={[40.181389, 44.514444]} zoom={13} maxZoom={18} scrollWheelZoom={true} className="map"> | ||
<MapContainer center={center} zoom={13} maxZoom={18} scrollWheelZoom={true} className="map"> | ||
<TileLayer | ||
attribution='© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors' | ||
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png" | ||
/> | ||
<Marker position={[51.505, -0.09]}> | ||
<Popup> | ||
A pretty CSS3 popup. <br /> Easily customizable. | ||
</Popup> | ||
</Marker> | ||
|
||
{markers.map((marker, index) => ( | ||
<Marker key={index} position={[marker.lat, marker.lon]}> | ||
<Popup> | ||
A pretty CSS3 popup. <br /> Easily customizable. | ||
</Popup> | ||
</Marker> | ||
))} | ||
|
||
</MapContainer> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { useState, useEffect } from "react"; | ||
|
||
import { ITreeInfo } from "./types"; | ||
import { treeMapService } from "../../services/api"; | ||
|
||
export const useMarkers = () => { | ||
const center = [40.181389, 44.514444]; | ||
const [markers, setMarkers] = useState<ITreeInfo>([]); | ||
|
||
useEffect(() => { | ||
(async () => { | ||
const res = await treeMapService.getMarkers(); | ||
console.debug("MARKERS", res); | ||
|
||
setMarkers(res); | ||
})(); | ||
|
||
// Fix markers multiplying on every re-render. | ||
return () => { | ||
setMarkers([]); | ||
}; | ||
}, []); | ||
|
||
console.debug(`Have ${markers.length} markers.`); | ||
|
||
return { | ||
center, | ||
markers, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import axios, { AxiosResponse, AxiosInstance, AxiosRequestConfig } from "axios"; | ||
|
||
import { ITreeInfo } from "./types"; | ||
|
||
export class TreeMapService { | ||
private readonly client: AxiosInstance; | ||
|
||
public constructor() { | ||
this.client = axios.create({ | ||
baseURL: "http://localhost:8000", | ||
timeout: 10000, | ||
responseType: "json", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
}); | ||
} | ||
|
||
public async getMarkers(): Promise<ITreeInfo[]> { | ||
const res = await this.get("/v1/trees"); | ||
return res.data.trees; | ||
} | ||
|
||
private async get<T>(url: string, config?: AxiosRequestConfig): Promise<AxiosResponse<T>> { | ||
return this.client.get<T>(url, config); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { TreeMapService } from "./TreeMapService"; | ||
|
||
export const treeMapService = new TreeMapService(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export interface ITreeInfo { | ||
id: number; | ||
lat: number; | ||
lon: number; | ||
} |