Skip to content

Commit

Permalink
feat: message action on conversations with single messages only
Browse files Browse the repository at this point in the history
  • Loading branch information
geeky-abhishek committed Feb 18, 2022
1 parent 312dd13 commit 0f692e2
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 30 deletions.
51 changes: 27 additions & 24 deletions src/views/app/detail-panel/edit/edit-view.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,10 @@ export default function EditView({ mailId, folderId, setHeader, toggleAppBoard }
}, [account, accounts, defaultIdentity?.address, defaultIdentity?.fullname, t, updateEditorCb]);

useEffect(() => {
if (activeMailId) {
if (activeMailId && !messages[activeMailId]?.isComplete) {
dispatch(getMsg({ msgId: activeMailId }));
}
}, [activeMailId, dispatch]);
}, [activeMailId, dispatch, messages, updateEditorCb]);

const sendMailCb = useCallback(() => {
setBtnSendLabel(t('label.sending', 'Sending'));
Expand Down Expand Up @@ -474,28 +474,30 @@ export default function EditView({ mailId, folderId, setHeader, toggleAppBoard }
}, [editor?.subject, setHeader, updateBoard, action, t]);

useEffect(() => {
if (!editors[editorId]) {
dispatch(
createEditor({
settings,
editorId,
id: action === ActionsType.EDIT_AS_DRAFT ? activeMailId : undefined,
original: messages[activeMailId ?? editorId],
boardContext,
action,
change,
accounts,
labels: {
to: `${t('label.to', 'To')}:`,
from: `${t('label.from', 'From')}:`,
cc: `${t('label.cc', 'CC')}:`,
subject: `${t('label.subject', 'Subject')}:`,
sent: `${t('label.sent', 'Sent')}:`
}
})
);
} else {
setEditor(editors[editorId]);
if (activeMailId && messages[activeMailId]?.isComplete) {
if (!editors[editorId]) {
dispatch(
createEditor({
settings,
editorId,
id: action === ActionsType.EDIT_AS_DRAFT ? activeMailId : undefined,
original: messages[activeMailId ?? editorId],
boardContext,
action,
change,
accounts,
labels: {
to: `${t('label.to', 'To')}:`,
from: `${t('label.from', 'From')}:`,
cc: `${t('label.cc', 'CC')}:`,
subject: `${t('label.subject', 'Subject')}:`,
sent: `${t('label.sent', 'Sent')}:`
}
})
);
} else {
setEditor(editors[editorId]);
}
}
}, [
editors,
Expand Down Expand Up @@ -574,6 +576,7 @@ export default function EditView({ mailId, folderId, setHeader, toggleAppBoard }
const participants = concat(editor?.to, editor?.bcc, editor?.cc);
return btnSendDisabled || participants.length === 0 || some(participants, { error: true });
}, [btnSendDisabled, editor]);

return editor ? (
<Catcher>
<Container onDragOver={(event) => onDragOverEvent(event)}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ export default function ConversationListItem({
item.messages,
(acc, v) => {
const msg = find(messages, ['id', v.id]);

if (msg) {
// in trash we show all messages of the conversation even if only one is deleted
if (folderId === FOLDERS.TRASH) {
Expand Down Expand Up @@ -284,6 +285,7 @@ export default function ConversationListItem({
onDoubleClick={_onDoubleClick}
hoverTooltipLabel={participantsString}
isConversation
messagesToRender={messagesToRender}
>
<div style={{ alignSelf: 'center' }} data-testid={`AvatarContainer`}>
<ItemAvatar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,19 @@ const ListItemActionWrapper = ({
onDoubleClick,
item,
isConversation,
hoverTooltipLabel
hoverTooltipLabel,
messagesToRender
}) => {
const { getMessageActions, getConversationActions } = useContext(ActionsContext);
const [hoverActions, dropdownActions] = useMemo(
() => (isConversation ? getConversationActions(item) : getMessageActions(item)),
[isConversation, getConversationActions, item, getMessageActions]
);

const [hoverActions, dropdownActions] = useMemo(() => {
if (isConversation) {
return messagesToRender?.length > 1
? getConversationActions(item)
: getMessageActions({ ...item, ...messagesToRender[0] });
}
return getMessageActions(item);
}, [isConversation, getMessageActions, item, messagesToRender, getConversationActions]);
return (
<Dropdown
contextMenu
Expand Down
2 changes: 1 addition & 1 deletion translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,8 @@
"receive_message": "Receiving Messages",
"received_from_address": "Received from (address)",
"remove": "Remove",
"remove_plural": "Remove all",
"remove_from_this_list": "Remove from this list",
"remove_plural": "Remove all",
"replied": "Replied",
"resend": "Resend",
"restore": "Restore",
Expand Down

0 comments on commit 0f692e2

Please sign in to comment.