import { computed , observable } from "mobx" ; import LoadAction from "../classes/status/LoadAction" ; import ErrorAction from "../classes/status/ErrorAction" ; import StatusActionQueue from "../classes/status/StatusActionQueue" ; import StatusAction from "../classes/status/StatusAction" ; export default class AppStatusStore { @ observable public showLoadingQueue = false ; @ observable public loadingQueue : StatusActionQueue < LoadAction > = new StatusActionQueue < LoadAction > ( ) ; @ observable public statusQueue : StatusActionQueue < StatusAction > = new StatusActionQueue < StatusAction > ( ) ; @ observable public errors : StatusActionQueue < ErrorAction > = new StatusActionQueue < ErrorAction > ( ) ; @ computed get isVisible ( ) { return ! ( this . loadingQueue . isEmpty && this . errors . isEmpty && this . statusQueue . isEmpty ) ; } public status ( action ) { this . statusQueue . add ( action ) ; } public removeStatus ( action ) { this . statusQueue . remove ( action ) ; } public load ( action ) { this . loadingQueue . add ( action ) ; } public loadStatusUpdate ( actionKey , max , current ) { const savedAction = this . loadingQueue . getAction ( actionKey ) ; if ( savedAction ) { savedAction . setStatus ( max , current ) ; this . loadingQueue = this . loadingQueue . update ( savedAction ) ; } } public loadComplete ( action ) { this . loadingQueue . remove ( action ) ; } public error ( error ) { this . errors . add ( error ) ; } public acknowledgeError ( error ) { this . errors . remove ( error ) ; } }