Skip to content

Commit

Permalink
Merge pull request #2420 from daostack/bugfix/CW-2416-infinite-inbox-…
Browse files Browse the repository at this point in the history
…loading

DEV Infinite loading of the Inbox #2416
  • Loading branch information
andreymikhadyuk authored Dec 25, 2023
2 parents cfb7ab4 + d75f405 commit 854bf86
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const GroupChatIcon: FC<GroupChatIconProps> = ({ className }) => (
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<g id="Layer_1" clip-path="url(#clip0_11827_31255)">
<g id="Layer_1" clipPath="url(#clip0_11827_31255)">
<path
id="Vector"
d="M12.4725 8.84766C8.9225 8.84766 6.03516 12.2649 6.03516 14.4519C6.03516 16.6389 8.91856 17.9824 12.4725 17.9824C16.0265 17.9824 18.9138 16.6389 18.9138 14.4675C18.9138 12.2961 16.0501 8.84766 12.4725 8.84766Z"
Expand Down
2 changes: 1 addition & 1 deletion src/shared/icons/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,5 @@ export { default as ReplyIcon } from "./reply.icon";
export { default as CopyIcon } from "./copy.icon";
export { default as HideIcon } from "./hide.icon";
export { default as InboxFilterIcon } from "./inboxFilter.icon";
export { default as GroupChatIcon } from "./group-chat.icon";
export { default as GroupChatIcon } from "./groupChat.icon";
export { default as NotificationsIcon } from "./notifications.icon";
54 changes: 46 additions & 8 deletions src/store/states/inbox/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ const getDocTimestamps = (
: null,
});

const areTimestampsEqual = (
timestampA: Timestamp | null,
timestampB: Timestamp | null,
): boolean =>
timestampA?.seconds === timestampB?.seconds &&
timestampA?.nanoseconds === timestampB?.nanoseconds;

const updateInboxItemInList = (
state: WritableDraft<InboxState>,
payload: {
Expand Down Expand Up @@ -93,10 +100,16 @@ const updateInboxItemInList = (

state.items = {
...state.items,
firstDocTimestamp,
lastDocTimestamp,
data: nextData,
};

if (!areTimestampsEqual(state.items.firstDocTimestamp, firstDocTimestamp)) {
state.items.firstDocTimestamp = firstDocTimestamp;
}

if (!areTimestampsEqual(state.items.lastDocTimestamp, lastDocTimestamp)) {
state.items.lastDocTimestamp = lastDocTimestamp;
}
};

const updateInboxItemInChatChannelItems = (
Expand Down Expand Up @@ -194,10 +207,16 @@ const updateFeedItemInInboxItem = (

state.items = {
...state.items,
firstDocTimestamp,
lastDocTimestamp,
data: nextData,
};

if (!areTimestampsEqual(state.items.firstDocTimestamp, firstDocTimestamp)) {
state.items.firstDocTimestamp = firstDocTimestamp;
}

if (!areTimestampsEqual(state.items.lastDocTimestamp, lastDocTimestamp)) {
state.items.lastDocTimestamp = lastDocTimestamp;
}
};

const updateSharedInboxItem = (
Expand Down Expand Up @@ -321,10 +340,16 @@ const updateChatChannelItemInInboxItem = (

state.items = {
...state.items,
firstDocTimestamp,
lastDocTimestamp,
data: nextData,
};

if (!areTimestampsEqual(state.items.firstDocTimestamp, firstDocTimestamp)) {
state.items.firstDocTimestamp = firstDocTimestamp;
}

if (!areTimestampsEqual(state.items.lastDocTimestamp, lastDocTimestamp)) {
state.items.lastDocTimestamp = lastDocTimestamp;
}
};

const updateChatChannelItemInChatChannelItem = (
Expand Down Expand Up @@ -499,9 +524,22 @@ export const reducer = createReducer<InboxState, Action>(INITIAL_INBOX_STATE)
nextState.items = {
...nextState.items,
data,
firstDocTimestamp,
lastDocTimestamp,
};

if (
!areTimestampsEqual(
nextState.items.firstDocTimestamp,
firstDocTimestamp,
)
) {
nextState.items.firstDocTimestamp = firstDocTimestamp;
}

if (
!areTimestampsEqual(nextState.items.lastDocTimestamp, lastDocTimestamp)
) {
nextState.items.lastDocTimestamp = lastDocTimestamp;
}
}),
)
.handleAction(actions.updateInboxItem, (state, { payload }) =>
Expand Down

0 comments on commit 854bf86

Please sign in to comment.