-
Notifications
You must be signed in to change notification settings - Fork 955
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(mobile): auto mark as read when scrolling (#2781)
* feat(mobile): auto mark as read when scrolling * reset unread state after fetch * refetch with subscription and unread * chore: auto-fix linting and formatting issues * chore: trigger build
- Loading branch information
Showing
8 changed files
with
135 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import type ViewToken from "@shopify/flash-list/dist/viewability/ViewToken" | ||
import { useCallback } from "react" | ||
|
||
import { useGeneralSettingKey } from "@/src/atoms/settings/general" | ||
import { debouncedFetchEntryContentByStream } from "@/src/store/entry/store" | ||
import { unreadSyncService } from "@/src/store/unread/store" | ||
|
||
export function useOnViewableItemsChanged(): (info: { | ||
viewableItems: ViewToken[] | ||
changed: ViewToken[] | ||
}) => void { | ||
const markAsReadWhenScrolling = useGeneralSettingKey("scrollMarkUnread") | ||
|
||
return useCallback( | ||
({ viewableItems, changed }) => { | ||
debouncedFetchEntryContentByStream(viewableItems.map((item) => item.key)) | ||
if (markAsReadWhenScrolling) { | ||
changed | ||
.filter((item) => !item.isViewable) | ||
.forEach((item) => { | ||
unreadSyncService.markEntryAsRead(item.key) | ||
}) | ||
} | ||
}, | ||
[markAsReadWhenScrolling], | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters