Skip to content

Commit 7ff573c

Browse files
committed
feat: add 500ms delay on topbar
1 parent ed1d50c commit 7ff573c

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

assets/js/app.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -663,17 +663,24 @@ let routeUpdated = () => {
663663
// Focus.focusMain();
664664
};
665665

666+
let topBarScheduled = undefined;
667+
666668
// Show progress bar on live navigation and form submits
667669
topbar.config({
668670
barColors: { 0: "rgba(5, 150, 105, 1)" },
669671
shadowColor: "rgba(0, 0, 0, .3)",
670672
});
671673
window.addEventListener("phx:page-loading-start", (info) => {
672-
if (!window.location.search.includes("screenshot")) {
673-
topbar.show(300);
674+
if (topBarScheduled || window.location.search.includes("screenshot")) {
675+
return;
674676
}
677+
topBarScheduled = setTimeout(() => topbar.show(), 500);
678+
});
679+
window.addEventListener("phx:page-loading-stop", (info) => {
680+
clearTimeout(topBarScheduled);
681+
topBarScheduled = undefined;
682+
topbar.hide();
675683
});
676-
window.addEventListener("phx:page-loading-stop", (info) => topbar.hide());
677684

678685
// Accessible routing
679686
window.addEventListener("phx:page-loading-stop", routeUpdated);

0 commit comments

Comments
 (0)