From 031363c927cb2fa28832aea7bf71585e4aab811e Mon Sep 17 00:00:00 2001
From: Yannis Barlas <yannisbarlas@gmail.com>
Date: Fri, 20 Apr 2018 20:00:55 +0300
Subject: [PATCH] feat(app) add navigation links from summary to manuscript and
 back

---
 app/components/App.js | 69 +++++++++++++++++++++++++++++++++++++++++++
 app/routes.js         |  3 +-
 2 files changed, 71 insertions(+), 1 deletion(-)
 create mode 100644 app/components/App.js

diff --git a/app/components/App.js b/app/components/App.js
new file mode 100644
index 0000000000..beb65b85f0
--- /dev/null
+++ b/app/components/App.js
@@ -0,0 +1,69 @@
+import React from 'react'
+import { compose } from 'recompose'
+import { connect } from 'react-redux'
+import { withRouter, matchPath } from 'react-router-dom'
+// import PropTypes from 'prop-types'
+
+import { AppBar, Link } from '@pubsweet/ui'
+import { withJournal } from 'xpub-journal'
+import actions from 'pubsweet-client/src/actions'
+
+const getParams = routerPath => {
+  const path = '/projects/:project/versions/:version'
+  return matchPath(routerPath, path).params
+}
+
+const App = ({
+  children,
+  currentUser,
+  journal,
+  logoutUser,
+  history,
+  match,
+}) => {
+  const { pathname } = history.location
+  const showLinks = pathname.match(/submit|manuscript/g)
+  let links
+
+  if (showLinks) {
+    const params = getParams(pathname)
+    const baseLink = `/projects/${params.project}/versions/${params.version}`
+    const submitLink = `${baseLink}/submit`
+    const manuscriptLink = `${baseLink}/manuscript`
+
+    links = showLinks
+      ? [
+          <Link key="submission" to={submitLink}>
+            Summary Info
+          </Link>,
+          <Link key="manuscript" to={manuscriptLink}>
+            Manuscript
+          </Link>,
+        ]
+      : null
+  }
+
+  return (
+    <div>
+      <AppBar
+        brand={journal.metadata.name}
+        navLinkComponents={links}
+        onLogoutClick={logoutUser}
+        user={currentUser}
+      />
+
+      <div>{children}</div>
+    </div>
+  )
+}
+
+export default compose(
+  connect(
+    state => ({
+      currentUser: state.currentUser.user,
+    }),
+    { logoutUser: actions.logoutUser },
+  ),
+  withJournal,
+  withRouter,
+)(App)
diff --git a/app/routes.js b/app/routes.js
index ff93475936..4aa21a310c 100644
--- a/app/routes.js
+++ b/app/routes.js
@@ -3,7 +3,6 @@ import { withProps } from 'recompose'
 import { Route, Switch } from 'react-router-dom'
 import { AuthenticatedComponent } from 'pubsweet-client'
 
-import App from 'pubsweet-component-xpub-app/src/components'
 import Login from 'pubsweet-component-login/LoginContainer'
 import Signup from 'pubsweet-component-signup/SignupContainer'
 
@@ -20,6 +19,8 @@ import ReviewersPage from 'pubsweet-component-xpub-review/src/components/Reviewe
 import ReviewPage from 'pubsweet-component-xpub-review/src/components/ReviewPage'
 import DecisionPage from 'pubsweet-component-xpub-review/src/components/DecisionPage'
 
+import App from './components/App'
+
 const LoginPage = withProps({ passwordReset: false })(Login)
 
 const PrivateRoute = ({ component: Component, ...rest }) => (
-- 
GitLab