Skip to content

Commit

Permalink
Create HTML templates for modals (#1425)
Browse files Browse the repository at this point in the history
* reuse modals

* refactor

* only load templates when needed

* lint

* shared-modals

* lint

* type

* lint

* lint
  • Loading branch information
khaitruong922 authored Oct 5, 2024
1 parent 9d549ec commit 0d1b36e
Show file tree
Hide file tree
Showing 8 changed files with 1,503 additions and 1,819 deletions.
4 changes: 2 additions & 2 deletions ext/js/display/search-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ await Application.main(true, async (application) => {
const searchDisplayController = new SearchDisplayController(display, displayAudio, searchPersistentStateController);
await searchDisplayController.prepare();

const modalController = new ModalController();
modalController.prepare();
const modalController = new ModalController([]);
await modalController.prepare();

const settingsController = new SettingsController(application);
await settingsController.prepare();
Expand Down
4 changes: 2 additions & 2 deletions ext/js/pages/permissions-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ function setupPermissionsToggles() {
}

await Application.main(true, async (application) => {
const modalController = new ModalController();
modalController.prepare();
const modalController = new ModalController([]);
await modalController.prepare();

const settingsController = new SettingsController(application);
await settingsController.prepare();
Expand Down
20 changes: 18 additions & 2 deletions ext/js/pages/settings/modal-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,34 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

import {HtmlTemplateCollection} from '../../dom/html-template-collection.js';
import {Modal} from './modal.js';

export class ModalController {
constructor() {
/**
* @param {string[]} templateNames
*/
constructor(templateNames) {
/** @type {Modal[]} */
this._modals = [];
/** @type {Map<string|Element, Modal>} */
this._modalMap = new Map();
/** @type {HtmlTemplateCollection} */
this._templates = new HtmlTemplateCollection();
/** @type {string[]} */
this._templateNames = templateNames;
}

/** */
prepare() {
async prepare() {
if (this._templateNames.length > 0) {
await this._templates.loadFromFiles(['/templates-modals.html']);
for (const name of this._templateNames) {
const template = this._templates.getTemplateContent(name);
document.body.appendChild(template);
}
}

const idSuffix = '-modal';
for (const node of /** @type {NodeListOf<HTMLElement>} */ (document.querySelectorAll('.modal'))) {
let {id} = node;
Expand Down
4 changes: 2 additions & 2 deletions ext/js/pages/settings/settings-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ await Application.main(true, async (application) => {

const preparePromises = [];

const modalController = new ModalController();
modalController.prepare();
const modalController = new ModalController(['shared-modals', 'settings-modals']);
await modalController.prepare();

const settingsController = new SettingsController(application);
await settingsController.prepare();
Expand Down
4 changes: 2 additions & 2 deletions ext/js/pages/welcome-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ async function checkNeedsCustomTemplatesWarning() {
}

await Application.main(true, async (application) => {
const modalController = new ModalController();
modalController.prepare();
const modalController = new ModalController(['shared-modals']);
await modalController.prepare();

const settingsController = new SettingsController(application);
await settingsController.prepare();
Expand Down
1,476 changes: 0 additions & 1,476 deletions ext/settings.html

Large diffs are not rendered by default.

1,477 changes: 1,477 additions & 0 deletions ext/templates-modals.html

Large diffs are not rendered by default.

333 changes: 0 additions & 333 deletions ext/welcome.html

Large diffs are not rendered by default.

0 comments on commit 0d1b36e

Please sign in to comment.