Skip to content

Commit

Permalink
Add proxy for BE / call for sheet and group
Browse files Browse the repository at this point in the history
  • Loading branch information
MichalObi committed Feb 7, 2021
1 parent 7e1eca6 commit 6441ed5
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 19 deletions.
3 changes: 2 additions & 1 deletion FE/simple-sheet-fe/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,6 @@
"last 1 firefox version",
"last 1 safari version"
]
}
},
"proxy": "http://localhost:8080"
}
58 changes: 40 additions & 18 deletions FE/simple-sheet-fe/src/App.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,47 @@
import React, {useState, useEffect} from 'react';
import logo from './logo.svg';
import './App.css';

function App() {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
</div>
);
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 <p>error</p>;
} else if (!isLoaded) {
return <p>loading</p>;
} else {
return (
<div className="App">
<header className="App-header">
Simple Sheet
</header>
</div>
);
}
}

export default App;

0 comments on commit 6441ed5

Please sign in to comment.