Skip to content

Commit

Permalink
fix: Unsubscribe from bookmarks on unmount
Browse files Browse the repository at this point in the history
  • Loading branch information
TriPSs committed Oct 7, 2020
1 parent d400282 commit c162be1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 7 additions & 2 deletions app/mobile/screens/Home/BookmarksSlider/BookmarksSlider.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const BookmarksSlider = ({ handleGoTo, onPress }) => {
)

useEffect(() => {
subscribeToMore({
const unsubscribe = subscribeToMore({
document: BookmarkedSubscription,
updateQuery: (prev, { subscriptionData }) => {
if (!subscriptionData.data || !subscriptionData.data.bookmarked) {
Expand All @@ -37,12 +37,17 @@ export const BookmarksSlider = ({ handleGoTo, onPress }) => {
} else {
// Remove the bookmark
return Object.assign({}, {
bookmarks: prev.bookmarks.filter(prevBookmark => prevBookmark._id !== bookmarked._id),
bookmarks: prev.bookmarks.filter((prevBookmark) => prevBookmark._id !== bookmarked._id),
})
}
},
})

return () => {
if (unsubscribe) {
unsubscribe()
}
}
}, [])

if (!loading && (!data || !data.bookmarks || data.bookmarks.length === 0)) {
Expand Down
4 changes: 2 additions & 2 deletions app/mobile/screens/Home/HomeScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ export const Home = ({ navigation }) => {
const movies = noMoviesYet
? null
: moviesData.movies
.filter(movie => !movie.bookmarked)
.filter(movie => !movie.watched.complete)
.filter((movie) => !movie.bookmarked)
.filter((movie) => !movie.watched.complete)

return (
<ScrollViewWithStatusBar>
Expand Down

0 comments on commit c162be1

Please sign in to comment.