Skip to content

Commit 51d0036

Browse files
committed
chat selecting rework #8
1 parent a089e59 commit 51d0036

File tree

1 file changed

+39
-22
lines changed

1 file changed

+39
-22
lines changed

popup/popup.js

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,41 @@ chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
2020
meetId = url.split('?')[0].split('/').pop();
2121
});
2222

23+
const reactToSelectedChats = () => {
24+
// remove the class selectedChatStart and selectedChatEnd from all the divs
25+
const chatInstances = document.querySelectorAll(".youChatInstance, .interviewerChatInstance");
26+
chatInstances.forEach(chatInstance => {
27+
chatInstance.classList.remove("selectedChatStart");
28+
chatInstance.classList.remove("selectedChatEnd");
29+
});
30+
// find the startChat and endChat divs and add the class selectedChatStart and selectedChatEnd respectively
31+
if (startChat !== null) {
32+
const startChatInstance = document.querySelector(`[ticid="${chat[startChat].ticId}"]`);
33+
startChatInstance.classList.add("selectedChatStart");
34+
}
35+
if (endChat !== null) {
36+
const endChatInstance = document.querySelector(`[ticid="${chat[endChat].ticId}"]`);
37+
endChatInstance.classList.add("selectedChatEnd");
38+
}
39+
40+
startContentEx.innerText = startChat !== null ? chat[startChat].content : "";
41+
endContentEx.innerText = endChat !== null ? chat[endChat].content : "";
42+
43+
if (startChat !== null && endChat !== null) {
44+
generateResponseBtn.disabled = false;
45+
} else {
46+
generateResponseBtn.disabled = true;
47+
}
48+
}
49+
2350
const generateResponseBtn = document.getElementById("gernerateResponse");
2451
// add event listener to the button of id gernerateResponse
2552
generateResponseBtn.addEventListener("click", function () {
2653
// send a message to the service worker of type "GENERATE_RESPONSE" with the startChat and endChat
2754
chrome.runtime.sendMessage({ type: "GET_RESPONSE", data: { meetId, startChat, endChat } });
55+
startChat = null;
56+
endChat = null;
57+
reactToSelectedChats();
2858
})
2959

3060

@@ -34,31 +64,18 @@ const selectChatInstance = (targetChatInstanceElement) => {
3464
const chatIndex = chat.findIndex(chatInstance => chatInstance.ticId === targetTicId);
3565
if (startChat === null) {
3666
startChat = chatIndex;
37-
targetChatInstanceElement.classList.add("selectedChatStart");
3867
} else if (endChat === null) {
39-
endChat = chatIndex;
40-
targetChatInstanceElement.classList.add("selectedChatEnd");
41-
} else {
42-
// find startChat and endChat divs and remove their respective classes
43-
const startChatDiv = document.querySelector(`[ticId="${chat[startChat].ticId}"]`);
44-
const endChatDiv = document.querySelector(`[ticId="${chat[endChat].ticId}"]`);
45-
startChatDiv.classList.remove("selectedChatStart");
46-
endChatDiv.classList.remove("selectedChatEnd");
47-
startChat = null;
48-
endChat = null;
49-
}
50-
51-
console.log("startChat", startChat, "endChat", endChat)
52-
// updated the startContentEx and endContentEx with the content of the chatInstance
53-
startContentEx.innerText = startChat !== null ? chat[startChat].content : "";
54-
endContentEx.innerText = endChat !== null ? chat[endChat].content : "";
55-
// if both start chat and end chat exist then enable the generateResponseBtn
56-
if (startChat !== null && endChat !== null) {
57-
generateResponseBtn.disabled = false;
68+
if (chatIndex < startChat) {
69+
startChat = chatIndex;
70+
} else {
71+
endChat = chatIndex;
72+
}
5873
} else {
59-
generateResponseBtn.disabled = true;
74+
startChat = null
75+
endChat = null
6076
}
61-
77+
78+
reactToSelectedChats();
6279
}
6380

6481

0 commit comments

Comments
 (0)