diff --git a/client/src/modules/contentmanager.js b/client/src/modules/contentmanager.js index 0659d372..22afb863 100644 --- a/client/src/modules/contentmanager.js +++ b/client/src/modules/contentmanager.js @@ -13,6 +13,7 @@ import { FileUtils, ClientLogger as Logger } from 'common'; import path from 'path'; import { Events } from 'modules'; import { Error } from 'structs'; +import { Modals } from 'ui'; export default class { @@ -48,8 +49,8 @@ export default class { } if (this.errors.length) { - Events.emit('bd-error', { - header: `${this.moduleName} - one or more ${this.contentType}(s) failed to load`, + Modals.error({ + header: `${this.moduleName} - ${this.errors.length} ${this.contentType}${this.errors.length !== 1 ? 's' : ''} failed to load`, module: this.moduleName, type: 'err', content: this.errors diff --git a/client/src/styles/partials/generic/modals.scss b/client/src/styles/partials/generic/modals.scss index 2ae89057..a2dca7ff 100644 --- a/client/src/styles/partials/generic/modals.scss +++ b/client/src/styles/partials/generic/modals.scss @@ -16,6 +16,19 @@ } } +.bd-modal-wrap { + transition: all 0.2s ease; + width: 100%; + height: 100%; + position: absolute; + z-index: 9000; + + .bd-modal-close-area { + width: 100%; + height: 100%; + } +} + .bd-modal { position: fixed; align-content: space-around; diff --git a/client/src/ui/components/bd/BdModals.vue b/client/src/ui/components/bd/BdModals.vue index 61e7995f..e95d9306 100644 --- a/client/src/ui/components/bd/BdModals.vue +++ b/client/src/ui/components/bd/BdModals.vue @@ -8,66 +8,50 @@ * LICENSE file in the root directory of this source tree. */ - diff --git a/client/src/ui/components/bd/modals/ErrorModal.vue b/client/src/ui/components/bd/modals/ErrorModal.vue new file mode 100644 index 00000000..8764248b --- /dev/null +++ b/client/src/ui/components/bd/modals/ErrorModal.vue @@ -0,0 +1,47 @@ + + + diff --git a/client/src/ui/modals.js b/client/src/ui/modals.js new file mode 100644 index 00000000..7cbc1bc6 --- /dev/null +++ b/client/src/ui/modals.js @@ -0,0 +1,66 @@ +/** + * BetterDiscord Modals + * Copyright (c) 2015-present Jiiks/JsSucks - https://github.com/Jiiks / https://github.com/JsSucks + * All rights reserved. + * https://betterdiscord.net + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. +*/ + +import { FileUtils } from 'common'; +import { Events } from 'modules'; +import BasicModal from './components/bd/modals/BasicModal.vue'; +import ErrorModal from './components/bd/modals/ErrorModal.vue'; + +export default class Modals { + + static add(modal, component) { + modal.component = modal.component || { + template: '', + components: { 'custom-modal': component }, + data() { return { modal }; }, + created() { modal.vue = this; } + }; + modal.closing = false; + modal.close = () => this.close(modal); + + this.stack.push(modal); + Events.emit('bd-refresh-modals'); + return modal; + } + + static close(modal) { + return new Promise((resolve, reject) => { + modal.closing = true; + setTimeout(() => { + this._stack = this.stack.filter(m => m !== modal); + Events.emit('bd-refresh-modals'); + resolve(); + }, 200); + }); + } + + static closeAll() { + for (let modal of this.stack) + modal.close(); + } + + static closeLast() { + if (!this.stack.length) return; + this.stack[this.stack.length - 1].close(); + } + + static basic(title, text) { + return this.add({ title, text }, BasicModal); + } + + static error(event) { + return this.add({ event }, ErrorModal); + } + + static get stack() { + return this._stack ? this._stack : (this._stack = []); + } + +} diff --git a/client/src/ui/ui.js b/client/src/ui/ui.js index e17a542e..4a24e0cb 100644 --- a/client/src/ui/ui.js +++ b/client/src/ui/ui.js @@ -1,4 +1,5 @@ export { default as DOM } from './dom'; export { default as BdUI } from './bdui'; export { default as VueInjector } from './vueinjector'; +export { default as Modals } from './modals'; export { default as ProfileBadges } from './profilebadges';