fix event triggered when hold mouse click and release at sidebar

This commit is contained in:
game5413 2023-10-14 18:10:49 +07:00
parent 6b668aaebe
commit a0be0e10ac
2 changed files with 50 additions and 50 deletions

View File

@ -88,44 +88,41 @@ const CollectionItem = ({ item, collection, searchText }) => {
}); });
const handleClick = (event) => { const handleClick = (event) => {
switch (event.button) { if (isItemARequest(item)) {
case 0: // left click dispatch(hideHomePage());
if (isItemARequest(item)) { if (itemIsOpenedInTabs(item, tabs)) {
dispatch(hideHomePage());
if (itemIsOpenedInTabs(item, tabs)) {
dispatch(
focusTab({
uid: item.uid
})
);
return;
}
dispatch(
addTab({
uid: item.uid,
collectionUid: collection.uid,
requestPaneTab: getDefaultRequestPaneTab(item)
})
);
return;
}
dispatch( dispatch(
collectionFolderClicked({ focusTab({
itemUid: item.uid, uid: item.uid
collectionUid: collection.uid
}) })
); );
return; return;
case 2: // right click }
const _menuDropdown = dropdownTippyRef.current; dispatch(
if (_menuDropdown) { addTab({
let menuDropdownBehavior = 'show'; uid: item.uid,
if (_menuDropdown.state.isShown) { collectionUid: collection.uid,
menuDropdownBehavior = 'hide'; requestPaneTab: getDefaultRequestPaneTab(item)
} })
_menuDropdown[menuDropdownBehavior](); );
} return;
return; }
dispatch(
collectionFolderClicked({
itemUid: item.uid,
collectionUid: collection.uid
})
);
};
const handleRightClick = (event) => {
const _menuDropdown = dropdownTippyRef.current;
if (_menuDropdown) {
let menuDropdownBehavior = 'show';
if (_menuDropdown.state.isShown) {
menuDropdownBehavior = 'hide';
}
_menuDropdown[menuDropdownBehavior]();
} }
}; };
@ -203,7 +200,8 @@ const CollectionItem = ({ item, collection, searchText }) => {
? indents.map((i) => { ? indents.map((i) => {
return ( return (
<div <div
onMouseUp={handleClick} onClick={handleClick}
onContextMenu={handleRightClick}
onDoubleClick={handleDoubleClick} onDoubleClick={handleDoubleClick}
className="indent-block" className="indent-block"
key={i} key={i}
@ -219,7 +217,8 @@ const CollectionItem = ({ item, collection, searchText }) => {
}) })
: null} : null}
<div <div
onMouseUp={handleClick} onClick={handleClick}
onContextMenu={handleRightClick}
onDoubleClick={handleDoubleClick} onDoubleClick={handleDoubleClick}
className="flex flex-grow items-center h-full overflow-hidden" className="flex flex-grow items-center h-full overflow-hidden"
style={{ style={{

View File

@ -66,20 +66,17 @@ const Collection = ({ collection, searchText }) => {
}); });
const handleClick = (event) => { const handleClick = (event) => {
dispatch(collectionClicked(collection.uid));
};
const handleRightClick = (event) => {
const _menuDropdown = menuDropdownTippyRef.current; const _menuDropdown = menuDropdownTippyRef.current;
switch (event.button) { if (_menuDropdown) {
case 0: // left click let menuDropdownBehavior = 'show';
dispatch(collectionClicked(collection.uid)); if (_menuDropdown.state.isShown) {
return; menuDropdownBehavior = 'hide';
case 2: // right click }
if (_menuDropdown) { _menuDropdown[menuDropdownBehavior]();
let menuDropdownBehavior = 'show';
if (_menuDropdown.state.isShown) {
menuDropdownBehavior = 'hide';
}
_menuDropdown[menuDropdownBehavior]();
}
return;
} }
}; };
@ -138,7 +135,11 @@ const Collection = ({ collection, searchText }) => {
<CollectionProperties collection={collection} onClose={() => setCollectionPropertiesModal(false)} /> <CollectionProperties collection={collection} onClose={() => setCollectionPropertiesModal(false)} />
)} )}
<div className="flex py-1 collection-name items-center" ref={drop}> <div className="flex py-1 collection-name items-center" ref={drop}>
<div className="flex flex-grow items-center overflow-hidden" onMouseUp={handleClick}> <div
className="flex flex-grow items-center overflow-hidden"
onClick={handleClick}
onContextMenu={handleRightClick}
>
<IconChevronRight <IconChevronRight
size={16} size={16}
strokeWidth={2} strokeWidth={2}