From f5bb1a239550cd75d461f586aa05a289bde7793b Mon Sep 17 00:00:00 2001 From: Miodec Date: Mon, 19 Jun 2023 21:34:21 +0200 Subject: [PATCH] removed unnecessary imports from page controller --- .../src/ts/controllers/page-controller.ts | 14 ++++---- .../src/ts/controllers/route-controller.ts | 35 +++++++++---------- 2 files changed, 23 insertions(+), 26 deletions(-) diff --git a/frontend/src/ts/controllers/page-controller.ts b/frontend/src/ts/controllers/page-controller.ts index 3e967bcb3..074d4293d 100644 --- a/frontend/src/ts/controllers/page-controller.ts +++ b/frontend/src/ts/controllers/page-controller.ts @@ -21,7 +21,7 @@ interface ChangeOptions { } export async function change( - page: Page, + pageName: MonkeyTypes.PageName, options = {} as ChangeOptions ): Promise { const defaultOptions = { @@ -33,19 +33,19 @@ export async function change( return new Promise((resolve) => { if (PageTransition.get()) { console.debug( - `change page to ${page.name} stopped, page transition is true` + `change page to ${pageName} stopped, page transition is true` ); return resolve(false); } - if (!options.force && ActivePage.get() === page.name) { - console.debug(`change page ${page.name} stoped, page already active`); + if (!options.force && ActivePage.get() === pageName) { + console.debug(`change page ${pageName} stoped, page already active`); return resolve(false); } else { - console.log(`changing page ${page.name}`); + console.log(`changing page ${pageName}`); } - const pages: Record = { + const pages: Record = { loading: PageLoading.page, test: PageTest.page, settings: Settings.page, @@ -58,7 +58,7 @@ export async function change( }; const previousPage = pages[ActivePage.get()]; - const nextPage = page; + const nextPage = pages[pageName]; previousPage?.beforeHide(); PageTransition.set(true); diff --git a/frontend/src/ts/controllers/route-controller.ts b/frontend/src/ts/controllers/route-controller.ts index 94edddcac..d04a7e803 100644 --- a/frontend/src/ts/controllers/route-controller.ts +++ b/frontend/src/ts/controllers/route-controller.ts @@ -1,20 +1,10 @@ import * as PageController from "./page-controller"; -import * as PageTest from "../pages/test"; -import * as PageAbout from "../pages/about"; -import * as PageSettings from "../pages/settings"; -import * as PageAccount from "../pages/account"; -import * as PageLogin from "../pages/login"; -import * as Page404 from "../pages/404"; -import * as PageProfile from "../pages/profile"; import * as Leaderboards from "../elements/leaderboards"; import * as TestUI from "../test/test-ui"; import * as PageTransition from "../states/page-transition"; import * as NavigateEvent from "../observables/navigate-event"; import { Auth } from "../firebase"; -//this is the only one that is using nav (through navigation event) - maybe consider removing this circular somehow to get rid of the nav event -import * as PageProfileSearch from "../pages/profile-search"; - //source: https://www.youtube.com/watch?v=OstALBk-jTc // https://www.youtube.com/watch?v=OstALBk-jTc @@ -49,17 +39,24 @@ interface Route { ) => void; } +const route404: Route = { + path: "404", + load: (): void => { + PageController.change("404"); + }, +}; + const routes: Route[] = [ { path: "/", load: (): void => { - PageController.change(PageTest.page); + PageController.change("test"); }, }, { path: "/verify", load: (): void => { - PageController.change(PageTest.page); + PageController.change("test"); }, }, // { @@ -74,13 +71,13 @@ const routes: Route[] = [ { path: "/about", load: (): void => { - PageController.change(PageAbout.page); + PageController.change("about"); }, }, { path: "/settings", load: (): void => { - PageController.change(PageSettings.page); + PageController.change("settings"); }, }, { @@ -94,7 +91,7 @@ const routes: Route[] = [ nav("/account"); return; } - PageController.change(PageLogin.page); + PageController.change("login"); }, }, { @@ -104,7 +101,7 @@ const routes: Route[] = [ nav("/"); return; } - PageController.change(PageAccount.page, { + PageController.change("account", { data: options.data, }); }, @@ -112,13 +109,13 @@ const routes: Route[] = [ { path: "/profile", load: (_params): void => { - PageController.change(PageProfileSearch.page); + PageController.change("profileSearch"); }, }, { path: "/profile/:uidOrName", load: (params, options): void => { - PageController.change(PageProfile.page, { + PageController.change("profile", { force: true, params: { uidOrName: params["uidOrName"], @@ -160,7 +157,7 @@ async function router(options = {} as NavigateOptions): Promise { }; if (!match) { - PageController.change(Page404.page); + route404.load({}, {}); return; }