From 7653a90ff906306b30d43261b6bb9b7914b2f184 Mon Sep 17 00:00:00 2001 From: mitchelljfs Date: Fri, 27 Jul 2018 02:39:38 -0700 Subject: [PATCH] Redesigned routing configuration; modified navbar to create buttons according to routes --- src/components/Navbar/index.js | 64 +++++++++++++--------------------- src/routes/index.js | 37 ++++++++++++-------- src/routes/routes.js | 41 ++++++++++++++++++++++ 3 files changed, 88 insertions(+), 54 deletions(-) create mode 100644 src/routes/routes.js diff --git a/src/components/Navbar/index.js b/src/components/Navbar/index.js index a75659e..ba1020d 100644 --- a/src/components/Navbar/index.js +++ b/src/components/Navbar/index.js @@ -1,10 +1,11 @@ // @flow -import React from "react" +import * as React from "react" import { NavLink } from "react-router-dom" import FontAwesomeIcon from "@fortawesome/react-fontawesome" import faBars from "@fortawesome/fontawesome-free-solid/faBars" import "./index.css" +import { routes } from "../../routes/routes.js" const changeMenu = 800 @@ -15,6 +16,8 @@ type State = { } class Navbar extends React.Component { + buttons: Array> + constructor(props: Props) { super(props) @@ -23,25 +26,40 @@ class Navbar extends React.Component { } else { this.state = { showMenu: true } } + + this.buttons = routes.map(route => ( + + {route.name} + + )) } + isMobile = () => window.innerWidth <= changeMenu + closeMenu = () => { window.scrollTo(0, 0) - if (window.innerWidth <= changeMenu) { + if (this.isMobile()) { this.setState({ showMenu: false }) } } toggleMenu = () => { - if (window.innerWidth <= changeMenu || !this.state.showMenu) { + if (this.isMobile() || !this.state.showMenu) { this.setState(prev => ({ showMenu: !prev.showMenu })) } } render() { - let menuButton = null + let menuButton: ?React.Element - if (window.innerWidth <= changeMenu) { + if (this.isMobile()) { menuButton = (
{
{menuButton} {this.state.showMenu ? ( -
- - Home - - - Projects - - - Experience - - - Contact - -
+
{this.buttons}
) : null}
) diff --git a/src/routes/index.js b/src/routes/index.js index 0283bb1..2d6caa8 100644 --- a/src/routes/index.js +++ b/src/routes/index.js @@ -2,27 +2,36 @@ import React from "react" import { Route, Switch } from "react-router-dom" -import Home from "../containers/Home" -import Projects from "../containers/Projects" -import Experience from "../containers/Experience" -import Contact from "../containers/Contact" +import { routes, redirects } from "./routes.js" type Props = {} class Routes extends React.Component { + routes: Array + redirects: Array + + constructor(props: Props) { + super(props) + + this.routes = routes.map(route => ( + + )) + + this.redirects = redirects.map(route => ( + + )) + } + render() { return ( - - - - - - (window.location = "https://linkedin.com/in/mitchelljfsimon") - } - /> + {this.routes} + {this.redirects} ) } diff --git a/src/routes/routes.js b/src/routes/routes.js new file mode 100644 index 0000000..559b5dd --- /dev/null +++ b/src/routes/routes.js @@ -0,0 +1,41 @@ +// @flow +import Home from "../containers/Home" +import Projects from "../containers/Projects" +import Experience from "../containers/Experience" +import Contact from "../containers/Contact" + +const routes = [ + { + path: "/", + name: "Home", + component: Home, + exact: true + }, + { + path: "/projects", + name: "Projects", + component: Projects, + exact: false + }, + { + path: "/experience", + name: "Experience", + component: Experience, + exact: false + }, + { + path: "/contact", + name: "Contact", + component: Contact, + exact: false + } +] + +const redirects = [ + { + path: "/linkedin", + func: () => (window.location = "https://linkedin.com/in/mitchelljfsimon") + } +] + +export { routes, redirects }