Skip to content

Commit

Permalink
Refreshed the page once successfully configured webhooks
Browse files Browse the repository at this point in the history
  • Loading branch information
Roger Cortez committed Jul 14, 2024
1 parent 2532d8d commit ed22cf9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion server/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ router.get('/', async function(req, res, next) {
});

router.get('/webhook/config', async (req, res) => {
const { repo, hassetwebhook } = req.query;
const { repo, hassetwebhook} = req.query;
try {
const githubUsername = req.session.user[0].github_username;
const githubToken = req.session.user[0].github_token;
Expand Down
33 changes: 17 additions & 16 deletions server/views/index.pug
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ block content
document.getElementById('repoActionButton').innerText = "Revoke"
// Update the href attribute of the button
//- document.getElementById('repoWebhookAction').href = `/webhook/config?repo=${repoName}&hassetwebhook=true`;
document.getElementById('repoActionButton').setAttribute('onclick', `handleRepoAction('${repoName}', true)`);
document.getElementById('repoActionButton').setAttribute('onclick', `handleRepoAction('${repoName}', true, ${currentPage}, ${perPage})`);

} else {
document.getElementById('repoWebhookStatus').innerText = "You haven't set up linkedin-auto-post for the repository ";
Expand All @@ -212,31 +212,32 @@ block content

document.getElementById('repoActionButton').innerText = "Set Now"
//- document.getElementById('repoWebhookAction').href = `/webhook/config?repo=${repoName}&hassetwebhook=false`;
document.getElementById('repoActionButton').setAttribute('onclick', `handleRepoAction('${repoName}', false)`);
document.getElementById('repoActionButton').setAttribute('onclick', `handleRepoAction('${repoName}', false, ${currentPage}, ${perPage})`);
}
//- document.getElementById('repoNameModal').innerText = repoName + " - Do you want to modify it?";
const modal = document.getElementById('repoModal');
modal.style.display = 'flex';
}

function handleRepoAction(repoName, hasSetWebhook) {
function handleRepoAction(repoName, hasSetWebhook, currentPage, perPage) {
fetch(`/webhook/config?repo=${repoName}&hassetwebhook=${hasSetWebhook}`)
.then(response => response.json())
.then(data => {
if (data.success) {
const repoCard = document.querySelector(`.card-body[data-repo-name="${repoName}"]`);
const webhookIcon = repoCard.querySelector('.bi-check2-all');
if (hasSetWebhook) {
if (webhookIcon) webhookIcon.remove();
} else {
if (!webhookIcon) {
const icon = document.createElement('i');
icon.className = 'bi bi-check2-all';
icon.style = 'font-weight: bolder; font-size: 24px; color: green;';
repoCard.querySelector('h5.card-title').appendChild(icon);
}
}
repoCard.setAttribute('webhook-repo-status', data.hasSetWebhook);
//- const repoCard = document.querySelector(`.card-body[data-repo-name="${repoName}"]`);
//- const webhookIcon = repoCard.querySelector('.bi-check2-all');
//- if (hasSetWebhook) {
//- if (webhookIcon) webhookIcon.remove();
//- } else {
//- if (!webhookIcon) {
//- const icon = document.createElement('i');
//- icon.className = 'bi bi-check2-all';
//- icon.style = 'font-weight: bolder; font-size: 24px; color: green;';
//- repoCard.querySelector('h5.card-title').appendChild(icon);
//- }
//- }
//- repoCard.setAttribute('webhook-repo-status', data.hasSetWebhook);
window.location.href = `/?page=${currentPage}&per_page=${perPage}`;
document.getElementById('repoModal').style.display = 'none';
}
})
Expand Down

0 comments on commit ed22cf9

Please sign in to comment.