diff --git a/app/components/Badge.js b/app/components/Badge.js
index c4d3f3604..c138111ff 100644
--- a/app/components/Badge.js
+++ b/app/components/Badge.js
@@ -6,7 +6,8 @@ const Badge = styled.span`
padding: 2px 6px 3px;
background-color: ${({ yellow, primary, theme }) =>
yellow ? theme.yellow : primary ? theme.primary : theme.textTertiary};
- color: ${({ primary, theme }) => (primary ? theme.white : theme.background)};
+ color: ${({ primary, yellow, theme }) =>
+ primary ? theme.white : yellow ? theme.text : theme.background};
border-radius: 4px;
font-size: 11px;
font-weight: 500;
diff --git a/app/components/DocumentMeta.js b/app/components/DocumentMeta.js
index 08eede428..31a96d403 100644
--- a/app/components/DocumentMeta.js
+++ b/app/components/DocumentMeta.js
@@ -18,8 +18,7 @@ const Container = styled(Flex)`
`;
const Modified = styled.span`
- color: ${(props) =>
- props.highlight ? props.theme.text : props.theme.textTertiary};
+ color: ${(props) => props.theme.textTertiary};
font-weight: ${(props) => (props.highlight ? "600" : "400")};
`;
@@ -28,6 +27,7 @@ type Props = {
auth: AuthStore,
showCollection?: boolean,
showPublished?: boolean,
+ showLastViewed?: boolean,
document: Document,
children: React.Node,
to?: string,
@@ -38,6 +38,7 @@ function DocumentMeta({
collections,
showPublished,
showCollection,
+ showLastViewed,
document,
children,
to,
@@ -66,37 +67,37 @@ function DocumentMeta({
if (deletedAt) {
content = (
- deleted ago
+ deleted
);
} else if (archivedAt) {
content = (
- archived ago
+ archived
);
} else if (createdAt === updatedAt) {
content = (
- created ago
+ created
);
} else if (publishedAt && (publishedAt === updatedAt || showPublished)) {
content = (
- published ago
+ published
);
} else if (isDraft) {
content = (
- saved ago
+ saved
);
} else {
content = (
- updated ago
+ updated
);
}
@@ -105,12 +106,20 @@ function DocumentMeta({
const updatedByMe = auth.user && auth.user.id === updatedBy.id;
const timeSinceNow = () => {
- if (!lastViewedAt)
- return Never viewed;
+ if (isDraft || !showLastViewed) {
+ return null;
+ }
+ if (!lastViewedAt) {
+ return (
+ <>
+ • Never viewed
+ >
+ );
+ }
return (
- Viewed ago
+ • Viewed
);
};
@@ -127,7 +136,7 @@ function DocumentMeta({
)}
- • {timeSinceNow()}
+ {timeSinceNow()}
{children}
);
diff --git a/app/components/DocumentPreview/DocumentPreview.js b/app/components/DocumentPreview/DocumentPreview.js
index 2cd050956..d8f59be99 100644
--- a/app/components/DocumentPreview/DocumentPreview.js
+++ b/app/components/DocumentPreview/DocumentPreview.js
@@ -86,6 +86,7 @@ class DocumentPreview extends React.Component {
>
+ {document.isNew && New}
{!document.isDraft &&
!document.isArchived &&
!document.isTemplate && (
@@ -105,7 +106,6 @@ class DocumentPreview extends React.Component {
{document.isTemplate && showTemplate && (
Template
)}
- {document.isNew && New}
{document.isTemplate &&
!document.isArchived &&
@@ -134,6 +134,7 @@ class DocumentPreview extends React.Component {
document={document}
showCollection={showCollection}
showPublished={showPublished}
+ showLastViewed
/>
);
diff --git a/app/components/Time.js b/app/components/Time.js
index d7b55f329..bee88cf66 100644
--- a/app/components/Time.js
+++ b/app/components/Time.js
@@ -24,6 +24,8 @@ type Props = {
dateTime: string,
children?: React.Node,
tooltipDelay?: number,
+ addSuffix?: boolean,
+ shorten?: boolean,
};
class Time extends React.Component {
@@ -40,6 +42,18 @@ class Time extends React.Component {
}
render() {
+ const { shorten, addSuffix } = this.props;
+ let content = distanceInWordsToNow(this.props.dateTime, {
+ addSuffix,
+ });
+
+ if (shorten) {
+ content = content
+ .replace("about", "")
+ .replace("minute", "min")
+ .replace("less than a minute ago", "just now");
+ }
+
return (
{
placement="bottom"
>
);
diff --git a/app/models/Document.js b/app/models/Document.js
index 91818e040..1ec8134f9 100644
--- a/app/models/Document.js
+++ b/app/models/Document.js
@@ -21,11 +21,11 @@ export default class Document extends BaseModel {
@observable isSaving: boolean = false;
@observable embedsDisabled: boolean = false;
@observable injectTemplate: boolean = false;
+ @observable lastViewedAt: ?string;
store: DocumentsStore;
collaborators: User[];
collectionId: string;
- @observable lastViewedAt: ?string;
createdAt: string;
createdBy: User;
updatedAt: string;
diff --git a/app/stores/DocumentsStore.js b/app/stores/DocumentsStore.js
index 1e9e1046e..c14b9e180 100644
--- a/app/stores/DocumentsStore.js
+++ b/app/stores/DocumentsStore.js
@@ -23,7 +23,6 @@ type ImportOptions = {
};
export default class DocumentsStore extends BaseStore {
- @observable recentlyViewedIds: string[] = [];
@observable searchCache: Map = new Map();
@observable starredIds: Map = new Map();
@observable backlinks: Map = new Map();
@@ -50,8 +49,8 @@ export default class DocumentsStore extends BaseStore {
@computed
get recentlyViewed(): Document[] {
return orderBy(
- compact(this.recentlyViewedIds.map((id) => this.data.get(id))),
- "updatedAt",
+ filter(this.all, (d) => d.lastViewedAt),
+ "lastViewedAt",
"desc"
);
}
@@ -299,15 +298,7 @@ export default class DocumentsStore extends BaseStore {
@action
fetchRecentlyViewed = async (options: ?PaginationParams): Promise<*> => {
- const data = await this.fetchNamedPage("viewed", options);
-
- runInAction("DocumentsStore#fetchRecentlyViewed", () => {
- // $FlowFixMe
- this.recentlyViewedIds.replace(
- uniq(this.recentlyViewedIds.concat(map(data, "id")))
- );
- });
- return data;
+ return this.fetchNamedPage("viewed", options);
};
@action
@@ -541,10 +532,6 @@ export default class DocumentsStore extends BaseStore {
async delete(document: Document) {
await super.delete(document);
- runInAction(() => {
- this.recentlyViewedIds = without(this.recentlyViewedIds, document.id);
- });
-
// check to see if we have any shares related to this document already
// loaded in local state. If so we can go ahead and remove those too.
const share = this.rootStore.shares.getByDocumentId(document.id);
diff --git a/server/api/documents.js b/server/api/documents.js
index 6e760b2b4..f8a375842 100644
--- a/server/api/documents.js
+++ b/server/api/documents.js
@@ -283,7 +283,11 @@ router.post("documents.viewed", auth(), pagination(), async (ctx) => {
limit: ctx.state.pagination.limit,
});
- const documents = views.map((view) => view.document);
+ const documents = views.map((view) => {
+ const document = view.document;
+ document.views = [view];
+ return document;
+ });
const data = await Promise.all(
documents.map((document) => presentDocument(document))
);