diff --git a/src/shared/hooks/useCases/useUnreadInboxItems.ts b/src/shared/hooks/useCases/useUnreadInboxItems.ts deleted file mode 100644 index 6b3ae8f6c0..0000000000 --- a/src/shared/hooks/useCases/useUnreadInboxItems.ts +++ /dev/null @@ -1,36 +0,0 @@ -import { useEffect } from "react"; -import { useDispatch, useSelector } from "react-redux"; -import { usePreviousDistinct, useUpdateEffect } from "react-use"; -import { selectUserStreamsWithNotificationsAmount } from "@/pages/Auth/store/selectors"; -import { inboxActions } from "@/store/states"; - -export const useUnreadInboxItems = (unread?: boolean): void => { - const dispatch = useDispatch(); - const notificationsAmount = useSelector( - selectUserStreamsWithNotificationsAmount(), - ); - const previousNotificationsAmount = usePreviousDistinct(notificationsAmount); - - useUpdateEffect(() => { - if ( - !unread || - !notificationsAmount || - (typeof previousNotificationsAmount === "number" && - notificationsAmount < previousNotificationsAmount) - ) { - return; - } - - dispatch(inboxActions.refreshUnreadInboxItems.request()); - }, [notificationsAmount]); - - useEffect(() => { - return () => { - dispatch( - inboxActions.refreshUnreadInboxItems.cancel( - "Cancel unread inbox items refresh on unmount", - ), - ); - }; - }, []); -}; diff --git a/src/store/states/inbox/actions.ts b/src/store/states/inbox/actions.ts index aad2217412..d62a64992d 100644 --- a/src/store/states/inbox/actions.ts +++ b/src/store/states/inbox/actions.ts @@ -23,13 +23,6 @@ export const getInboxItems = createAsyncAction( string >(); -export const refreshUnreadInboxItems = createAsyncAction( - InboxActionType.REFRESH_UNREAD_INBOX_ITEMS, - InboxActionType.REFRESH_UNREAD_INBOX_ITEMS_SUCCESS, - InboxActionType.REFRESH_UNREAD_INBOX_ITEMS_FAILURE, - InboxActionType.REFRESH_UNREAD_INBOX_ITEMS_CANCEL, -)(); - export const addNewInboxItems = createStandardAction( InboxActionType.ADD_NEW_INBOX_ITEMS, )< diff --git a/src/store/states/inbox/constants.ts b/src/store/states/inbox/constants.ts index bc42bc1710..9a7b410e4c 100644 --- a/src/store/states/inbox/constants.ts +++ b/src/store/states/inbox/constants.ts @@ -6,11 +6,6 @@ export enum InboxActionType { GET_INBOX_ITEMS_FAILURE = "@INBOX/GET_INBOX_ITEMS_FAILURE", GET_INBOX_ITEMS_CANCEL = "@INBOX/GET_INBOX_ITEMS_CANCEL", - REFRESH_UNREAD_INBOX_ITEMS = "@INBOX/REFRESH_UNREAD_INBOX_ITEMS", - REFRESH_UNREAD_INBOX_ITEMS_SUCCESS = "@INBOX/REFRESH_UNREAD_INBOX_ITEMS_SUCCESS", - REFRESH_UNREAD_INBOX_ITEMS_FAILURE = "@INBOX/REFRESH_UNREAD_INBOX_ITEMS_FAILURE", - REFRESH_UNREAD_INBOX_ITEMS_CANCEL = "@INBOX/REFRESH_UNREAD_INBOX_ITEMS_CANCEL", - ADD_NEW_INBOX_ITEMS = "@INBOX/ADD_NEW_INBOX_ITEMS", UPDATE_INBOX_ITEM = "@INBOX/UPDATE_INBOX_ITEM", diff --git a/src/store/states/inbox/saga/index.ts b/src/store/states/inbox/saga/index.ts index b71cbe048b..f040cb9624 100644 --- a/src/store/states/inbox/saga/index.ts +++ b/src/store/states/inbox/saga/index.ts @@ -1,7 +1,6 @@ import { takeLatestWithCancel } from "@/shared/utils/saga"; import * as actions from "../actions"; import { getInboxItems } from "./getInboxItems"; -import { refreshUnreadInboxItems } from "./refreshUnreadInboxItems"; export function* mainSaga() { yield takeLatestWithCancel( @@ -9,9 +8,4 @@ export function* mainSaga() { actions.getInboxItems.cancel, getInboxItems, ); - yield takeLatestWithCancel( - actions.refreshUnreadInboxItems.request, - actions.refreshUnreadInboxItems.cancel, - refreshUnreadInboxItems, - ); } diff --git a/src/store/states/inbox/saga/refreshUnreadInboxItems.ts b/src/store/states/inbox/saga/refreshUnreadInboxItems.ts deleted file mode 100644 index 9b01188219..0000000000 --- a/src/store/states/inbox/saga/refreshUnreadInboxItems.ts +++ /dev/null @@ -1,73 +0,0 @@ -import { call, put, select } from "redux-saga/effects"; -import { Logger, UserService } from "@/services"; -import { - ChatChannelToLayoutItemConverter, - FeedItemFollowToLayoutItemWithFollowDataConverter, -} from "@/shared/converters"; -import { Awaited, FeedLayoutItemWithFollowData } from "@/shared/interfaces"; -import { Timestamp } from "@/shared/models"; -import * as actions from "../actions"; -import { selectInboxItems } from "../selectors"; -import { InboxItems } from "../types"; - -export function* refreshUnreadInboxItems() { - try { - const currentItems = (yield select(selectInboxItems)) as InboxItems; - const newInboxItems: FeedLayoutItemWithFollowData[] = []; - let startAfter: Timestamp | null = null; - let keepItemsFetching = true; - - while (keepItemsFetching) { - const { data, lastDocTimestamp, hasMore } = (yield call( - UserService.getInboxItemsWithMetadata, - { - startAfter, - limit: 5, - unread: true, - }, - )) as Awaited>; - const chatChannelItems = data.chatChannels - .filter( - (chatChannel) => - chatChannel.messageCount > 0 && - (!currentItems.data || - currentItems.data.every( - (item) => item.itemId !== chatChannel.id, - )), - ) - .map((item) => ChatChannelToLayoutItemConverter.toTargetEntity(item)); - const feedItemFollowItems = data.feedItemFollows - .filter( - (feedItemFollow) => - !currentItems.data || - currentItems.data.every( - (item) => item.itemId !== feedItemFollow.id, - ), - ) - .map((item) => - FeedItemFollowToLayoutItemWithFollowDataConverter.toTargetEntity( - item, - ), - ); - newInboxItems.push(...chatChannelItems, ...feedItemFollowItems); - keepItemsFetching = hasMore; - startAfter = lastDocTimestamp; - } - - if (newInboxItems.length > 0) { - yield put( - actions.addNewInboxItems( - newInboxItems.map((item) => ({ - item, - statuses: { - isAdded: false, - isRemoved: false, - }, - })), - ), - ); - } - } catch (err) { - Logger.error(err); - } -}