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:
@ -14,14 +14,18 @@ type Props = {|
|
|||||||
|
|
||||||
function DocumentMetaWithViews({ to, isDraft, document }: Props) {
|
function DocumentMetaWithViews({ to, isDraft, document }: Props) {
|
||||||
const { views } = useStores();
|
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 (
|
return (
|
||||||
<Meta document={document} to={to}>
|
<Meta document={document} to={to}>
|
||||||
{totalViews && !isDraft ? (
|
{totalViewers && !isDraft ? (
|
||||||
<>
|
<>
|
||||||
· Viewed{" "}
|
· Viewed by{" "}
|
||||||
{totalViews === 1 ? "once" : `${totalViews} times`}
|
{onlyYou
|
||||||
|
? "only you"
|
||||||
|
: `${totalViewers} ${totalViewers === 1 ? "person" : "people"}`}
|
||||||
</>
|
</>
|
||||||
) : null}
|
) : null}
|
||||||
</Meta>
|
</Meta>
|
||||||
|
Reference in New Issue
Block a user