mirror of
https://github.com/lingble/chatwoot.git
synced 2025-11-01 03:27:52 +00:00
1. Ensure audio player ref is accessible before triggering calls ([Sentry](https://chatwoot-p3.sentry.io/issues/6221981610)) 2. Use correct default for attachments, this was incorrectly set to `null` in a previous PR ([Sentry](https://chatwoot-p3.sentry.io/issues/5966738120)) 3. Fix `lastNonActivityMessage` is not present ([Sentry](https://chatwoot-p3.sentry.io/issues/6116038455)) 4. Fix `Alt+J` & `Alt+K` shortcuts not working ([Sentry](https://chatwoot-p3.sentry.io/issues/6075125384)) --------- Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com>
61 lines
1.9 KiB
JavaScript
61 lines
1.9 KiB
JavaScript
import { useKeyboardEvents } from 'dashboard/composables/useKeyboardEvents';
|
|
|
|
export function useChatListKeyboardEvents(listRef) {
|
|
const getKeyboardListenerParams = () => {
|
|
const allConversations = listRef.value.querySelectorAll(
|
|
'div.conversations-list div.conversation'
|
|
);
|
|
const activeConversation = listRef.value.querySelector(
|
|
'div.conversations-list div.conversation.active'
|
|
);
|
|
const activeConversationIndex = [...allConversations].indexOf(
|
|
activeConversation
|
|
);
|
|
const lastConversationIndex = allConversations.length - 1;
|
|
return {
|
|
allConversations,
|
|
activeConversation,
|
|
activeConversationIndex,
|
|
lastConversationIndex,
|
|
};
|
|
};
|
|
|
|
const handleConversationNavigation = direction => {
|
|
const { allConversations, activeConversationIndex, lastConversationIndex } =
|
|
getKeyboardListenerParams();
|
|
|
|
// Determine the new index based on the direction
|
|
const newIndex =
|
|
direction === 'previous'
|
|
? activeConversationIndex - 1
|
|
: activeConversationIndex + 1;
|
|
|
|
// Check if the new index is within the valid range
|
|
if (
|
|
allConversations.length > 0 &&
|
|
newIndex >= 0 &&
|
|
newIndex <= lastConversationIndex
|
|
) {
|
|
// Click the conversation at the new index
|
|
allConversations[newIndex].click();
|
|
} else if (allConversations.length > 0) {
|
|
// If the new index is out of range, click the first or last conversation based on the direction
|
|
const fallbackIndex =
|
|
direction === 'previous' ? 0 : lastConversationIndex;
|
|
allConversations[fallbackIndex].click();
|
|
}
|
|
};
|
|
const keyboardEvents = {
|
|
'Alt+KeyJ': {
|
|
action: () => handleConversationNavigation('previous'),
|
|
allowOnFocusedInput: true,
|
|
},
|
|
'Alt+KeyK': {
|
|
action: () => handleConversationNavigation('next'),
|
|
allowOnFocusedInput: true,
|
|
},
|
|
};
|
|
|
|
useKeyboardEvents(keyboardEvents);
|
|
}
|