Chonky icon indicating copy to clipboard operation
Chonky copied to clipboard

failure to get 'open_files' callback on initial double click after page refresh when using +2 browsers in the same page

Open eilyaamin opened this issue 2 years ago • 2 comments

scrnli-7-20-2023-12-40-13-pm_q7PLD7KD.webm

eilyaamin avatar Jul 20 '23 10:07 eilyaamin

+1. When I render filebrowser component more than 1, chonky's action handler doesn't fires open_files and mouse_click: double events. Basically it couldn't handle double clicks. Only bottom component fires double click events. When clicking randomly on any file browser, somehow the double click throw event can pass from the bottom component to another random component. But in the end, only one rendered component can handle double clicks. That's why I developed my action handler by adapting it to a single mouse click. This is a critical bug that needs to be resolved.

erenertas avatar Oct 14 '23 13:10 erenertas

Hi, I am having the same issue.

For the moment, I fixed it by keeping track of the "single" clicks events myself (only works because the single-click event doesn't have a major effect on my app):

function getActionHandler() {
    let lastSingleClick = Date.now();
    let doubleClickDelay = 300;

    const handleAction = (data, setCurrentFolder) => {
        if (data.id === ChonkyActions.MouseClickFile.id) {
            let file = data.payload.file;
            if (data.payload.clickType === "double") {
                setCurrentFolder(file.id);
            } else {
                let now = Date.now();
                if(now - lastSingleClick < doubleClickDelay) {
                    setCurrentFolder(file.id);
                }
                lastSingleClick = now;
            }
        }
    };

    return handleAction;
}

and I use it this way in my component:

const handleAction = React.useMemo(getActionHandler, []);

This won't prevent the "single" click event to be fired so any action triggered by the single click will apply. Hope it helps in some of your cases.

divad1196 avatar Nov 26 '23 18:11 divad1196