Tidy, tidy

This commit is contained in:
Tom Moor
2018-08-10 00:11:58 -07:00
parent 2f681b1ce8
commit 266b4d735c
4 changed files with 36 additions and 43 deletions

View File

@ -31,10 +31,11 @@ function PublishingInfo({ collection, document }: Props) {
publishedAt,
isDraft,
} = document;
const neverUpdated = publishedAt === updatedAt;
return (
<Container align="center">
{publishedAt && publishedAt === updatedAt ? (
{publishedAt && neverUpdated ? (
<span>
{updatedBy.name} published <Time dateTime={publishedAt} /> ago
</span>

View File

@ -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<Props> {
}
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 (
<Route path={path}>
{this.isLoaded || documents.length ? (
<DocumentList documents={documents} showCollection />
) : (
<ListPlaceholder count={5} />
)}
</Route>
);
};
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 (
<CenteredContent>
@ -55,41 +65,23 @@ class Dashboard extends React.Component<Props> {
<h1>Home</h1>
<Tabs>
<Tab to="/dashboard" exact>
Recently edited
Recently updated
</Tab>
<Tab to="/dashboard/recent" exact>
Recently viewed
</Tab>
<Tab to="/dashboard/owned">Created by me</Tab>
<Tab to="/dashboard/created">Created by me</Tab>
</Tabs>
{showContent ? (
<React.Fragment>
<Switch>
<Route path="/dashboard/recent">
<DocumentList
documents={documents.recentlyViewed}
showCollection
/>
</Route>
<Route path="/dashboard/owned">
<DocumentList documents={owned} showCollection />
</Route>
<Route path="/dashboard">
<DocumentList
documents={documents.recentlyEdited}
showCollection
/>
</Route>
</Switch>
<Actions align="center" justify="flex-end">
<Action>
<NewDocumentMenu label={<NewDocumentIcon />} />
</Action>
</Actions>
</React.Fragment>
) : (
<ListPlaceholder count={5} />
)}
<Switch>
{this.renderTab('/dashboard/recent', documents.recentlyViewed)}
{this.renderTab('/dashboard/created', createdDocuments)}
{this.renderTab('/dashboard', documents.recentlyEdited)}
</Switch>
<Actions align="center" justify="flex-end">
<Action>
<NewDocumentMenu label={<NewDocumentIcon />} />
</Action>
</Actions>
</CenteredContent>
);
}

View File

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

View File

@ -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]],