Skip to content

Commit 89e87cd

Browse files
authored
Don't update the whole segment list on time update (#1569)
Update segment element classes instead. This probably is more efficient than what we're doing currently. Also, this seems to fix a bug where the vote confirmation/error msg is removed immediately
1 parent 311c4ca commit 89e87cd

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

src/popup.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,7 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
614614
const votingButtons = document.createElement("details");
615615
votingButtons.classList.add("votingButtons");
616616
votingButtons.id = "votingButtons" + UUID;
617+
votingButtons.setAttribute("data-uuid", UUID);
617618
votingButtons.addEventListener("toggle", () => {
618619
if (votingButtons.open) {
619620
openedUUIDs.push(UUID);
@@ -1068,10 +1069,37 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
10681069
port.onMessage.addListener((msg) => onMessage(msg));
10691070
}
10701071

1072+
function updateCurrentTime(currentTime: number) {
1073+
// Create a map of segment UUID -> segment object for easy access
1074+
const segmentMap: Record<string, SponsorTime> = {};
1075+
for (const segment of downloadedTimes)
1076+
segmentMap[segment.UUID] = segment
1077+
1078+
// Iterate over segment elements and update their classes
1079+
const segmentList = document.getElementById("issueReporterTimeButtons");
1080+
for (const segmentElement of segmentList.children) {
1081+
const UUID = segmentElement.getAttribute("data-uuid");
1082+
if (UUID == null || segmentMap[UUID] == undefined) continue;
1083+
1084+
const summaryElement = segmentElement.querySelector("summary")
1085+
if (summaryElement == null) continue;
1086+
1087+
const segment = segmentMap[UUID]
1088+
summaryElement.classList.remove("segmentActive", "segmentPassed")
1089+
if (currentTime >= segment.segment[0]) {
1090+
if (currentTime < segment.segment[1]) {
1091+
summaryElement.classList.add("segmentActive");
1092+
} else {
1093+
summaryElement.classList.add("segmentPassed");
1094+
}
1095+
}
1096+
}
1097+
}
1098+
10711099
function onMessage(msg: PopupMessage) {
10721100
switch (msg.message) {
10731101
case "time":
1074-
displayDownloadedSponsorTimes(downloadedTimes, msg.time);
1102+
updateCurrentTime(msg.time);
10751103
break;
10761104
case "infoUpdated":
10771105
infoFound(msg);

0 commit comments

Comments
 (0)