Skip to content

Commit c162be1

Browse files
committed
fix: Unsubscribe from bookmarks on unmount
1 parent d400282 commit c162be1

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

app/mobile/screens/Home/BookmarksSlider/BookmarksSlider.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const BookmarksSlider = ({ handleGoTo, onPress }) => {
1818
)
1919

2020
useEffect(() => {
21-
subscribeToMore({
21+
const unsubscribe = subscribeToMore({
2222
document: BookmarkedSubscription,
2323
updateQuery: (prev, { subscriptionData }) => {
2424
if (!subscriptionData.data || !subscriptionData.data.bookmarked) {
@@ -37,12 +37,17 @@ export const BookmarksSlider = ({ handleGoTo, onPress }) => {
3737
} else {
3838
// Remove the bookmark
3939
return Object.assign({}, {
40-
bookmarks: prev.bookmarks.filter(prevBookmark => prevBookmark._id !== bookmarked._id),
40+
bookmarks: prev.bookmarks.filter((prevBookmark) => prevBookmark._id !== bookmarked._id),
4141
})
4242
}
4343
},
4444
})
4545

46+
return () => {
47+
if (unsubscribe) {
48+
unsubscribe()
49+
}
50+
}
4651
}, [])
4752

4853
if (!loading && (!data || !data.bookmarks || data.bookmarks.length === 0)) {

app/mobile/screens/Home/HomeScreen.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ export const Home = ({ navigation }) => {
8080
const movies = noMoviesYet
8181
? null
8282
: moviesData.movies
83-
.filter(movie => !movie.bookmarked)
84-
.filter(movie => !movie.watched.complete)
83+
.filter((movie) => !movie.bookmarked)
84+
.filter((movie) => !movie.watched.complete)
8585

8686
return (
8787
<ScrollViewWithStatusBar>

0 commit comments

Comments
 (0)