add archive progress styles

This commit is contained in:
qcrao
2024-07-25 16:52:23 +08:00
parent 4f9cd6a9aa
commit fd34ee6450
4 changed files with 66 additions and 26 deletions

View File

@@ -13,9 +13,20 @@ async function bulkArchiveConversations() {
sendEventAsync("archive", selectedConversations.length); sendEventAsync("archive", selectedConversations.length);
for (const element of selectedConversations) { for (let i = 0; i < selectedConversations.length; i++) {
await archiveConversation(element); await archiveConversation(selectedConversations[i]);
const progress = Math.round(((i + 1) / selectedConversations.length) * 100);
chrome.runtime.sendMessage({
action: "updateProgress",
buttonId: "bulk-archive",
progress: progress,
});
} }
chrome.runtime.sendMessage({
action: "operationComplete",
buttonId: "bulk-archive",
});
} }
function getSelectedConversations() { function getSelectedConversations() {

View File

@@ -21,11 +21,15 @@ async function bulkDeleteConversations() {
const progress = Math.round(((i + 1) / selectedConversations.length) * 100); const progress = Math.round(((i + 1) / selectedConversations.length) * 100);
chrome.runtime.sendMessage({ chrome.runtime.sendMessage({
action: "updateProgress", action: "updateProgress",
buttonId: "bulk-delete",
progress: progress, progress: progress,
}); });
} }
chrome.runtime.sendMessage({ action: "deleteComplete" }); chrome.runtime.sendMessage({
action: "operationComplete",
buttonId: "bulk-delete",
});
} }
function getSelectedConversations() { function getSelectedConversations() {

View File

@@ -353,8 +353,17 @@ button#bulk-delete {
transition: background-color 0.3s ease; transition: background-color 0.3s ease;
} }
button#bulk-archive {
background-color: #9b59b6;
color: white;
position: relative;
overflow: hidden;
transition: background-color 0.3s ease;
}
/* New styles for progress bar */ /* New styles for progress bar */
button#bulk-delete::before { button#bulk-delete::before,
button#bulk-archive::before {
content: ""; content: "";
position: absolute; position: absolute;
top: 0; top: 0;
@@ -366,26 +375,34 @@ button#bulk-delete::before {
transition: transform 0.3s ease-out; transition: transform 0.3s ease-out;
} }
button#bulk-delete::after { button#bulk-delete::after,
button#bulk-archive::after {
content: attr(data-progress) "%"; content: attr(data-progress) "%";
position: absolute; position: absolute;
top: 50%; top: 50%;
left: 50%; left: 50%;
transform: translate(-50%, -50%); transform: translate(-50%, -50%);
color: white; color: rgb(149, 20, 20);
font-weight: bold; font-weight: bold;
z-index: 1; z-index: 100;
} }
button#bulk-delete.progress { button#bulk-delete.progress,
button#bulk-archive.progress {
cursor: not-allowed; cursor: not-allowed;
background-color: #34495e; /* Darker background when in progress */ background-color: #34495e; /* Darker background when in progress */
} }
button#bulk-delete.progress::before { button#bulk-delete.progress::before,
button#bulk-archive.progress::before {
transform: translateX(var(--progress, -100%)); transform: translateX(var(--progress, -100%));
} }
button#bulk-delete.progress::before,
button#bulk-archive.progress::before {
animation: pulse 2s infinite;
}
/* Add a pulsing animation to the progress bar */ /* Add a pulsing animation to the progress bar */
@keyframes pulse { @keyframes pulse {
0% { 0% {
@@ -398,7 +415,3 @@ button#bulk-delete.progress::before {
opacity: 1; opacity: 1;
} }
} }
button#bulk-delete.progress::before {
animation: pulse 2s infinite;
}

View File

@@ -21,7 +21,7 @@ function addButtonListener(buttonId, scriptName) {
chrome.tabs.query({ active: true, currentWindow: true }, ([tab]) => { chrome.tabs.query({ active: true, currentWindow: true }, ([tab]) => {
if (tab) { if (tab) {
if (buttonId === "bulk-delete") { if (buttonId === "bulk-delete") {
const bulkDeleteButton = document.getElementById("bulk-delete"); const bulkDeleteButton = document.getElementById(buttonId);
bulkDeleteButton.disabled = true; bulkDeleteButton.disabled = true;
bulkDeleteButton.classList.add("progress"); bulkDeleteButton.classList.add("progress");
@@ -34,18 +34,20 @@ function addButtonListener(buttonId, scriptName) {
}); });
} }
function updateProgressBar(progress) { function updateProgressBar(buttonId, progress) {
console.log("Updating progress bar:", progress); console.log(`Updating progress bar for ${buttonId}:`, progress);
const bulkDeleteButton = document.getElementById("bulk-delete"); const button = document.getElementById(buttonId);
bulkDeleteButton.style.setProperty("--progress", `${progress}%`); button.style.setProperty("--progress", `${progress}%`);
bulkDeleteButton.setAttribute("data-progress", progress); button.setAttribute("data-progress", progress);
if (progress === 100 || progress === 0) { if (progress === 100 || progress === 0) {
bulkDeleteButton.disabled = false; button.disabled = false;
bulkDeleteButton.classList.remove("progress"); button.classList.remove("progress");
bulkDeleteButton.textContent = "Bulk Delete"; // Reset button text button.textContent =
buttonId === "bulk-delete" ? "Bulk Delete" : "Bulk Archive";
} else { } else {
bulkDeleteButton.textContent = "Deleting..."; // Change button text during deletion button.textContent =
buttonId === "bulk-delete" ? "Deleting..." : "Archiving...";
} }
} }
@@ -53,9 +55,12 @@ function updateProgressBar(progress) {
chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) { chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
console.log("Received message:", request); console.log("Received message:", request);
if (request.action === "updateProgress") { if (request.action === "updateProgress") {
updateProgressBar(request.progress); updateProgressBar(request.buttonId, request.progress);
} else if (request.action === "deleteComplete") { } else if (request.action === "operationComplete") {
updateProgressBar(0); // This will reset the button text const button = document.getElementById(request.buttonId);
button.disabled = false;
button.classList.remove("progress");
updateProgressBar(request.buttonId, 0);
} }
}); });
@@ -113,6 +118,9 @@ async function handleBulkArchive() {
if (localIsPaid) { if (localIsPaid) {
chrome.tabs.query({ active: true, currentWindow: true }, ([tab]) => { chrome.tabs.query({ active: true, currentWindow: true }, ([tab]) => {
if (tab) { if (tab) {
const bulkArchiveButton = document.getElementById("bulk-archive");
bulkArchiveButton.disabled = true;
bulkArchiveButton.classList.add("progress");
loadGlobalsThenExecute(tab.id, "bulkArchiveConversations.js"); loadGlobalsThenExecute(tab.id, "bulkArchiveConversations.js");
} }
}); });
@@ -136,6 +144,10 @@ async function handleBulkArchive() {
if (data.isPaid) { if (data.isPaid) {
chrome.tabs.query({ active: true, currentWindow: true }, ([tab]) => { chrome.tabs.query({ active: true, currentWindow: true }, ([tab]) => {
if (tab) { if (tab) {
const bulkArchiveButton = document.getElementById("bulk-archive");
bulkArchiveButton.disabled = true;
bulkArchiveButton.classList.add("progress");
loadGlobalsThenExecute(tab.id, "bulkArchiveConversations.js"); loadGlobalsThenExecute(tab.id, "bulkArchiveConversations.js");
} }
}); });