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, publishedAt,
isDraft, isDraft,
} = document; } = document;
const neverUpdated = publishedAt === updatedAt;
return ( return (
<Container align="center"> <Container align="center">
{publishedAt && publishedAt === updatedAt ? ( {publishedAt && neverUpdated ? (
<span> <span>
{updatedBy.name} published <Time dateTime={publishedAt} /> ago {updatedBy.name} published <Time dateTime={publishedAt} /> ago
</span> </span>

View File

@ -12,7 +12,6 @@ import Actions, { Action } from 'components/Actions';
import CenteredContent from 'components/CenteredContent'; import CenteredContent from 'components/CenteredContent';
import DocumentList from 'components/DocumentList'; import DocumentList from 'components/DocumentList';
import PageTitle from 'components/PageTitle'; import PageTitle from 'components/PageTitle';
import Subheading from 'components/Subheading';
import Tabs from 'components/Tabs'; import Tabs from 'components/Tabs';
import Tab from 'components/Tab'; import Tab from 'components/Tab';
import { ListPlaceholder } from 'components/LoadingPlaceholder'; import { ListPlaceholder } from 'components/LoadingPlaceholder';
@ -31,23 +30,34 @@ class Dashboard extends React.Component<Props> {
} }
loadContent = async () => { loadContent = async () => {
const { auth } = this.props;
const user = auth.user ? auth.user.id : undefined;
await Promise.all([ await Promise.all([
this.props.documents.fetchRecentlyModified({ limit: 15 }), this.props.documents.fetchRecentlyModified({ limit: 15 }),
this.props.documents.fetchRecentlyViewed({ limit: 15 }), this.props.documents.fetchRecentlyViewed({ limit: 15 }),
this.props.documents.fetchOwned({ limit: 15, user }),
]); ]);
this.isLoaded = true; this.isLoaded = true;
}; };
renderTab = (path, documents) => {
return (
<Route path={path}>
{this.isLoaded || documents.length ? (
<DocumentList documents={documents} showCollection />
) : (
<ListPlaceholder count={5} />
)}
</Route>
);
};
render() { render() {
const { documents, auth } = this.props; const { documents, auth } = this.props;
if (!auth.user) return; if (!auth.user) return;
const hasRecentlyViewed = documents.recentlyViewed.length > 0; const createdDocuments = documents.owned(auth.user.id);
const hasRecentlyEdited = documents.recentlyEdited.length > 0;
const owned = documents.owned(auth.user.id);
const showContent =
this.isLoaded || (hasRecentlyViewed && hasRecentlyEdited);
return ( return (
<CenteredContent> <CenteredContent>
@ -55,41 +65,23 @@ class Dashboard extends React.Component<Props> {
<h1>Home</h1> <h1>Home</h1>
<Tabs> <Tabs>
<Tab to="/dashboard" exact> <Tab to="/dashboard" exact>
Recently edited Recently updated
</Tab> </Tab>
<Tab to="/dashboard/recent" exact> <Tab to="/dashboard/recent" exact>
Recently viewed Recently viewed
</Tab> </Tab>
<Tab to="/dashboard/owned">Created by me</Tab> <Tab to="/dashboard/created">Created by me</Tab>
</Tabs> </Tabs>
{showContent ? ( <Switch>
<React.Fragment> {this.renderTab('/dashboard/recent', documents.recentlyViewed)}
<Switch> {this.renderTab('/dashboard/created', createdDocuments)}
<Route path="/dashboard/recent"> {this.renderTab('/dashboard', documents.recentlyEdited)}
<DocumentList </Switch>
documents={documents.recentlyViewed} <Actions align="center" justify="flex-end">
showCollection <Action>
/> <NewDocumentMenu label={<NewDocumentIcon />} />
</Route> </Action>
<Route path="/dashboard/owned"> </Actions>
<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} />
)}
</CenteredContent> </CenteredContent>
); );
} }

View File

@ -163,7 +163,7 @@ class DocumentsStore extends BaseStore {
@action @action
fetchOwned = async (options: ?PaginationParams): Promise<*> => { fetchOwned = async (options: ?PaginationParams): Promise<*> => {
await this.fetchPage('owned', options); await this.fetchPage('list', options);
}; };
@action @action

View File

@ -14,14 +14,14 @@ const { authorize, cannot } = policy;
const router = new Router(); const router = new Router();
router.post('documents.list', auth(), pagination(), async ctx => { 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'; if (direction !== 'ASC') direction = 'DESC';
const user = ctx.state.user; let where = { teamId: ctx.state.user.teamId };
let where = { teamId: user.teamId };
if (collection) where = { ...where, collectionId: collection }; 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({ const documents = await Document.scope('defaultScope', starredScope).findAll({
where, where,
order: [[sort, direction]], order: [[sort, direction]],