Skip to content

Commit

Permalink
Merge pull request #95 from Alokit-Innovations/tr/TriggerButton
Browse files Browse the repository at this point in the history
Add Trigger button to popup
  • Loading branch information
avikalpg authored Mar 29, 2024
2 parents 472910c + a797b5e commit 90f6559
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 11 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Vibinex Code Review",
"version": "1.2.0",
"version": "1.2.1",
"manifest_version": 3,
"description": "Personalization and context for pull requests on GitHub & Bitbucket",
"key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsRm6EaBdHDBxVjt9o9WKeL9EDdz1X+knDAU5uoZaRsXTmWjslhJN9DhSd7/Ys4aJOSN+s+5/HnIHcKV63P4GYaUM5FhETHEWORHlwIgjcV/1h6wD6bNbvXi06gtiygE+yMrCzzD93/Z+41XrwMElYiW2U5owNpat2Yfq4p9FDX1uBJUKsRIMp6LbRQla4vAzH/HMUtHWmeuUsmPVzcq1b6uB1QmuJqIQ1GrntIHw3UBWUlqRZ5OtxI1DCP3knglvqz26WT5Pc4GBDNlcI9+3F0vhwqwHqrdyjZpIKZ7iaQzcrovOqUKuXs1J3hDtXq8WoJELIqfIisY7rhAvq6b8jQIDAQAB",
Expand Down
4 changes: 4 additions & 0 deletions popup/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ <h1 id="session-name" class="title"></h1>
<small>(Logout)</small>
</button>
</form>
<div id="pr-input-div">
<input type="text" id="pr-url-input" placeholder="Ex: https://github.com/Alokit-Innovations/vibi-dpu/pull/1">
<button id="pr-url-submit-button" class="button">Trigger!</button>
</div>
<a href="https://www.producthunt.com/products/vibinex-code-review/reviews?utm_source=badge-product_review&utm_medium=badge&utm_souce=badge-vibinex&#0045;code&#0045;review"
target="_blank">
<img src="https://api.producthunt.com/widgets/embed-image/v1/product_review.svg?product_id=534479&theme=light"
Expand Down
55 changes: 45 additions & 10 deletions popup/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ chrome.storage.local.get(["websiteUrl"]).then(({ websiteUrl }) => {
document.querySelector("#session-image").src = user.image;
document.querySelector("#session-name").innerHTML = user.name;
document.querySelector("#session-email").innerHTML = user.email;

// Retrieve the session token from the cookie and store user details in Chrome's local storage.
let tokenval = "";
chrome.cookies.get({ url: websiteUrl, name: '__Secure-next-auth.session-token' })
.then((cookie) => {
const tokenval = cookie.value;
tokenval = cookie.value;
chrome.storage.local.set({
userId: user.id,
userName: user.name,
Expand All @@ -68,16 +68,51 @@ chrome.storage.local.get(["websiteUrl"]).then(({ websiteUrl }) => {
.catch((err) => {
console.error("Unable to get Cookie value for session: ", err);
});
} else {
// If no user session exists, display the login options.
document.querySelector("#login-div").style.display = "flex";
}
});

// Add event listener to the submit button
const submitButton = document.getElementById("pr-url-submit-button");
submitButton.addEventListener("click", () => {
submitButton.disabled = true;
const urlInput = document.getElementById("pr-url-input");
const url = urlInput.value.trim();
if (url === "") {
console.error("[popup/submitButton] URL cannot be empty");
submitButton.textContent = "Empty URL! Try Again";
return;
}
// Send the inputted URL through a POST call to an API
fetch(`${websiteUrl}/api/extension/trigger`, {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${tokenval}`
},
body: JSON.stringify({ url: url })
}).then(response => {
if (response.ok) {
console.info("[popup/submitButton] URL submitted successfully");
submitButton.textContent = "Triggered!";
} else {
submitButton.disabled = false;
console.error("[popup/submitButton] Failed to submit URL", JSON.stringify(response));
submitButton.textContent = "Failed! Try Again";
}
}).catch(error => {
submitButton.disabled = false;
console.error("[popup/submitButton] Error while submitting URL:", error);
submitButton.textContent = "Failed! Try Again";
});
});
} else {
// If no user session exists, display the login options.
document.querySelector("#login-div").style.display = "flex";
}
});
});

// Display the extension version on window load.
window.addEventListener('load', () => {
const manifestData = chrome.runtime.getManifest();
const version_p = document.getElementById("version");
version_p.innerHTML = "v" + manifestData.version;
const manifestData = chrome.runtime.getManifest();
const version_p = document.getElementById("version");
version_p.innerHTML = "v" + manifestData.version;
});

0 comments on commit 90f6559

Please sign in to comment.