Skip to content
Snippets Groups Projects
Commit 793f8876 authored by ambient.impact's avatar ambient.impact
Browse files

Issue #3488464: Moved progress bar delay custom prop to delay component:

This also required altering the hide and finish methods/logic to return
Promises so external calls can know when they've finished doing async
stuff. It's still a bit messy but hopefully less so than before.
parent 5aca822e
No related branches found
No related tags found
1 merge request!10Issue #3488464: Implemented our own progress bar; removed Turbo progress
...@@ -12,6 +12,29 @@ ...@@ -12,6 +12,29 @@
'use strict'; 'use strict';
/**
* CSS custom property base name.
*
* @type {String}
*/
const customPropertyBase = '--refreshless-progress-bar';
/**
* Name of the CSS custom property containing the progress bar delay.
*
* The value will be a time in ms.
*
* @type {String}
*/
const delayCustomProperty = `${customPropertyBase}-delay`;
/**
* The <html> element.
*
* @type {HTMLHtmlElement}
*/
const html = document.documentElement;
/** /**
* Represents a progress bar delay wrapper. * Represents a progress bar delay wrapper.
*/ */
...@@ -53,6 +76,26 @@ ...@@ -53,6 +76,26 @@
} }
/**
* Install the progress bar in the document and set various properties.
*/
install() {
html.style.setProperty(
delayCustomProperty, `${this.#delay}ms`,
);
}
/**
* Uninstall the progress bar from the document and remove properties.
*/
uninstall() {
html.style.removeProperty(delayCustomProperty);
}
/** /**
* Start the timeout to show the progress bar. * Start the timeout to show the progress bar.
* *
...@@ -68,11 +111,15 @@ ...@@ -68,11 +111,15 @@
window.clearTimeout(timeoutId); window.clearTimeout(timeoutId);
} }
this.#progressBar.setValue(0); this.install();
return window.setTimeout( return window.setTimeout(async () => {
() => { this.#progressBar.show() }, this.#delay,
); await this.#progressBar.setValue(0);
this.#progressBar.show();
}, this.#delay);
} }
...@@ -89,13 +136,11 @@ ...@@ -89,13 +136,11 @@
return timeoutId; return timeoutId;
} }
this.#progressBar.setValue(1);
this.#progressBar.hide();
window.clearTimeout(timeoutId); window.clearTimeout(timeoutId);
timeoutId = null timeoutId = null;
this.#progressBar.finish().then(() => this.uninstall());
return timeoutId; return timeoutId;
......
...@@ -45,15 +45,6 @@ ...@@ -45,15 +45,6 @@
*/ */
const durationCustomProperty = `${customPropertyBase}-transition-duration`; const durationCustomProperty = `${customPropertyBase}-transition-duration`;
/**
* Name of the CSS custom property containing the progress bar delay.
*
* The value will be a time in ms.
*
* @type {String}
*/
const delayCustomProperty = `${customPropertyBase}-delay`;
/** /**
* Name of the CSS custom property containing the current progress bar value. * Name of the CSS custom property containing the current progress bar value.
* *
...@@ -142,23 +133,29 @@ ...@@ -142,23 +133,29 @@
/** /**
* Hide the progress bar if visible and not already hiding. * Hide the progress bar if visible and not already hiding.
*
* @return {Promise}
*/ */
hide() { hide() {
if (!(this.#visible === true && this.#hiding === false)) { if (!(this.#visible === true && this.#hiding === false)) {
return; return Promise.resolve();
} }
this.#hiding = true; this.#hiding = true;
this.stopTrickling(); this.stopTrickling();
this.#transitionOut().then(() => { return new Promise(async (resolve, reject) => {
await this.#transitionOut();
this.uninstall(); this.uninstall();
this.#visible = false; this.#visible = false;
this.#hiding = false; this.#hiding = false;
resolve();
}); });
} }
...@@ -224,7 +221,7 @@ ...@@ -224,7 +221,7 @@
this.#value = value; this.#value = value;
this.refresh(); return this.refresh();
} }
...@@ -237,10 +234,6 @@ ...@@ -237,10 +234,6 @@
durationCustomProperty, `${this.#transitionDuration}ms`, durationCustomProperty, `${this.#transitionDuration}ms`,
); );
html.style.setProperty(
delayCustomProperty, `${Turbo.session.progressBarDelay}ms`,
);
html.style.setProperty(valueCustomProperty, 0); html.style.setProperty(valueCustomProperty, 0);
this.#setInactive(); this.#setInactive();
...@@ -266,7 +259,6 @@ ...@@ -266,7 +259,6 @@
this.#element.remove(); this.#element.remove();
} }
html.style.removeProperty(delayCustomProperty);
html.style.removeProperty(durationCustomProperty); html.style.removeProperty(durationCustomProperty);
html.style.removeProperty(valueCustomProperty); html.style.removeProperty(valueCustomProperty);
...@@ -319,16 +311,12 @@ ...@@ -319,16 +311,12 @@
} }
/** /**
* Finish/complete the progress bar to 100% and start hiding it. * Finish/complete the progress bar by setting to 100% and start hiding it.
* *
* @return {[type]} [description] * @return {Promise}
*/ */
finish() { finish() {
return this.setValue(1).then(() => this.hide());
this.setValue(1);
this.hide();
} }
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment