fix: TypeError cannot read properties of undefined (reading 'click') (#10067)
Fixes https://linear.app/chatwoot/issue/CW-3535/typeerror-cannot-read-properties-of-undefined-reading-click
This commit is contained in:
@@ -117,35 +117,41 @@ export default {
|
|||||||
lastConversationIndex,
|
lastConversationIndex,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
const handlePreviousConversation = () => {
|
const handleConversationNavigation = direction => {
|
||||||
const { allConversations, activeConversationIndex } =
|
|
||||||
getKeyboardListenerParams();
|
|
||||||
if (activeConversationIndex === -1) {
|
|
||||||
allConversations[0].click();
|
|
||||||
}
|
|
||||||
if (activeConversationIndex >= 1) {
|
|
||||||
allConversations[activeConversationIndex - 1].click();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
const handleNextConversation = () => {
|
|
||||||
const {
|
const {
|
||||||
allConversations,
|
allConversations,
|
||||||
activeConversationIndex,
|
activeConversationIndex,
|
||||||
lastConversationIndex,
|
lastConversationIndex,
|
||||||
} = getKeyboardListenerParams();
|
} = getKeyboardListenerParams();
|
||||||
if (activeConversationIndex === -1) {
|
|
||||||
allConversations[lastConversationIndex].click();
|
// Determine the new index based on the direction
|
||||||
} else if (activeConversationIndex < lastConversationIndex) {
|
const newIndex =
|
||||||
allConversations[activeConversationIndex + 1].click();
|
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 = {
|
const keyboardEvents = {
|
||||||
'Alt+KeyJ': {
|
'Alt+KeyJ': {
|
||||||
action: () => handlePreviousConversation(),
|
action: () => handleConversationNavigation('previous'),
|
||||||
allowOnFocusedInput: true,
|
allowOnFocusedInput: true,
|
||||||
},
|
},
|
||||||
'Alt+KeyK': {
|
'Alt+KeyK': {
|
||||||
action: () => handleNextConversation(),
|
action: () => handleConversationNavigation('next'),
|
||||||
allowOnFocusedInput: true,
|
allowOnFocusedInput: true,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user