From 8e79c5dbfc183d0d700a51683435e72a1f8215eb Mon Sep 17 00:00:00 2001 From: "Begerad, Stefan" Date: Fri, 11 Aug 2023 14:24:34 +0200 Subject: [PATCH] feat: add app/utils/request.js --- app/components/hello.jsx | 15 ----- app/pages/home.jsx | 126 +++++++++++++++++++++++++++++++++++++-- app/utils/request.js | 16 +++++ 3 files changed, 138 insertions(+), 19 deletions(-) delete mode 100644 app/components/hello.jsx create mode 100644 app/utils/request.js diff --git a/app/components/hello.jsx b/app/components/hello.jsx deleted file mode 100644 index ba72c06..0000000 --- a/app/components/hello.jsx +++ /dev/null @@ -1,15 +0,0 @@ -import React from 'react'; -import PropTypes from 'prop-types'; - -//destructure props -export default function Hello({msg}) { - return ( - <> -

{msg}

- - ); -} - -Hello.propTypes = { - msg: PropTypes.string, -}; diff --git a/app/pages/home.jsx b/app/pages/home.jsx index f1aad88..f68f73f 100644 --- a/app/pages/home.jsx +++ b/app/pages/home.jsx @@ -1,11 +1,129 @@ -import React from 'react'; -import Hello from '../components/hello'; +import React, { useEffect, useState } from 'react'; +import {get} from '../utils/request'; export default function Home() { + + const [bsRry, setBsRry] = useState([]); + const [bpRry, setBpRry] = useState([]); + const [prRry, setPrRry] = useState([]); + const [shopRry, setShopRry] = useState([]); + const [taxiRry, setTaxiRry] = useState([]); + const [vmRry, setVmRry] = useState([]); + + useEffect(() => { + const address = 'https://overpass-api.de/api/interpreter?data=[out:json][timeout:60];node[uic_ref=8000050];'; + //get bus stop + get(address + 'nwr[highway=bus_stop](around:200);out body center qt;') + .then(data => { + setBsRry((bsRry) => data.elements); + }); + + //get B+R + get(address + 'nwr[amenity=bicycle_parking](around:200);out body center qt;') + .then(data => { + setBpRry((bpRry) => data.elements); + }); + + //get P+R + get(address + 'nwr["park_ride"!="no"]["park_ride"](around:200);out body center qt;') + .then(data => { + setPrRry((prRry => data.elements)); + }); + + //get shop + get(address + 'nwr[shop=ticket]["tickets:public_transport"!=no](around:500);out body center qt;') + .then(data => { + setShopRry((shopRry) => data.elements); + }); + + //get taxi + get(address + 'nwr[amenity=taxi](around:200);out body center qt;') + .then(data => { + setTaxiRry((taxiRry) => data.elements); + }); + + //get vending machine + get(address + 'nwr[amenity=vending_machine][vending=public_transport_tickets](around:40);out body center qt;') + .then(data => { + setVmRry((vmRry) => data.elements); + }); + +}, []); + return ( <> -

Home

- +

Bus Stop

+ +

B+R

+ +

P+R

+ +

Ticket Shop

+ +

Taxi Stop

+ +

Vending Machine

+ ); } diff --git a/app/utils/request.js b/app/utils/request.js new file mode 100644 index 0000000..f76d02c --- /dev/null +++ b/app/utils/request.js @@ -0,0 +1,16 @@ +/** + * http get request + * + * @param pth path + */ +export async function get(pth) { + const data = await fetch(pth, { + method: 'GET', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + } + }); + const jsonData = await data.json(); + return jsonData; +}