2023-08-13 12:21:12 +01:00
|
|
|
import * as React from 'react';
|
|
|
|
|
import { useCallback } from 'react';
|
|
|
|
|
import { Dispatch } from 'redux';
|
2023-08-13 15:12:23 +01:00
|
|
|
import { FocusNote } from './useFocusNote';
|
2023-08-13 12:21:12 +01:00
|
|
|
|
2023-08-13 15:12:23 +01:00
|
|
|
const useOnNoteClick = (dispatch: Dispatch, focusNote: FocusNote) => {
|
2023-08-13 12:21:12 +01:00
|
|
|
const onNoteClick = useCallback((event: React.MouseEvent<HTMLDivElement>) => {
|
2023-08-13 17:44:49 +01:00
|
|
|
const noteId = event.currentTarget.getAttribute('data-id');
|
2023-08-13 12:21:12 +01:00
|
|
|
|
2023-08-13 15:12:23 +01:00
|
|
|
focusNote(noteId);
|
|
|
|
|
|
2023-08-13 12:21:12 +01:00
|
|
|
if (event.ctrlKey || event.metaKey) {
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
dispatch({
|
|
|
|
|
type: 'NOTE_SELECT_TOGGLE',
|
|
|
|
|
id: noteId,
|
|
|
|
|
});
|
|
|
|
|
} else if (event.shiftKey) {
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
dispatch({
|
|
|
|
|
type: 'NOTE_SELECT_EXTEND',
|
|
|
|
|
id: noteId,
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
dispatch({
|
|
|
|
|
type: 'NOTE_SELECT',
|
|
|
|
|
id: noteId,
|
|
|
|
|
});
|
|
|
|
|
}
|
2023-08-13 15:12:23 +01:00
|
|
|
}, [dispatch, focusNote]);
|
2023-08-13 12:21:12 +01:00
|
|
|
|
|
|
|
|
return onNoteClick;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default useOnNoteClick;
|