Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
tienifr committed May 10, 2024
1 parent cd29b00 commit 2611633
Showing 1 changed file with 15 additions and 19 deletions.
34 changes: 15 additions & 19 deletions src/pages/NewChatPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,32 +94,28 @@ function useOptions({isGroupChat}: NewChatPageProps) {
if (!newGroupDraft?.participants) {
return;
}
const selectedParticipants: OptionData[] = [];
newGroupDraft.participants.forEach((p) => {
if (p.accountID === personalData.accountID) {
const newSelectedOptions: OptionData[] = [];
newGroupDraft.participants.forEach((participant) => {
if (participant.accountID === personalData.accountID) {
return;
}
const participant = listOptions.personalDetails.find((option) => option.accountID === p.accountID);
if (participant) {
selectedParticipants.push(participant);
return;
let participantOption: OptionData | undefined | null = listOptions.personalDetails.find((option) => option.accountID === participant.accountID);
if (!participantOption) {
participantOption = OptionsListUtils.getUserToInviteOption({
searchValue: participant.login,
betas,
});
}
const userToInvite = OptionsListUtils.getUserToInviteOption({
searchValue: p.login,
betas,
});
if (!userToInvite) {
if (!participantOption) {
return;
}
selectedParticipants.push(userToInvite);
newSelectedOptions.push({
...participantOption,
isSelected: true,
});
});
const newSelectedOptions = selectedParticipants.map((participant) => ({
...participant,
reportID: participant?.reportID ?? '',
isSelected: true,
}));
setSelectedOptions(newSelectedOptions);
}, [newGroupDraft, listOptions.personalDetails, betas, personalData]);
}, [newGroupDraft?.participants, listOptions.personalDetails, betas, personalData.accountID]);

return {...options, searchTerm, debouncedSearchTerm, setSearchTerm, areOptionsInitialized: areOptionsInitialized && didScreenTransitionEnd, selectedOptions, setSelectedOptions};
}
Expand Down

0 comments on commit 2611633

Please sign in to comment.