Skip to content

Commit

Permalink
reordered modules
Browse files Browse the repository at this point in the history
  • Loading branch information
AMushegh committed Oct 12, 2023
1 parent 0453537 commit 90aeead
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 17 deletions.
18 changes: 9 additions & 9 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import React, { useEffect, useState } from "react";
import { useController } from "@hooks/useController";
import { InjectionToken } from "./constants/injection-token";
import { bootstrap } from "@/utils/bootstrap";

type PropsType = {
children: React.ReactNode;
};

const App = ({ children }: PropsType) => {
const [isAuthChecked, setIsAuthChecked] = useState<boolean>(false);
const { appReady } = useController<IAuthController>(
InjectionToken.IAuthController
);
const [appReady, setAppReady] = useState<boolean>(false);

useEffect(() => {
appReady();
setIsAuthChecked(true);
const boot = async () => {
const res = await bootstrap();
setAppReady(res);
};

boot();
}, []);

if (!isAuthChecked) {
if (!appReady) {
return <h1>Loading...</h1>;
}

Expand Down
File renamed without changes.
5 changes: 1 addition & 4 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@ import "reflect-metadata";
import React from "react";
import { createRoot } from "react-dom/client";

import { AppRoutes } from "@routes/AppRoutes";
import App from "@/App";

import "@/index.css";
import { AppRoutes } from "./modules/shared/routes/components/AppRoutes";
import { injectDeps } from "./utils/bootstrap";

injectDeps();

const root = createRoot(document.getElementById("root")!);

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React from "react";
import { Navigate, Route, Routes } from "react-router-dom";

import { CustomBrowserRouter } from "./CustomRouter";
import { CustomBrowserRouter } from "@routes/CustomRouter";
import { Login } from "@/modules/shared/auth/components/Login";
import { ProtectedRoute } from "./ProtectedRoute";
import { Game } from "@/modules/game/components/Game";
import { Layout } from "@/modules/shared/Layout";
import { Layout } from "@/Layout";

export const AppRoutes = () => {
return (
Expand Down
File renamed without changes.
File renamed without changes.
21 changes: 20 additions & 1 deletion src/utils/bootstrap.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { container, Lifecycle } from "tsyringe";

import { InjectionToken } from "@/constants/injection-token";
import { HistoryService } from "@/modules/shared/routes/HistoryService";
import { HistoryService } from "@/modules/shared/history/HistoryService";
import { useGameStore } from "@/modules/game/useGameStore";
import { GameService } from "@/modules/game/GameService";
import { GameController } from "@/modules/game/GameController";
Expand Down Expand Up @@ -55,3 +55,22 @@ export function injectDeps() {
useValue: useGameStore,
});
}

const initServices = () => {
const authService = container.resolve<IAuthService>(
InjectionToken.IAuthService
);

authService.setAuthStateOnAppReady();
};

export const bootstrap = async () => {
try {
injectDeps();
initServices();

return true;
} catch (e) {
throw new Error(e);
}
};
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"@/*": ["*"],
"@hooks/*": ["utils/hooks/*"],
"@history": ["utils/history"],
"@helpers": ["utils/helpers"]
"@helpers": ["utils/helpers"],
"@routes/*": ["routes/*"]
},
"typeRoots": ["@types", "node_modules/@types"]
},
Expand Down

0 comments on commit 90aeead

Please sign in to comment.