mirror of
https://github.com/fromchat-messenger/web.git
synced 2026-09-22 19:15:08 +03:00
Improve message context menu code
This commit is contained in:
@@ -108,27 +108,8 @@ export function MessageContextMenu({
|
|||||||
window.removeEventListener('blur', handleWindowBlur);
|
window.removeEventListener('blur', handleWindowBlur);
|
||||||
};
|
};
|
||||||
}, [isOpen, isClosing]);
|
}, [isOpen, isClosing]);
|
||||||
|
|
||||||
const handleAction = (action: string) => {
|
|
||||||
switch (action) {
|
|
||||||
case "reply":
|
|
||||||
onReply(message);
|
|
||||||
handleClose();
|
|
||||||
break;
|
|
||||||
case "edit":
|
|
||||||
if (isAuthor) onEdit(message);
|
|
||||||
break;
|
|
||||||
case "delete":
|
|
||||||
if (isAuthor) {
|
|
||||||
onDelete(message);
|
|
||||||
handleClose();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
onOpenChange(false);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleClose = () => {
|
function handleClose() {
|
||||||
setIsClosing(true);
|
setIsClosing(true);
|
||||||
// Set appropriate closing animation based on opening animation
|
// Set appropriate closing animation based on opening animation
|
||||||
const closingAnimation = animationClass.replace('entering', 'closing');
|
const closingAnimation = animationClass.replace('entering', 'closing');
|
||||||
@@ -140,7 +121,44 @@ export function MessageContextMenu({
|
|||||||
setIsClosing(false);
|
setIsClosing(false);
|
||||||
setAnimationClass('entering'); // Reset for next opening
|
setAnimationClass('entering'); // Reset for next opening
|
||||||
}, 200); // Match the animation duration from _animations.scss
|
}, 200); // Match the animation duration from _animations.scss
|
||||||
};
|
}
|
||||||
|
|
||||||
|
interface Action {
|
||||||
|
label: string;
|
||||||
|
icon: string;
|
||||||
|
onClick: () => void;
|
||||||
|
show: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
const actions: Action[] = [
|
||||||
|
{
|
||||||
|
label: "Reply",
|
||||||
|
icon: "reply",
|
||||||
|
onClick: () => {
|
||||||
|
onReply(message);
|
||||||
|
handleClose();
|
||||||
|
},
|
||||||
|
show: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "Edit",
|
||||||
|
icon: "edit",
|
||||||
|
onClick: () => {
|
||||||
|
onEdit(message);
|
||||||
|
handleClose();
|
||||||
|
},
|
||||||
|
show: isAuthor
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "Delete",
|
||||||
|
icon: "delete",
|
||||||
|
onClick: () => {
|
||||||
|
onDelete(message);
|
||||||
|
handleClose();
|
||||||
|
},
|
||||||
|
show: isAuthor
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
return isOpen && (
|
return isOpen && (
|
||||||
<div
|
<div
|
||||||
@@ -153,22 +171,18 @@ export function MessageContextMenu({
|
|||||||
zIndex: 1000
|
zIndex: 1000
|
||||||
}}
|
}}
|
||||||
onClick={(e) => e.stopPropagation()}>
|
onClick={(e) => e.stopPropagation()}>
|
||||||
<div className="context-menu-item" onClick={() => handleAction("reply")}>
|
{actions.map((action, i) => (
|
||||||
<span className="material-symbols">reply</span>
|
action.show && (
|
||||||
Ответить
|
<div
|
||||||
</div>
|
className="context-menu-item"
|
||||||
{isAuthor && (
|
onClick={action.onClick}
|
||||||
<>
|
key={i}
|
||||||
<div className="context-menu-item" onClick={() => handleAction("edit")}>
|
>
|
||||||
<span className="material-symbols">edit</span>
|
<span className="material-symbols">{action.icon}</span>
|
||||||
Редактировать
|
{action.label}
|
||||||
</div>
|
</div>
|
||||||
<div className="context-menu-item" onClick={() => handleAction("delete")}>
|
)
|
||||||
<span className="material-symbols">delete</span>
|
))}
|
||||||
Удалить
|
|
||||||
</div>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user