Skip to content

Commit

Permalink
Fix BE bug / add react routing
Browse files Browse the repository at this point in the history
  • Loading branch information
MichalObi committed Feb 14, 2021
1 parent 2c7c821 commit c2be024
Show file tree
Hide file tree
Showing 9 changed files with 180 additions and 24 deletions.
2 changes: 1 addition & 1 deletion BE/cmd/api/models/sheet.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type Fields struct {
Value string `json:"value"`
}

type FieldsSlice []Position
type FieldsSlice []Fields

type Sheet struct {
ID int `json:"id"`
Expand Down
2 changes: 2 additions & 0 deletions BE/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ go 1.13

require (
github.com/apache/thrift v0.12.0 // indirect
github.com/fatih/color v1.10.0 // indirect
github.com/githubnemo/CompileDaemon v1.2.1 // indirect
github.com/golang-migrate/migrate/v4 v4.14.1
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/joho/godotenv v1.3.0
Expand Down
11 changes: 11 additions & 0 deletions BE/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,13 @@ github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymF
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/fatih/color v1.10.0 h1:s36xzo75JdqLaaWoiEHk767eHiwo0598uUxyfiPkDsg=
github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM=
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsouza/fake-gcs-server v1.17.0/go.mod h1:D1rTE4YCyHFNa99oyJJ5HyclvN/0uQR+pM/VdlL83bw=
github.com/githubnemo/CompileDaemon v1.2.1 h1:yEJ28U3sIsuhCtpqN2Pb5XL8G+hpg7KUNfTGvL7GxL0=
github.com/githubnemo/CompileDaemon v1.2.1/go.mod h1:lE3EXX1td33uhlkFLp+ImWY9qBaoRcDeA3neh4m8ic0=
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
Expand Down Expand Up @@ -259,9 +264,13 @@ github.com/lib/pq v1.8.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/markbates/pkger v0.15.1/go.mod h1:0JoVlrol20BSywW79rN3kdFFsE5xYM+rSCQDXbLhiuI=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ=
github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8=
github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-sqlite3 v1.9.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
github.com/mattn/go-sqlite3 v1.10.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
Expand Down Expand Up @@ -471,6 +480,7 @@ golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200113162924-86b910548bc1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200124204421-9fbb57f87de9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand All @@ -487,6 +497,7 @@ golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200826173525-f9321e4c35a6/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201029080932-201ba4db2418 h1:HlFl4V6pEMziuLXyRkm5BIYq1y1GAbb02pRlWvI54OM=
golang.org/x/sys v0.0.0-20201029080932-201ba4db2418/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down
96 changes: 96 additions & 0 deletions FE/simple-sheet-fe/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions FE/simple-sheet-fe/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"@testing-library/user-event": "^12.6.3",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-router-dom": "^5.2.0",
"react-scripts": "4.0.2",
"web-vitals": "^1.1.0"
},
Expand Down
77 changes: 54 additions & 23 deletions FE/simple-sheet-fe/src/App.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import React, {useState, useEffect} from 'react';
import logo from './logo.svg';
import './App.css';
import {
BrowserRouter as Router,
Switch,
Route,
Link
} from "react-router-dom";

import CreateSheet from './components/CreateSheet';
import ExploreSheets from './components/ExploreSheets';
import Home from './components/Home';

function App() {
const useStateCallbackWrapper = (initilValue, callBack) => {
Expand All @@ -14,42 +24,63 @@ function App() {

const [error, setError] = useStateCallbackWrapper(null, state => log('error', state)),
[isLoaded, setIsLoaded] = useStateCallbackWrapper(false, state => log('isLoaded', state)),
[sheetsAndGroups, setSheetsAndGroups] = useStateCallbackWrapper({}, state => log('sheetsAndGroups', state));
[sheets, setSheets] = useStateCallbackWrapper({}, state => log('sheets', state));

const handleAjaxError = error => {
setIsLoaded(true);
setError(error);
};

useEffect(() => {
fetch('/sheets/1')
.then(sheets => sheets.json())
.then(sheets => {
if (sheets) {
fetch(`/groups/${sheets.id}`)
.then(groups => groups.json())
.then(groups => {
const sheetsAndGroups = Object.assign({}, sheets, groups);
delete sheetsAndGroups.id;

setSheetsAndGroups(sheetsAndGroups);
setIsLoaded(true);
}, handleAjaxError)
}
}, handleAjaxError)
}, []);
// useEffect(() => {
// fetch('/sheets/')
// .then(sheets => sheets.json())
// .then(sheets => {
// setSheets(sheets);
// setIsLoaded(true);
// }, handleAjaxError)
// }, []);

useEffect(() => {
setIsLoaded(true);
}, []);

if (error) {
return <p>error</p>;
} else if (!isLoaded) {
return <p>loading</p>;
} else {
return (
<div className="App">
<header className="App-header">
Simple Sheet id {sheetsAndGroups.sheet_id}
</header>
</div>
<Router>
<div className="App">
<header className="App-header">
<nav>
<ul>
<li>
<Link to="/">Home</Link>
</li>
<li>
<Link to="/create">Create new</Link>
</li>
<li>
<Link to="/explore">Explore sheets</Link>
</li>
</ul>
</nav>
</header>
</div>

<Switch>
<Route path="/create">
<CreateSheet />
</Route>
<Route path="/explore">
<ExploreSheets />
</Route>
<Route path="/">
<Home />
</Route>
</Switch>
</Router>
);
}
}
Expand Down
5 changes: 5 additions & 0 deletions FE/simple-sheet-fe/src/components/CreateSheet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function CreateSheet() {
return <h2>Create Sheet</h2>;
}

export default CreateSheet;
5 changes: 5 additions & 0 deletions FE/simple-sheet-fe/src/components/ExploreSheets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function ExploreSheets() {
return <h2>Explore sheets</h2>;
}

export default ExploreSheets;
5 changes: 5 additions & 0 deletions FE/simple-sheet-fe/src/components/Home.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function Home() {
return <h2>Simple Sheets App</h2>;
}

export default Home;

0 comments on commit c2be024

Please sign in to comment.