From ed22cf9e2d34071431dea437cf20273b4f315672 Mon Sep 17 00:00:00 2001 From: Roger Cortez Date: Sun, 14 Jul 2024 09:12:55 +0800 Subject: [PATCH] Refreshed the page once successfully configured webhooks --- server/routes/index.js | 2 +- server/views/index.pug | 33 +++++++++++++++++---------------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/server/routes/index.js b/server/routes/index.js index 6e156f2..03ac749 100644 --- a/server/routes/index.js +++ b/server/routes/index.js @@ -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; diff --git a/server/views/index.pug b/server/views/index.pug index f54f8fe..84b9895 100644 --- a/server/views/index.pug +++ b/server/views/index.pug @@ -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 "; @@ -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'; } })