Skip to content

Commit

Permalink
create filters for messageCount
Browse files Browse the repository at this point in the history
  • Loading branch information
felipe-rod123 committed Oct 28, 2023
1 parent 083f0c2 commit ba04471
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
19 changes: 17 additions & 2 deletions apps/meteor/client/views/admin/import/useMessagesCount.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
const useMessagesCount = () => {
return 'messageCount';
import { useMemo } from 'react';

const useMessagesCount = (users, channels, messages, setMessageCount) => {
useMemo(() => {
let messageCount = 0;

const selectedUsers = new Set(users.map((user) => user._id));
const selectedChannels = new Set(users.map((channel) => channel._id));

for (const message of messages) {
if (selectedUsers.has(message.u._id) || selectedChannels.has(message.rid)) {
messageCount++;
}
}

setMessageCount(messageCount);
}, [users, setMessageCount, messages]);
};

export default useMessagesCount;
2 changes: 2 additions & 0 deletions packages/core-typings/src/import/IImportFileData.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import type { IImportChannel } from './IImportChannel';
import type { IImportMessage } from './IImportMessage';
import type { IImportUser } from './IImportUser';

export interface IImportFileData {
users: Array<IImportUser>;
channels: Array<IImportChannel>;
messages: Array<Pick<IImportMessage, '_id' | 'rid' | 'u'>>;
message_count: number;
}

0 comments on commit ba04471

Please sign in to comment.