diff --git a/app/components/DocumentPreview/components/PublishingInfo.js b/app/components/DocumentPreview/components/PublishingInfo.js index 11f2254a..1adfcb46 100644 --- a/app/components/DocumentPreview/components/PublishingInfo.js +++ b/app/components/DocumentPreview/components/PublishingInfo.js @@ -31,10 +31,11 @@ function PublishingInfo({ collection, document }: Props) { publishedAt, isDraft, } = document; + const neverUpdated = publishedAt === updatedAt; return ( - {publishedAt && publishedAt === updatedAt ? ( + {publishedAt && neverUpdated ? ( {updatedBy.name} published diff --git a/app/scenes/Dashboard.js b/app/scenes/Dashboard.js index d5ca3ddf..0c6f67f6 100644 --- a/app/scenes/Dashboard.js +++ b/app/scenes/Dashboard.js @@ -12,7 +12,6 @@ import Actions, { Action } from 'components/Actions'; import CenteredContent from 'components/CenteredContent'; import DocumentList from 'components/DocumentList'; import PageTitle from 'components/PageTitle'; -import Subheading from 'components/Subheading'; import Tabs from 'components/Tabs'; import Tab from 'components/Tab'; import { ListPlaceholder } from 'components/LoadingPlaceholder'; @@ -31,23 +30,34 @@ class Dashboard extends React.Component { } loadContent = async () => { + const { auth } = this.props; + const user = auth.user ? auth.user.id : undefined; + await Promise.all([ this.props.documents.fetchRecentlyModified({ limit: 15 }), this.props.documents.fetchRecentlyViewed({ limit: 15 }), + this.props.documents.fetchOwned({ limit: 15, user }), ]); this.isLoaded = true; }; + renderTab = (path, documents) => { + return ( + + {this.isLoaded || documents.length ? ( + + ) : ( + + )} + + ); + }; + render() { const { documents, auth } = this.props; if (!auth.user) return; - const hasRecentlyViewed = documents.recentlyViewed.length > 0; - const hasRecentlyEdited = documents.recentlyEdited.length > 0; - - const owned = documents.owned(auth.user.id); - const showContent = - this.isLoaded || (hasRecentlyViewed && hasRecentlyEdited); + const createdDocuments = documents.owned(auth.user.id); return ( @@ -55,41 +65,23 @@ class Dashboard extends React.Component {

Home

- Recently edited + Recently updated Recently viewed - Created by me + Created by me - {showContent ? ( - - - - - - - - - - - - - - - } /> - - - - ) : ( - - )} + + {this.renderTab('/dashboard/recent', documents.recentlyViewed)} + {this.renderTab('/dashboard/created', createdDocuments)} + {this.renderTab('/dashboard', documents.recentlyEdited)} + + + + } /> + +
); } diff --git a/app/stores/DocumentsStore.js b/app/stores/DocumentsStore.js index dea90d0e..79c1e3b9 100644 --- a/app/stores/DocumentsStore.js +++ b/app/stores/DocumentsStore.js @@ -163,7 +163,7 @@ class DocumentsStore extends BaseStore { @action fetchOwned = async (options: ?PaginationParams): Promise<*> => { - await this.fetchPage('owned', options); + await this.fetchPage('list', options); }; @action diff --git a/server/api/documents.js b/server/api/documents.js index 5c3f5513..f582275b 100644 --- a/server/api/documents.js +++ b/server/api/documents.js @@ -14,14 +14,14 @@ const { authorize, cannot } = policy; const router = new Router(); router.post('documents.list', auth(), pagination(), async ctx => { - let { sort = 'updatedAt', direction, collection } = ctx.body; + let { sort = 'updatedAt', direction, collection, user } = ctx.body; if (direction !== 'ASC') direction = 'DESC'; - const user = ctx.state.user; - let where = { teamId: user.teamId }; + let where = { teamId: ctx.state.user.teamId }; if (collection) where = { ...where, collectionId: collection }; + if (user) where = { ...where, userId: collection }; - const starredScope = { method: ['withStarred', user.id] }; + const starredScope = { method: ['withStarred', ctx.state.user.id] }; const documents = await Document.scope('defaultScope', starredScope).findAll({ where, order: [[sort, direction]],