Skip to content

Commit

Permalink
Fixed manual routing.
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkusPaulsen committed Dec 29, 2019
1 parent 0df98e3 commit 44e4953
Show file tree
Hide file tree
Showing 7 changed files with 147 additions and 102 deletions.
4 changes: 1 addition & 3 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,12 @@ const path = require("path");

app.use(express.static(path.join(__dirname, "thespoon", "build")));

/*

app.get("*", (req, res) => {
res.sendFile(path.join(__dirname, "thespoon", "build", "index.html"));

});

*/

//END OF THE REQUIRED CODE TO MAKE THE DEPLOY WORK

const port = process.env.PORT || 80;
Expand Down
10 changes: 7 additions & 3 deletions thespoon/src/App.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from "react";
import {BrowserRouter, Switch, Route} from "react-router-dom";
import {BrowserRouter, Switch, Route, Link} from "react-router-dom";
import HomePage from "./components/HomePage/Homepage.js";
import MainPage from "./components/MainPage/YourMainPage.js";
import CustomModal from "./containers/CustomModal";
import Dashboard from "./components/DashboardPage/YourDashboardPage.js";
import YourRestaurantPage from "./components/RestaurantPage/YourRestaurantPage.js";
Expand All @@ -10,17 +9,22 @@ import CustomerMainPage from "./components/MainPage/CustomerMainPage";
//import Navbar from "./components/layout/Navbar.js"

/* the Spoon app browser */
const NoMatch = ({ location }) => {
console.log(location)
return(<h1>Fail</h1>);
};

function App() {
return (
<BrowserRouter>
{<CustomModal />}
<Switch>
<Route exact path="/" component={HomePage} />
<Route exact path="/Mainpage" component={MainPage} />
<Route exact path="/Dashboard" component={Dashboard} />
<Route exact path="/YourRestaurant" component={YourRestaurantPage} />
<Route exact path="/Profile" component={Profile} />
<Route exact path="/CustomerMain" component={CustomerMainPage} />
<Route component={NoMatch}/>
</Switch>
</BrowserRouter>
);
Expand Down
78 changes: 65 additions & 13 deletions thespoon/src/components/DashboardPage/YourDashboardPage.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,83 @@
//<editor-fold desc="React Import">
//<editor-fold desc="React">
import React, {Component} from "react";
import {Link, Redirect} from "react-router-dom"
//</editor-fold>
//<editor-fold desc="Redux import">
//<editor-fold desc="Redux">
import {connect} from "react-redux";
import {setBackgroundPage} from "../../actionCreators/BackgroundPageActionCreator";
//</editor-fold>

//<editor-fold desc="Layout">
import MainLayout from "../layout/MainLayout.js"
import {ajax} from "rxjs/ajax";
import {paths} from "../../constants/paths";
import {timeout} from "../../constants/timeout";
//</editor-fold>

class YourDashboardPage extends Component {
//<editor-fold desc="Constructor">
constructor(props) {
super(props);

this.update = this.update.bind(this);

this.state = {
token: window.localStorage.getItem("token"),
restaurantOwner: window.localStorage.getItem("restaurantOwner"),
toUpdate: false
}
}
//<editor-fold desc="Component Lifecycle">
componentDidMount() {
this.props.setBackgroundPageHere(this);

};

componentWillUnmount() {
this.props.setBackgroundPageHere(null);
}

componentDidUpdate(prevProps, prevState, snapshot) {
if (this.state.toUpdate) {
this.setState({
toUpdate: false
});
this.componentWillUnmount();
this.componentDidMount();
}
}

//</editor-fold>

//<editor-fold desc="Business Logic">
update() {
this.setState({toUpdate: true});
this.forceUpdate()
}

//</editor-fold>
//<editor-fold desc="Render">
render() {
if(typeof this.props.loginStatus != "undefined" && this.props.loginStatus === "logged in"){
if (this.state.token == null
|| this.state.token === "null"
|| this.state.restaurantOwner == null
|| this.state.restaurantOwner === "null") {
return (
<Redirect to={{pathname: "/"}}/>
);
} else if(this.state.restaurantOwner === "false") {
return (
<Redirect to={{pathname: "/CustomerMain"}}/>
);
} else {
return (
<MainLayout >
<div className="mainpage-banner">
<div className="mainpage-text">
<div className="container">
<div className="row">
<div className="col-sm-8">
<h1 className="title">This is your dashboard {this.props.username}</h1>
<h1 className="title">This is your dashboard</h1>
</div>
</div>
</div>
Expand All @@ -30,22 +86,18 @@ class YourDashboardPage extends Component {
</MainLayout>
);
}
else {
return(
<Redirect to={{pathname: "/"}}/>
);
}
}
//</editor-fold>
}

//<editor-fold desc="Redux">
const mapStateToProps = (state) => {
const mapDispatchToProps = (dispatch) => {
return {
username: state.logInReducer.username,
loginStatus: state.logInReducer.loginStatus
setBackgroundPageHere: (backgroundPage) => {
dispatch(setBackgroundPage(backgroundPage));
}
};
};

export default connect(mapStateToProps, null)(YourDashboardPage);
export default connect(null, mapDispatchToProps)(YourDashboardPage);
//</editor-fold>
71 changes: 60 additions & 11 deletions thespoon/src/components/ProfilePage/YourProfilePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,65 @@ import {connect} from "react-redux";
//</editor-fold>
//<editor-fold desc="Layout">
import MainLayout from "../layout/MainLayout.js"
import {setBackgroundPage} from "../../actionCreators/BackgroundPageActionCreator";
//</editor-fold>

class YourProfilePage extends Component {
//<editor-fold desc="Constructor">
constructor(props) {
super(props);

this.update = this.update.bind(this);

this.state = {
token: window.localStorage.getItem("token"),
restaurantOwner: window.localStorage.getItem("restaurantOwner"),
toUpdate: false
}
}
//<editor-fold desc="Component Lifecycle">
componentDidMount() {
this.props.setBackgroundPageHere(this);

};

componentWillUnmount() {
this.props.setBackgroundPageHere(null);
}

componentDidUpdate(prevProps, prevState, snapshot) {
if (this.state.toUpdate) {
this.setState({
toUpdate: false
});
this.componentWillUnmount();
this.componentDidMount();
}
}

//</editor-fold>

//<editor-fold desc="Business Logic">
update() {
this.setState({toUpdate: true});
this.forceUpdate()
}

//</editor-fold>
//<editor-fold desc="Render">
render() {
if(typeof this.props.loginStatus != "undefined" && this.props.loginStatus === "logged in"){
if (this.state.token == null
|| this.state.token === "null"
|| this.state.restaurantOwner == null
|| this.state.restaurantOwner === "null") {
return (
<Redirect to={{pathname: "/"}}/>
);
} else if(this.state.restaurantOwner === "false") {
return (
<Redirect to={{pathname: "/CustomerMain"}}/>
);
} else {
return (
<MainLayout >
<div className="mainpage-banner">
Expand All @@ -29,22 +82,18 @@ class YourProfilePage extends Component {
</MainLayout>
);
}
else {
return(
<Redirect to={{pathname: "/"}}/>
);
}
}
};
//</editor-fold>
}

//<editor-fold desc="Redux">
const mapStateToProps = (state) => {
const mapDispatchToProps = (dispatch) => {
return {
username: state.logInReducer.username,
loginStatus: state.logInReducer.loginStatus
setBackgroundPageHere: (backgroundPage) => {
dispatch(setBackgroundPage(backgroundPage));
}
};
};

export default connect(mapStateToProps, null)(YourProfilePage);
export default connect(null, mapDispatchToProps)(YourProfilePage);
//</editor-fold>
26 changes: 9 additions & 17 deletions thespoon/src/components/homepage/Homepage.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,17 @@ class Homepage extends Component {
//<editor-fold desc="Component Lifecycle">
componentDidMount() {
this.props.setBackgroundPageHere(this);
this.setState({
token: window.localStorage.getItem("token"),
restaurantOwner: window.localStorage.getItem("restaurantOwner"),
toUpdate: false
},
() => {
});
}

componentWillUnmount() {
this.setState({
token: null,
restaurantOwner: null,
toUpdate: false
},
() => {
});
this.props.setBackgroundPageHere(null);
}

componentDidUpdate(prevProps, prevState, snapshot) {
if (this.state.toUpdate) {
this.setState({
toUpdate: false
});
this.componentWillUnmount();
this.componentDidMount();
}
Expand All @@ -77,7 +66,10 @@ class Homepage extends Component {

//<editor-fold desc="Render">
render() {
if (this.state.token == null || this.state.token === "null") {
if (this.state.token == null
|| this.state.token === "null"
|| this.state.restaurantOwner == null
|| this.state.restaurantOwner === "null") {
return (
<Layout>
<div className="homepage-banner">
Expand All @@ -98,11 +90,11 @@ class Homepage extends Component {
);
} else if (this.state.restaurantOwner === "false") {
return (
<Redirect to={{pathname: "/CustomerMain/"}}/>
<Redirect to={{pathname: "/CustomerMain"}}/>
);
} else {
return (
<Redirect to={{pathname: "/YourRestaurant/"}}/>
<Redirect to={{pathname: "/YourRestaurant"}}/>
);
}
}
Expand Down
53 changes: 0 additions & 53 deletions thespoon/src/components/mainPage/YourMainPage.js

This file was deleted.

7 changes: 5 additions & 2 deletions thespoon/src/components/restaurantPage/YourRestaurantPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,16 @@ class YourRestaurantPage extends Component {

//<editor-fold desc="Render">
render() {
if (this.state.token == null || this.state.token === "null") {
if (this.state.token == null
|| this.state.token === "null"
|| this.state.restaurantOwner == null
|| this.state.restaurantOwner === "null") {
return (
<Redirect to={{pathname: "/"}}/>
);
} else if(this.state.restaurantOwner === "false") {
return (
<Redirect to={{pathname: "/CustomerMain/"}}/>
<Redirect to={{pathname: "/CustomerMain"}}/>
);
} else if (this.state.restaurant == null || this.state.menus == null) {
return (
Expand Down

0 comments on commit 44e4953

Please sign in to comment.