(
pageName: PageName,
options = {} as ChangeOptions,
)
| 279 | } |
| 280 | |
| 281 | export async function change( |
| 282 | pageName: PageName, |
| 283 | options = {} as ChangeOptions, |
| 284 | ): Promise<boolean> { |
| 285 | const defaultOptions = { |
| 286 | force: false, |
| 287 | }; |
| 288 | |
| 289 | options = { ...defaultOptions, ...options }; |
| 290 | |
| 291 | if (PageTransition.get() && !options.force) { |
| 292 | console.debug( |
| 293 | `change page to ${pageName} stopped, page transition is true`, |
| 294 | ); |
| 295 | return false; |
| 296 | } |
| 297 | |
| 298 | if (!options.force && getActivePage() === pageName) { |
| 299 | console.debug(`change page ${pageName} stoped, page already active`); |
| 300 | return false; |
| 301 | } else { |
| 302 | console.log(`changing page ${pageName}`); |
| 303 | } |
| 304 | |
| 305 | const previousPage = pages[getActivePage()]; |
| 306 | const nextPage = pages[pageName]; |
| 307 | const totalDuration = Misc.applyReducedMotion(250); |
| 308 | |
| 309 | //start |
| 310 | PageTransition.set(true); |
| 311 | qsa(".page")?.removeClass("active"); |
| 312 | |
| 313 | //previous page |
| 314 | await previousPage?.beforeHide?.(); |
| 315 | previousPage.element.show().setStyle({ opacity: "1" }); |
| 316 | await previousPage.element.promiseAnimate({ |
| 317 | opacity: "0", |
| 318 | duration: totalDuration / 2, |
| 319 | }); |
| 320 | previousPage.element.hide(); |
| 321 | await previousPage?.afterHide(); |
| 322 | |
| 323 | // we need to evaluate and store next page loading mode in case options.loadingOptions.loadingMode is sync |
| 324 | const nextPageLoadingMode = nextPage.loadingOptions?.loadingMode(); |
| 325 | |
| 326 | //show loading page if needed |
| 327 | try { |
| 328 | let syncLoadingOptions: LoadingOptions[] = []; |
| 329 | if (options.loadingOptions?.loadingMode() === "sync") { |
| 330 | syncLoadingOptions.push(options.loadingOptions); |
| 331 | } |
| 332 | if (nextPage.loadingOptions?.loadingMode() === "sync") { |
| 333 | syncLoadingOptions.push(nextPage.loadingOptions); |
| 334 | } |
| 335 | |
| 336 | if (syncLoadingOptions.length > 0) { |
| 337 | await showSyncLoading({ |
| 338 | loadingOptions: syncLoadingOptions, |
nothing calls this directly
no test coverage detected