fix: Update DocumentMetaWithViews to hooks, correctly observe store changes
closes #1555
This commit is contained in:
@ -1,20 +1,20 @@
|
|||||||
// @flow
|
// @flow
|
||||||
import { inject } from "mobx-react";
|
import { useObserver } from "mobx-react";
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import styled from "styled-components";
|
import styled from "styled-components";
|
||||||
import ViewsStore from "stores/ViewsStore";
|
|
||||||
import Document from "models/Document";
|
import Document from "models/Document";
|
||||||
import DocumentMeta from "components/DocumentMeta";
|
import DocumentMeta from "components/DocumentMeta";
|
||||||
|
import useStores from "../hooks/useStores";
|
||||||
|
|
||||||
type Props = {|
|
type Props = {|
|
||||||
views: ViewsStore,
|
|
||||||
document: Document,
|
document: Document,
|
||||||
isDraft: boolean,
|
isDraft: boolean,
|
||||||
to?: string,
|
to?: string,
|
||||||
|};
|
|};
|
||||||
|
|
||||||
function DocumentMetaWithViews({ views, to, isDraft, document }: Props) {
|
function DocumentMetaWithViews({ to, isDraft, document }: Props) {
|
||||||
const totalViews = views.countForDocument(document.id);
|
const { views } = useStores();
|
||||||
|
const totalViews = useObserver(() => views.countForDocument(document.id));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Meta document={document} to={to}>
|
<Meta document={document} to={to}>
|
||||||
@ -45,4 +45,4 @@ const Meta = styled(DocumentMeta)`
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
export default inject("views")(DocumentMetaWithViews);
|
export default DocumentMetaWithViews;
|
||||||
|
Reference in New Issue
Block a user