Skip to content

Commit

Permalink
Merge pull request #112 from rogershi-dev/feature/registration-auth
Browse files Browse the repository at this point in the history
Retained user's scroll position for restoring it once the page refres…
  • Loading branch information
rogershi-dev authored Jul 14, 2024
2 parents 2dbb168 + 38f9967 commit 17ebfab
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions server/views/index.pug
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,9 @@ block content
}

function handleRepoAction(repoName, hasSetWebhook, currentPage, perPage) {
// Save the scroll position
const scrollY = window.scrollY;

fetch(`/webhook/config?repo=${repoName}&hassetwebhook=${hasSetWebhook}&page=${currentPage}&per_page=${perPage}`)
.then(response => response.json())
.then(data => {
Expand All @@ -239,6 +242,9 @@ block content
//- }
//- repoCard.setAttribute('webhook-repo-status', data.hasSetWebhook);

// Store the scroll position in localStorage
localStorage.setItem("scrollY", scrollY);
// Refresh the page
window.location.href = `/?page=${currentPage}&per_page=${perPage}`;
document.getElementById('repoModal').style.display = 'none';
}
Expand All @@ -262,3 +268,11 @@ block content
modal.style.display = 'none';
}
});

document.addEventListener('DOMContentLoaded', (event) => {
const scrollY = localStorage.getItem('scrollY');
if (scrollY) {
window.scrollTo(0, parseInt(scrollY, 10));
localStorage.removeItem('scrollY'); // Clean up after restoring
}
});

0 comments on commit 17ebfab

Please sign in to comment.