feat: Show unique views rather than total views in document meta. (#1559)

* unique-views

* fix: 'only you' displays briefly when visiting a document previously only viewed by one other
This commit is contained in:
Tom Moor 2020-10-19 22:44:28 -07:00 committed by GitHub
parent b3549637fe
commit 758fcc1759
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 4 deletions

View File

@ -14,14 +14,18 @@ type Props = {|
function DocumentMetaWithViews({ to, isDraft, document }: Props) {
const { views } = useStores();
const totalViews = useObserver(() => views.countForDocument(document.id));
const documentViews = useObserver(() => views.inDocument(document.id));
const totalViewers = documentViews.length;
const onlyYou = totalViewers === 1 && documentViews[0].user.id;
return (
<Meta document={document} to={to}>
{totalViews && !isDraft ? (
{totalViewers && !isDraft ? (
<>
&nbsp;&middot; Viewed{" "}
{totalViews === 1 ? "once" : `${totalViews} times`}
&nbsp;&middot; Viewed by{" "}
{onlyYou
? "only you"
: `${totalViewers} ${totalViewers === 1 ? "person" : "people"}`}
</>
) : null}
</Meta>