MCPcopy Index your code
hub / github.com/monkeytypegame/monkeytype / change

Function change

frontend/src/ts/controllers/page-controller.ts:281–402  ·  view source on GitHub ↗
(
  pageName: PageName,
  options = {} as ChangeOptions,
)

Source from the content-addressed store, hash-verified

279}
280
281export 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,

Callers

nothing calls this directly

Calls 14

qsaFunction · 0.90
showSyncLoadingFunction · 0.85
updateOpenGraphUrlFunction · 0.85
setMethod · 0.80
promiseAnimateMethod · 0.80
pushMethod · 0.80
updateTitleFunction · 0.70
getMethod · 0.45
removeClassMethod · 0.45
setStyleMethod · 0.45
showMethod · 0.45
hideMethod · 0.45

Tested by

no test coverage detected