How Applay Filter to Observable and get the length of list to count notification for each user: how can I get the count of notification type number for each user by html code
<div class="users-list-body">
<div>
<h5>
{{ onlineusermodel.userName }}
</h5>
<p>It seems logical that the</p>
</div>
<div class="last-chat-time">
<small class="text-muted">05 min</small>
<div class="new-message-count">
{{ getUserNotification(onlineusermodel) }}
</div>
</div>
</div>
component ts
getUserNotification(onlineUserModel: OnlineUserModel): Number {
// var count = this.allNotifications$.subscribe((n) =>
// n.filter((u) => u.onlineUserModel == onlineUserModel).length
// );
var count = this.store
.pipe(select(selectDirectNotifications))
.subscribe(
(n) => n.filter((u) => u.onlineUserModel == onlineUserModel).length
);
return count;
}
Reducer
const directMessagesReducerInternal = createReducer(
initialState,
on(
directMessagesAction.receivedNotificationForUserAction,
(state, { payload }) => {
const directNotification: DirectNotification = {
onlineUserModel: payload.onlineUserModel,
notificationModel: payload.notificationModel,
};
return {
...state,
allNotifications: [...state.allNotifications, directNotification],
};
}
),
state
allNotifications: DirectNotification[];
selector
export const selectDirectNotifications = createSelector(
selectDirectMessageStore,
(state: DirectMessagesState) => state.allNotifications
);
Action
export const receivedNotificationForUserAction = createAction(
"[DN] RECEIVED_DIRECT_NOTIFICATION",
props<{ payload: ReceivedNotificationForUserDto }>()
);