From 6425450617b9aef522e3618e6b0d597591bb1ad1 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Sat, 1 Jul 2017 17:02:17 -0700 Subject: [PATCH] Fixes #96 - No longer a delay between clicking on a doc and it becoming active. Note: I removed a bunch of stuff that was observing mobx state change for no reason --- .../SidebarCollection/SidebarCollection.js | 6 ++--- .../components/SidebarLink/SidebarLink.js | 26 +++++++------------ frontend/scenes/Document/Document.js | 7 ++++- 3 files changed, 18 insertions(+), 21 deletions(-) diff --git a/frontend/components/Layout/components/SidebarCollection/SidebarCollection.js b/frontend/components/Layout/components/SidebarCollection/SidebarCollection.js index 828221186..2ca591be2 100644 --- a/frontend/components/Layout/components/SidebarCollection/SidebarCollection.js +++ b/frontend/components/Layout/components/SidebarCollection/SidebarCollection.js @@ -1,6 +1,5 @@ // @flow import React from 'react'; -import { observer } from 'mobx-react'; import { Flex } from 'reflexbox'; import styled from 'styled-components'; @@ -8,6 +7,7 @@ import SidebarLink from '../SidebarLink'; import Collection from 'models/Collection'; import Document from 'models/Document'; +import type { NavigationNode } from 'types'; type Props = { collection: ?Collection, @@ -17,7 +17,7 @@ type Props = { class SidebarCollection extends React.Component { props: Props; - renderDocuments(documentList) { + renderDocuments(documentList: Array) { const { document } = this.props; if (document) { @@ -63,4 +63,4 @@ const Children = styled(Flex)` margin-left: 20px; `; -export default observer(SidebarCollection); +export default SidebarCollection; diff --git a/frontend/components/Layout/components/SidebarLink/SidebarLink.js b/frontend/components/Layout/components/SidebarLink/SidebarLink.js index df60708c4..eed38e036 100644 --- a/frontend/components/Layout/components/SidebarLink/SidebarLink.js +++ b/frontend/components/Layout/components/SidebarLink/SidebarLink.js @@ -1,7 +1,6 @@ // @flow import React from 'react'; -import { observer } from 'mobx-react'; -import { NavLink, withRouter } from 'react-router-dom'; +import { NavLink } from 'react-router-dom'; import { Flex } from 'reflexbox'; import styled from 'styled-components'; @@ -9,27 +8,20 @@ const activeStyle = { color: '#000000', }; -@observer class SidebarLink extends React.Component { - shouldComponentUpdate(nextProps) { - // Navlink is having issues updating, forcing update on URL changes - return this.props.match !== nextProps.match; - } - - render() { - return ( - - - - ); - } +function SidebarLink(props: Object) { + return ( + + + + ); } const LinkContainer = styled(Flex)` padding: 5px 0; - + a { color: #848484; } `; -export default withRouter(SidebarLink); +export default SidebarLink; diff --git a/frontend/scenes/Document/Document.js b/frontend/scenes/Document/Document.js index edcf7c251..275ba0429 100644 --- a/frontend/scenes/Document/Document.js +++ b/frontend/scenes/Document/Document.js @@ -54,8 +54,13 @@ type Props = { } loadDocument = async props => { + let document = this.document; + if (document) { + this.props.ui.setActiveDocument(document); + } + await this.props.documents.fetch(props.match.params.id); - const document = this.document; + document = this.document; if (document) { this.props.ui.setActiveDocument(document);