Ignore:
Timestamp:
2021-12-09T16:15:55+13:00 (2 years ago)
Author:
cstephen
Message:

Add external timeout selection to Snackbar

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/model-interfaces-dev/atea/macron-restoration/src/components/Snackbar.vue

    r35756 r35784  
    5050
    5151export class SnackController {
     52    /**
     53     * The internal snack queue. Do not manipulate externally.
     54     * @type {Array<{c: String, t: Number}>}
     55     */
    5256    static queue = [];
     57
     58    /**
     59     * The Snackbar Vue component used by this controller.
     60     */
    5361    static bar = null;
     62
     63    /**
     64     * A value defining whether or not a snackbar is active. Do not manipulate externally.
     65     */
    5466    static isActive = false;
    5567
     68    /**
     69     * Sets the Snackbar Vue component that this controller should use.
     70     */
    5671    static setBar(snackBar) {
    5772        this.bar = snackBar;
    5873    }
    5974
    60     static addSnack(content) {
    61         this.queue.push(content);
     75    /**
     76     * Adds a snack to the queue.
     77     * @param {String} content The message of the snackbar.
     78     * @param {Number} timeoutMS The time in milliseconds for which the snack will be displayed.
     79     */
     80    static addSnack(content, timeoutMS = 3000) {
     81        this.queue.push({
     82            c: content,
     83            t: timeoutMS
     84        });
    6285
    6386        if (!this.isActive) {
     
    6689    }
    6790
     91    /**
     92     * Do not use this method externally.
     93     */
    6894    static eatSnacks() {
    6995        if (this.isActive || this.queue.length === 0) {
     
    7298
    7399        this.isActive = true;
    74         this.bar.setContent(this.queue.shift());
     100        const { c, t } = this.queue.shift();
     101        this.bar.setContent(c, t);
    75102
    76103        setTimeout(function() {
    77104            SnackController.isActive = false;
    78105            SnackController.eatSnacks();
    79         }, 3500);
     106        }, t + 500);
    80107    }
    81108}
Note: See TracChangeset for help on using the changeset viewer.