Merge pull request #4812 from thornbill/fix-view-container-unmount

This commit is contained in:
Bill Thornton 2023-09-29 07:56:24 -04:00 committed by GitHub
commit b1ddf81164
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3,11 +3,7 @@ import './viewManager/viewContainer.scss';
import Dashboard from '../utils/dashboard';
const getMainAnimatedPages = () => {
if (!mainAnimatedPages) {
mainAnimatedPages = document.querySelector('.mainAnimatedPages');
}
return mainAnimatedPages;
return document.querySelector('.mainAnimatedPages');
};
function setControllerClass(view, options) {
@ -61,7 +57,9 @@ export function loadView(options) {
view.classList.add('mainAnimatedPage');
if (!getMainAnimatedPages()) {
const mainAnimatedPages = getMainAnimatedPages();
if (!mainAnimatedPages) {
console.warn('[viewContainer] main animated pages element is not present');
return;
}
@ -187,6 +185,7 @@ export function setOnBeforeChange(fn) {
}
export function tryRestoreView(options) {
console.debug('[viewContainer] tryRestoreView', options);
const url = options.url;
const index = currentUrls.indexOf(url);
@ -232,14 +231,15 @@ function triggerDestroy(view) {
}
export function reset() {
console.debug('[viewContainer] resetting view cache');
allPages = [];
currentUrls = [];
const mainAnimatedPages = getMainAnimatedPages();
if (mainAnimatedPages) mainAnimatedPages.innerHTML = '';
selectedPageIndex = -1;
}
let onBeforeChange;
let mainAnimatedPages;
let allPages = [];
let currentUrls = [];
const pageContainerCount = 3;
@ -248,8 +248,8 @@ reset();
getMainAnimatedPages()?.classList.remove('hide');
export default {
loadView: loadView,
tryRestoreView: tryRestoreView,
reset: reset,
setOnBeforeChange: setOnBeforeChange
loadView,
tryRestoreView,
reset,
setOnBeforeChange
};