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
This commit is contained in:
Tom Moor
2017-07-01 17:02:17 -07:00
parent 603d5f2b6b
commit 6425450617
3 changed files with 18 additions and 21 deletions

View File

@@ -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<NavigationNode>) {
const { document } = this.props;
if (document) {
@@ -63,4 +63,4 @@ const Children = styled(Flex)`
margin-left: 20px;
`;
export default observer(SidebarCollection);
export default SidebarCollection;

View File

@@ -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 (
<LinkContainer>
<NavLink exact {...this.props} activeStyle={activeStyle} />
</LinkContainer>
);
}
function SidebarLink(props: Object) {
return (
<LinkContainer>
<NavLink exact {...props} activeStyle={activeStyle} />
</LinkContainer>
);
}
const LinkContainer = styled(Flex)`
padding: 5px 0;
a {
color: #848484;
}
`;
export default withRouter(SidebarLink);
export default SidebarLink;

View File

@@ -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);