From 6441ed55b5c2303f7801122112642757d5bec324 Mon Sep 17 00:00:00 2001 From: MichalObi Date: Sun, 7 Feb 2021 21:06:06 +0100 Subject: [PATCH] Add proxy for BE / call for sheet and group --- FE/simple-sheet-fe/package.json | 3 +- FE/simple-sheet-fe/src/App.js | 58 +++++++++++++++++++++++---------- 2 files changed, 42 insertions(+), 19 deletions(-) diff --git a/FE/simple-sheet-fe/package.json b/FE/simple-sheet-fe/package.json index 1f06230..7cb70f0 100644 --- a/FE/simple-sheet-fe/package.json +++ b/FE/simple-sheet-fe/package.json @@ -34,5 +34,6 @@ "last 1 firefox version", "last 1 safari version" ] - } + }, + "proxy": "http://localhost:8080" } diff --git a/FE/simple-sheet-fe/src/App.js b/FE/simple-sheet-fe/src/App.js index 3784575..bb25434 100644 --- a/FE/simple-sheet-fe/src/App.js +++ b/FE/simple-sheet-fe/src/App.js @@ -1,25 +1,47 @@ +import React, {useState, useEffect} from 'react'; import logo from './logo.svg'; import './App.css'; function App() { - return ( -
-
- logo -

- Edit src/App.js and save to reload. -

- - Learn React - -
-
- ); + const [error, setError] = useState(null), + [isLoaded, setIsLoaded] = useState(false), + [items, setItems] = useState([]), + handleAjaxError = error => { + setIsLoaded(true); + setError(error); + + console.log('err', error); + }; + + useEffect(() => { + fetch('/sheets/1') + .then(res => res.json()) + .then( + res => { + console.log('sheets', res); + + fetch(`/groups/${res.id}`) + .then(res => res.json()) + .then(res => { + setIsLoaded(true); + console.log('groups', res); + }, handleAjaxError) + }, handleAjaxError) + }, []); + + if (error) { + return

error

; + } else if (!isLoaded) { + return

loading

; + } else { + return ( +
+
+ Simple Sheet +
+
+ ); + } } export default App;