Merge pull request #379 from jorilallo/collection-selection
Fixes: Collection selection state
This commit is contained in:
@@ -3,7 +3,7 @@ import React, { Component } from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import { observable, action } from 'mobx';
|
||||
import { observer, inject } from 'mobx-react';
|
||||
import { withRouter } from 'react-router';
|
||||
import { withRouter } from 'react-router-dom';
|
||||
import styled from 'styled-components';
|
||||
import ArrowKeyNavigation from 'boundless-arrow-key-navigation';
|
||||
import ToolbarButton from './ToolbarButton';
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// @flow
|
||||
import React from 'react';
|
||||
import { withRouter } from 'react-router-dom';
|
||||
import type { Location } from 'react-router-dom';
|
||||
import { Helmet } from 'react-helmet';
|
||||
import styled from 'styled-components';
|
||||
import { observer, inject } from 'mobx-react';
|
||||
@@ -30,6 +31,7 @@ import DocumentsStore from 'stores/DocumentsStore';
|
||||
|
||||
type Props = {
|
||||
history: Object,
|
||||
location: Location,
|
||||
collections: CollectionsStore,
|
||||
documents: DocumentsStore,
|
||||
children?: ?React.Element<any>,
|
||||
@@ -139,6 +141,7 @@ type Props = {
|
||||
<LinkSection>
|
||||
<SidebarCollections
|
||||
history={this.props.history}
|
||||
location={this.props.location}
|
||||
activeDocument={documents.active}
|
||||
onCreateCollection={this.handleCreateCollection}
|
||||
activeDocumentRef={this.scrollToActiveDocument}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
// @flow
|
||||
import React from 'react';
|
||||
import React, { Component } from 'react';
|
||||
import { observable } from 'mobx';
|
||||
import { observer, inject } from 'mobx-react';
|
||||
import type { Location } from 'react-router-dom';
|
||||
import Flex from 'shared/components/Flex';
|
||||
import styled from 'styled-components';
|
||||
import { color, fontWeight } from 'shared/styles/constants';
|
||||
@@ -20,6 +21,7 @@ import { type NavigationNode } from 'types';
|
||||
|
||||
type Props = {
|
||||
history: Object,
|
||||
location: Location,
|
||||
collections: CollectionsStore,
|
||||
documents: DocumentsStore,
|
||||
activeDocument: ?Document,
|
||||
@@ -28,7 +30,7 @@ type Props = {
|
||||
ui: UiStore,
|
||||
};
|
||||
|
||||
@observer class SidebarCollections extends React.PureComponent {
|
||||
@observer class SidebarCollections extends Component {
|
||||
props: Props;
|
||||
|
||||
render() {
|
||||
@@ -68,7 +70,7 @@ type Props = {
|
||||
}
|
||||
}
|
||||
|
||||
@observer class CollectionLink extends React.Component {
|
||||
@observer class CollectionLink extends Component {
|
||||
dropzoneRef;
|
||||
|
||||
@observable menuOpen = false;
|
||||
|
||||
@@ -13,9 +13,6 @@ const activeStyle = {
|
||||
fontWeight: fontWeight.semiBold,
|
||||
};
|
||||
|
||||
// This is a hack for `styleComponent()` as NavLink fails to render without `to` prop
|
||||
const StyleableDiv = props => <div {...props} />;
|
||||
|
||||
const StyledGoTo = styled(CollapsedIcon)`
|
||||
margin-bottom: -4px;
|
||||
margin-right: 0;
|
||||
@@ -28,7 +25,7 @@ const IconWrapper = styled.span`
|
||||
height: 24px;
|
||||
`;
|
||||
|
||||
const styleComponent = component => styled(component)`
|
||||
const StyledNavLink = styled(NavLink)`
|
||||
display: flex;
|
||||
width: 100%;
|
||||
position: relative;
|
||||
@@ -51,6 +48,8 @@ const styleComponent = component => styled(component)`
|
||||
}
|
||||
`;
|
||||
|
||||
const StyledDiv = StyledNavLink.withComponent('div');
|
||||
|
||||
type Props = {
|
||||
to?: string,
|
||||
onClick?: SyntheticEvent => *,
|
||||
@@ -62,6 +61,7 @@ type Props = {
|
||||
|
||||
@observer class SidebarLink extends Component {
|
||||
props: Props;
|
||||
@observable expanded: boolean = false;
|
||||
|
||||
componentDidMount() {
|
||||
if (this.props.expand) this.handleExpand();
|
||||
@@ -71,8 +71,6 @@ type Props = {
|
||||
if (nextProps.expand) this.handleExpand();
|
||||
}
|
||||
|
||||
@observable expanded: boolean = false;
|
||||
|
||||
@action handleClick = (event: SyntheticEvent) => {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
@@ -85,7 +83,7 @@ type Props = {
|
||||
|
||||
render() {
|
||||
const { icon, children, expandedContent, ...rest } = this.props;
|
||||
const Component = styleComponent(rest.to ? NavLink : StyleableDiv);
|
||||
const Component = rest.to ? StyledNavLink : StyledDiv;
|
||||
|
||||
return (
|
||||
<Flex column>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// @flow
|
||||
// based on: https://reacttraining.com/react-router/web/guides/scroll-restoration
|
||||
import { Component } from 'react';
|
||||
import { withRouter } from 'react-router';
|
||||
import { withRouter } from 'react-router-dom';
|
||||
|
||||
class ScrollToTop extends Component {
|
||||
componentDidUpdate(prevProps) {
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
// @flow
|
||||
import React from 'react';
|
||||
import React, { Component } from 'react';
|
||||
import { observable } from 'mobx';
|
||||
import { observer, inject } from 'mobx-react';
|
||||
import { Redirect } from 'react-router';
|
||||
import { Link } from 'react-router-dom';
|
||||
import _ from 'lodash';
|
||||
import { Link, Redirect } from 'react-router-dom';
|
||||
import styled from 'styled-components';
|
||||
import { newDocumentUrl } from 'utils/routeHelpers';
|
||||
|
||||
@@ -14,17 +12,17 @@ import Collection from 'models/Collection';
|
||||
import CenteredContent from 'components/CenteredContent';
|
||||
import LoadingListPlaceholder from 'components/LoadingListPlaceholder';
|
||||
import Button from 'components/Button';
|
||||
import Flex from 'shared/components/Flex';
|
||||
import HelpText from 'components/HelpText';
|
||||
import Flex from 'shared/components/Flex';
|
||||
|
||||
type Props = {
|
||||
collections: CollectionsStore,
|
||||
match: Object,
|
||||
};
|
||||
|
||||
@observer class CollectionScene extends React.Component {
|
||||
@observer class CollectionScene extends Component {
|
||||
props: Props;
|
||||
collection: ?Collection;
|
||||
@observable collection: ?Collection;
|
||||
@observable isFetching = true;
|
||||
@observable redirectUrl;
|
||||
|
||||
@@ -41,7 +39,7 @@ type Props = {
|
||||
fetchDocument = async (id: string) => {
|
||||
const { collections } = this.props;
|
||||
|
||||
this.collection = await collections.getById(id);
|
||||
this.collection = await collections.fetchById(id);
|
||||
|
||||
if (!this.collection) this.redirectUrl = '/404';
|
||||
|
||||
@@ -51,41 +49,48 @@ type Props = {
|
||||
this.isFetching = false;
|
||||
};
|
||||
|
||||
renderNewDocument() {
|
||||
renderEmptyCollection() {
|
||||
if (!this.collection) return;
|
||||
|
||||
return (
|
||||
<NewDocumentContainer auto column justify="center">
|
||||
<h1>Create a document</h1>
|
||||
<HelpText>
|
||||
Publish your first document to start building your collection.
|
||||
Publish your first document to start building the
|
||||
{' '}
|
||||
<strong>{this.collection.name}</strong>
|
||||
{' '}
|
||||
collection.
|
||||
</HelpText>
|
||||
{this.collection &&
|
||||
<Action>
|
||||
<Link to={newDocumentUrl(this.collection)}>
|
||||
<Button>Create new document</Button>
|
||||
</Link>
|
||||
</Action>}
|
||||
<Action>
|
||||
<Link to={newDocumentUrl(this.collection)}>
|
||||
<Button>Create new document</Button>
|
||||
</Link>
|
||||
</Action>
|
||||
</NewDocumentContainer>
|
||||
);
|
||||
}
|
||||
|
||||
render() {
|
||||
if (this.redirectUrl) return <Redirect to={this.redirectUrl} />;
|
||||
|
||||
return (
|
||||
<CenteredContent>
|
||||
{this.redirectUrl && <Redirect to={this.redirectUrl} />}
|
||||
{this.isFetching
|
||||
? <LoadingListPlaceholder />
|
||||
: this.renderNewDocument()}
|
||||
: this.renderEmptyCollection()}
|
||||
</CenteredContent>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const NewDocumentContainer = styled(Flex)`
|
||||
padding-top: 70px;
|
||||
padding-top: 50%;
|
||||
transform: translateY(-50%);
|
||||
`;
|
||||
|
||||
const Action = styled(Flex)`
|
||||
margin: 20px 0;
|
||||
margin: 10px 0;
|
||||
`;
|
||||
|
||||
export default inject('collections')(CollectionScene);
|
||||
|
||||
@@ -4,7 +4,8 @@ import get from 'lodash/get';
|
||||
import styled from 'styled-components';
|
||||
import { observable } from 'mobx';
|
||||
import { observer, inject } from 'mobx-react';
|
||||
import { withRouter, Prompt } from 'react-router';
|
||||
import { withRouter, Prompt } from 'react-router-dom';
|
||||
import type { Location } from 'react-router-dom';
|
||||
import keydown from 'react-keydown';
|
||||
import Flex from 'shared/components/Flex';
|
||||
import { color, layout } from 'shared/styles/constants';
|
||||
@@ -42,7 +43,7 @@ Are you sure you want to discard them?
|
||||
type Props = {
|
||||
match: Object,
|
||||
history: Object,
|
||||
location: Object,
|
||||
location: Location,
|
||||
keydown: Object,
|
||||
documents: DocumentsStore,
|
||||
collections: CollectionsStore,
|
||||
|
||||
@@ -3,7 +3,7 @@ import React, { Component } from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import { observable, computed } from 'mobx';
|
||||
import { observer, inject } from 'mobx-react';
|
||||
import { withRouter } from 'react-router';
|
||||
import { withRouter } from 'react-router-dom';
|
||||
import { Search } from 'js-search';
|
||||
import ArrowKeyNavigation from 'boundless-arrow-key-navigation';
|
||||
import _ from 'lodash';
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// @flow
|
||||
import React from 'react';
|
||||
import { observer, inject } from 'mobx-react';
|
||||
import { Redirect } from 'react-router';
|
||||
import { Redirect } from 'react-router-dom';
|
||||
import AuthStore from 'stores/AuthStore';
|
||||
|
||||
type Props = {
|
||||
|
||||
@@ -7,7 +7,7 @@ import { observer, inject } from 'mobx-react';
|
||||
import _ from 'lodash';
|
||||
import DocumentsStore from 'stores/DocumentsStore';
|
||||
|
||||
import { withRouter } from 'react-router';
|
||||
import { withRouter } from 'react-router-dom';
|
||||
import { searchUrl } from 'utils/routeHelpers';
|
||||
import styled from 'styled-components';
|
||||
import ArrowKeyNavigation from 'boundless-arrow-key-navigation';
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// @flow
|
||||
import React from 'react';
|
||||
import { Redirect } from 'react-router';
|
||||
import { Redirect } from 'react-router-dom';
|
||||
import type { Location } from 'react-router-dom';
|
||||
import queryString from 'query-string';
|
||||
import { observable } from 'mobx';
|
||||
import { observer, inject } from 'mobx-react';
|
||||
@@ -11,7 +12,7 @@ import AuthStore from 'stores/AuthStore';
|
||||
|
||||
type Props = {
|
||||
auth: AuthStore,
|
||||
location: Object,
|
||||
location: Location,
|
||||
};
|
||||
|
||||
@observer class SlackAuth extends React.Component {
|
||||
|
||||
Reference in New Issue
Block a user