Skip to content

Commit

Permalink
feat: add refetchContent helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
adrians5j committed Sep 1, 2020
1 parent a38b458 commit 5121c7e
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const ContentDetails = ({ contentModel, dataList }) => {
};
}, [contentModel.modelId]);

const { data, loading: readQueryLoading } = useQuery(READ_CONTENT, {
const { data, loading: readQueryLoading, refetch: readQueryRefetch } = useQuery(READ_CONTENT, {
variables: { id: contentId },
skip: !contentId,
onCompleted: data => {
Expand All @@ -63,9 +63,13 @@ const ContentDetails = ({ contentModel, dataList }) => {

const getLocale = useCallback(() => locale, [locale]);
const getLoading = useCallback(() => readQueryLoading || loading, [loading, readQueryLoading]);
const refetchContent = useCallback(async () => {
setLoading(true);
await readQueryRefetch();
setLoading(false);
}, [readQueryRefetch]);

const content = get(data, "content.data") || {};

const contentParent = get(content, "meta.parent");
const revisionsList = useQuery(LIST_REVISIONS, {
skip: !contentParent,
Expand All @@ -82,6 +86,7 @@ const ContentDetails = ({ contentModel, dataList }) => {
getLoading,
dataList,
content,
refetchContent,
contentModel,
revisionsList,
state,
Expand Down

0 comments on commit 5121c7e

Please sign in to comment.