diff --git a/frontend/scenes/Dashboard/Dashboard.js b/frontend/scenes/Dashboard/Dashboard.js index afbdc1b01..44a082d32 100644 --- a/frontend/scenes/Dashboard/Dashboard.js +++ b/frontend/scenes/Dashboard/Dashboard.js @@ -1,7 +1,8 @@ import React from 'react'; import { observer } from 'mobx-react'; +import { withRouter } from 'react-router'; -import store from './DashboardStore'; +import DashboardStore from './DashboardStore'; import { Flex } from 'reflexbox'; import Layout from 'components/Layout'; @@ -9,14 +10,21 @@ import AtlasPreview from 'components/AtlasPreview'; import AtlasPreviewLoading from 'components/AtlasPreviewLoading'; import CenteredContent from 'components/CenteredContent'; +@withRouter @observer(['user']) class Dashboard extends React.Component { static propTypes = { user: React.PropTypes.object.isRequired, + router: React.PropTypes.object.isRequired, } - componentDidMount = () => { - store.fetchCollections(this.props.user.team.id); + constructor(props) { + super(props); + + this.store = new DashboardStore({ + team: props.user.team, + router: props.router, + }); } render() { @@ -25,10 +33,10 @@ class Dashboard extends React.Component { - { store.isFetching ? ( + { this.store.isFetching ? ( ) : ( - store.collections && store.collections.map((collection) => { + this.store.collections && this.store.collections.map((collection) => { return (); }) ) } diff --git a/frontend/scenes/Dashboard/Dashboard.scss b/frontend/scenes/Dashboard/Dashboard.scss deleted file mode 100644 index e69de29bb..000000000 diff --git a/frontend/scenes/Dashboard/DashboardStore.js b/frontend/scenes/Dashboard/DashboardStore.js index 98072ad08..ff2da5cf5 100644 --- a/frontend/scenes/Dashboard/DashboardStore.js +++ b/frontend/scenes/Dashboard/DashboardStore.js @@ -1,7 +1,7 @@ import { observable, action, runInAction } from 'mobx'; import { client, cacheResponse } from 'utils/ApiClient'; -const store = new class DashboardStore { +class DashboardStore { @observable collections; @observable pagination; @@ -9,22 +9,33 @@ const store = new class DashboardStore { /* Actions */ - @action fetchCollections = async (teamId) => { + @action fetchCollections = async () => { this.isFetching = true; try { - const res = await client.post('/collections.list', { id: teamId }); + const res = await client.post('/collections.list', { id: this.team.id }); const { data, pagination } = res; runInAction('fetchCollections', () => { this.collections = data; this.pagination = pagination; data.forEach((collection) => cacheResponse(collection.recentDocuments)); }); + + // If only one collection, visit it automatically + if (this.collections.length === 1) { + this.router.push(this.collections[0].url); + } } catch (e) { - console.error("Something went wrong"); + console.error('Something went wrong'); } this.isFetching = false; } -}(); -export default store; + constructor(options) { + this.team = options.team; + this.router = options.router; + this.fetchCollections(); + } +} + +export default DashboardStore; diff --git a/frontend/scenes/DocumentEdit/DocumentEdit.js b/frontend/scenes/DocumentEdit/DocumentEdit.js index 0c742dec8..bdc7ea620 100644 --- a/frontend/scenes/DocumentEdit/DocumentEdit.js +++ b/frontend/scenes/DocumentEdit/DocumentEdit.js @@ -26,8 +26,6 @@ Are you sure you want to disgard them?`; @withRouter @observer class DocumentEdit extends Component { - static store; - static propTypes = { route: React.PropTypes.object.isRequired, router: React.PropTypes.object.isRequired,