Skip to content

Commit

Permalink
fix: bookmarks of null on a preview article (#2418)
Browse files Browse the repository at this point in the history
  • Loading branch information
apostolnikov authored and Valentin Georgiev committed Dec 4, 2019
1 parent 77e3cd6 commit 5d58e54
Showing 1 changed file with 29 additions and 26 deletions.
55 changes: 29 additions & 26 deletions packages/save-star-web/src/save-api.js
Expand Up @@ -53,33 +53,36 @@ function onUnsaveMutationUpdate(
function SaveAPI({ articleId, children }) {
return (
<ArticleBookmarked id={articleId} debounceTimeMs={0}>
{({ isLoading, article: { isBookmarked = false } = {} }) => (
<Mutation mutation={saveBookmarks} update={onSaveMutationUpdate}>
{(save, { loading: saveMutationLoading }) => (
<Mutation
mutation={unsaveBookmarks}
update={onUnsaveMutationUpdate}
>
{(unsave, { loading: unsaveMutationLoading }) =>
children({
savedStatus: isBookmarked,
async toggleSaved() {
const args = { variables: { id: articleId } };
{({ isLoading, article }) => {
const isSaved = article && Boolean(article.isBookmarked);
return (
<Mutation mutation={saveBookmarks} update={onSaveMutationUpdate}>
{(save, { loading: saveMutationLoading }) => (
<Mutation
mutation={unsaveBookmarks}
update={onUnsaveMutationUpdate}
>
{(unsave, { loading: unsaveMutationLoading }) =>
children({
savedStatus: isSaved,
async toggleSaved() {
const args = { variables: { id: articleId } };

if (isBookmarked) {
await unsave(args);
} else {
await save(args);
}
},
isLoading:
isLoading || saveMutationLoading || unsaveMutationLoading
})
}
</Mutation>
)}
</Mutation>
)}
if (isSaved) {
await unsave(args);
} else {
await save(args);
}
},
isLoading:
isLoading || saveMutationLoading || unsaveMutationLoading
})
}
</Mutation>
)}
</Mutation>
);
}}
</ArticleBookmarked>
);
}
Expand Down

0 comments on commit 5d58e54

Please sign in to comment.