mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 00:32:21 +00:00
ShellFeedback and the scene director show toasts through createToast(), each on its own timer as before, and the scene chrome renders the toast. Every show rewrites the text, so a repeated message is announced again.
43 lines
1.3 KiB
JavaScript
43 lines
1.3 KiB
JavaScript
import { useStatusStore } from './stores/status.js';
|
|
import { applicationPinia } from './vueRuntime.js';
|
|
|
|
// Counts every show on the page, so a repeated message is announced again.
|
|
let shown = 0;
|
|
|
|
/**
|
|
* One owner's use of the page toast, which the scene chrome renders from the
|
|
* status store. Each owner keeps its own timer, so a later toast from another
|
|
* owner is hidden when this one's time is up, as the shared element was.
|
|
* @param {object} options
|
|
* @param {number} options.durationMs How long a toast stays up.
|
|
* @param {object} [options.store] The status store.
|
|
*/
|
|
export function createToast({
|
|
durationMs,
|
|
store = useStatusStore(applicationPinia()),
|
|
}) {
|
|
let timer = null;
|
|
// The text stays while the toast fades out.
|
|
const hide = () => {
|
|
clearTimeout(timer);
|
|
timer = null;
|
|
if (store.toast?.visible)
|
|
store.publishToast({ ...store.toast, visible: false });
|
|
};
|
|
return {
|
|
/** @param {string} message */
|
|
show(message) {
|
|
store.publishToast({ text: message, visible: true, shown: ++shown });
|
|
clearTimeout(timer);
|
|
timer = setTimeout(hide, durationMs);
|
|
},
|
|
/** Hide the toast now and drop the timer. */
|
|
hide,
|
|
/** Drop the timer, leaving the toast as it is. */
|
|
cancel() {
|
|
clearTimeout(timer);
|
|
timer = null;
|
|
},
|
|
};
|
|
}
|