Skip to content

Commit

Permalink
perf: optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
rimorin committed May 23, 2024
1 parent fde3982 commit 91e9b4d
Show file tree
Hide file tree
Showing 23 changed files with 6,944 additions and 6,778 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"env": {
"browser": true,
"es2021": true
"es2021": true,
"node": true
},
"extends": [
"eslint:recommended",
Expand Down
File renamed without changes.
13,393 changes: 6,745 additions & 6,648 deletions package-lock.json

Large diffs are not rendered by default.

48 changes: 24 additions & 24 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@
"name": "ministry-mapper",
"version": "1.25.6",
"private": true,
"type": "module",
"dependencies": {
"@ebay/nice-modal-react": "^1.2.13",
"@rollbar/react": "^0.11.2",
"@types/node": "^20.12.11",
"@types/node": "^20.12.12",
"@types/react": "^18.3.2",
"@types/react-calendar": "^3.9.0",
"@types/react-dom": "^18.3.0",
"@types/react-router-dom": "^5.3.3",
"@vis.gl/react-google-maps": "^1.0.0",
"bootstrap": "^5.3.3",
"firebase": "^10.11.1",
"eslint": "^8.56.0",
"firebase": "^10.12.1",
"nanoid": "^5.0.7",
"react": "^18.3.1",
"react-bootstrap": "^2.10.2",
Expand All @@ -24,8 +26,7 @@
"react-password-checklist": "^1.6.0",
"react-router-dom": "^6.23.1",
"react-select": "^5.8.0",
"rollbar": "^2.26.4",
"web-vitals": "^3.5.2"
"rollbar": "^2.26.4"
},
"scripts": {
"start": "vite",
Expand Down Expand Up @@ -61,48 +62,47 @@
"devDependencies": {
"@commitlint/cli": "^19.3.0",
"@commitlint/config-conventional": "^19.2.2",
"@eslint/js": "^9.2.0",
"@eslint/js": "^9.3.0",
"@semantic-release/changelog": "^6.0.3",
"@semantic-release/git": "^10.0.1",
"@storybook/addon-essentials": "^8.0.10",
"@storybook/addon-interactions": "^8.0.10",
"@storybook/addon-links": "^8.0.10",
"@storybook/addon-onboarding": "^8.0.10",
"@storybook/addon-essentials": "^8.1.2",
"@storybook/addon-interactions": "^8.1.2",
"@storybook/addon-links": "^8.1.2",
"@storybook/addon-onboarding": "^8.1.2",
"@storybook/addon-styling": "^1.3.7",
"@storybook/blocks": "^8.0.10",
"@storybook/blocks": "^8.1.2",
"@storybook/jest": "^0.2.3",
"@storybook/manager-api": "^8.0.10",
"@storybook/react": "^8.0.10",
"@storybook/react-vite": "^8.0.10",
"@storybook/test-runner": "^0.18.0",
"@storybook/manager-api": "^8.1.2",
"@storybook/react": "^8.1.2",
"@storybook/react-vite": "^8.1.2",
"@storybook/test-runner": "^0.18.1",
"@storybook/testing-library": "^0.2.2",
"@storybook/theming": "^8.0.10",
"@storybook/theming": "^8.1.2",
"@testing-library/jest-dom": "^6.4.5",
"@testing-library/react": "^15.0.7",
"@testing-library/user-event": "^14.5.2",
"@typescript-eslint/eslint-plugin": "^7.8.0",
"@typescript-eslint/parser": "^7.8.0",
"@typescript-eslint/eslint-plugin": "^7.10.0",
"@typescript-eslint/parser": "^7.10.0",
"@vitejs/plugin-react": "^4.2.1",
"chromatic": "^11.3.2",
"eslint": "^8.57.0",
"chromatic": "^11.4.0",
"eslint-plugin-react": "^7.34.1",
"eslint-plugin-react-hooks": "^4.6.2",
"eslint-plugin-storybook": "^0.8.0",
"husky": "^9.0.11",
"jest-worker": "^29.7.0",
"jsdom": "^24.0.0",
"lint-staged": "^15.2.2",
"lint-staged": "^15.2.4",
"prettier": "^3.2.5",
"pretty-quick": "^4.0.0",
"rollup-plugin-visualizer": "^5.12.0",
"sass": "^1.77.1",
"sass": "^1.77.2",
"semantic-release": "^23.1.1",
"sharp": "^0.33.3",
"storybook": "^8.0.10",
"sharp": "^0.33.4",
"storybook": "^8.1.2",
"storybook-mock-date-decorator": "^1.0.2",
"svgo": "^3.3.2",
"typescript": "^5.4.5",
"typescript-eslint": "^7.8.0",
"typescript-eslint": "^7.10.0",
"unplugin-turbo-console": "^1.8.6",
"vite": "^5.2.11",
"vite-plugin-checker": "^0.6.4",
Expand Down
18 changes: 18 additions & 0 deletions src/components/middlewares/googlemap.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { FC, ReactNode } from "react";

import { APIProvider } from "@vis.gl/react-google-maps";
interface MapsMiddlewareProps {
children: ReactNode;
}

const MapsMiddleware: FC<MapsMiddlewareProps> = ({ children }) => {
const { VITE_GOOGLE_MAPS_API_KEY } = import.meta.env;
if (!VITE_GOOGLE_MAPS_API_KEY) {
return <div>Missing Google Maps API Key</div>;
}
return (
<APIProvider apiKey={VITE_GOOGLE_MAPS_API_KEY}>{children}</APIProvider>
);
};

export default MapsMiddleware;
17 changes: 17 additions & 0 deletions src/components/middlewares/main.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { FC, ReactNode } from "react";
import { Container } from "react-bootstrap";
import VersionDisplay from "../navigation/versiondisplay";
interface MainMiddlewareProps {
children: ReactNode;
}

const MainMiddleware: FC<MainMiddlewareProps> = ({ children }) => {
return (
<Container className="pt-2" fluid>
{children}
<VersionDisplay />
</Container>
);
};

export default MainMiddleware;
35 changes: 35 additions & 0 deletions src/components/middlewares/maintenance.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { FC, useState, useEffect, ReactNode, Suspense, lazy } from "react";
import { child, onValue, ref } from "firebase/database";
import { database } from "../../firebase";
import Loader from "../statics/loader";
const MaintenanceMode = lazy(() => import("../statics/maintenance"));

interface MaintenanceMiddlewareProps {
children: ReactNode;
}

const MaintenanceMiddleware: FC<MaintenanceMiddlewareProps> = ({
children
}) => {
const [isMaintenance, setIsMaintenance] = useState<boolean>(false);

useEffect(() => {
const maintenanceReference = child(ref(database), `/maintenance`);
onValue(maintenanceReference, (snapshot) => {
if (snapshot.exists()) {
setIsMaintenance(snapshot.val());
}
});
}, []);

if (isMaintenance)
return (
<Suspense fallback={<Loader />}>
<MaintenanceMode />
</Suspense>
);

return <>{children}</>;
};

export default MaintenanceMiddleware;
30 changes: 30 additions & 0 deletions src/components/middlewares/rollbar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Provider } from "@rollbar/react";
import { FC, ReactNode } from "react";

interface RollbarProviderProps {
children: ReactNode;
}

const { VITE_ROLLBAR_ACCESS_TOKEN, VITE_ROLLBAR_ENVIRONMENT, VITE_VERSION } =
import.meta.env;

const DEFEAULT_ROLLBAR_ENVIRONMENT = "staging";

const rollbarConfig = {
accessToken: VITE_ROLLBAR_ACCESS_TOKEN,
payload: {
environment: VITE_ROLLBAR_ENVIRONMENT || DEFEAULT_ROLLBAR_ENVIRONMENT,
client: {
javascript: {
source_map_enabled: true,
code_version: VITE_VERSION
}
}
}
};

const RollbarMiddleware: FC<RollbarProviderProps> = ({ children }) => {
return <Provider config={rollbarConfig}>{children}</Provider>;
};

export default RollbarMiddleware;
2 changes: 1 addition & 1 deletion src/components/modal/changepassword.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const ChangePassword = NiceModal.create(
alert("Password updated.");
modal.hide();
} catch (error) {
errorHandler(errorMessage((error as FirebaseError).code), rollbar);
errorHandler(errorMessage(error as FirebaseError), rollbar);
} finally {
setIsSaving(false);
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/modal/inviteuser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const InviteUser = NiceModal.create(
alert(`Granted ${roleDisplay} access to ${userEmail}.`);
modal.hide();
} catch (error) {
errorHandler(errorMessage((error as FirebaseError).code), rollbar);
errorHandler(errorMessage(error as FirebaseError), rollbar);
} finally {
setIsSaving(false);
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/modal/profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const GetProfile = NiceModal.create(({ user }: UpdateProfileModalProps) => {
alert("Profile updated.");
modal.hide();
} catch (error) {
errorHandler(errorMessage((error as FirebaseError).code), rollbar);
errorHandler(errorMessage(error as FirebaseError), rollbar);
} finally {
setIsSaving(false);
}
Expand Down
11 changes: 11 additions & 0 deletions src/components/navigation/versiondisplay.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { FC } from "react";

const VersionDisplay: FC = () => {
return (
<div className="fixed-bottom text-muted opacity-25 m-2">
<>v{import.meta.env.VITE_VERSION}</>
</div>
);
};

export default VersionDisplay;
19 changes: 10 additions & 9 deletions src/firebase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,18 @@ declare global {
var FIREBASE_APPCHECK_DEBUG_TOKEN: boolean | string | undefined;
}
const {
VITE_FIREBASE_API_KEY,
VITE_FIREBASE_AUTH_DOMAIN,
VITE_FIREBASE_DB_URL,
VITE_FIREBASE_PROJECT_ID,
VITE_FIREBASE_BUCKET,
VITE_FIREBASE_SENDER_ID,
VITE_FIREBASE_APP_ID,
VITE_FIREBASE_APPCHECK_DEBUG_TOKEN,
VITE_FIREBASE_API_KEY = "",
VITE_FIREBASE_AUTH_DOMAIN = "",
VITE_FIREBASE_DB_URL = "",
VITE_FIREBASE_PROJECT_ID = "",
VITE_FIREBASE_BUCKET = "",
VITE_FIREBASE_SENDER_ID = "",
VITE_FIREBASE_APP_ID = "",
VITE_FIREBASE_APPCHECK_DEBUG_TOKEN = false,
VITE_FIREBASE_RECAPTCHA_ENTERPRISE_SITE_KEY,
VITE_FIREBASE_FUNCTIONS_REGION
VITE_FIREBASE_FUNCTIONS_REGION = DEFAULT_FB_CLOUD_FUNCTIONS_REGION
} = import.meta.env;

global.FIREBASE_APPCHECK_DEBUG_TOKEN =
VITE_FIREBASE_APPCHECK_DEBUG_TOKEN || false;

Expand Down
35 changes: 6 additions & 29 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,45 +1,22 @@
import { createRoot } from "react-dom/client";
import Main from "./pages/index";
import reportWebVitals from "./reportWebVitals";
import { BrowserRouter } from "react-router-dom";
import { StrictMode } from "react";
import { Provider } from "@rollbar/react";
import NiceModal from "@ebay/nice-modal-react";
import { APIProvider } from "@vis.gl/react-google-maps";
const { VITE_ROLLBAR_ACCESS_TOKEN, VITE_ROLLBAR_ENVIRONMENT, VITE_VERSION } =
import.meta.env;

const DEFEAULT_ROLLBAR_ENVIRONMENT = "staging";

const rollbarConfig = {
accessToken: VITE_ROLLBAR_ACCESS_TOKEN,
payload: {
environment: VITE_ROLLBAR_ENVIRONMENT || DEFEAULT_ROLLBAR_ENVIRONMENT,
client: {
javascript: {
source_map_enabled: true,
code_version: VITE_VERSION
}
}
}
};
import RollbarMiddleware from "./components/middlewares/rollbar";
import MapsMiddleware from "./components/middlewares/googlemap";

const root = createRoot(document.getElementById("root") as HTMLElement);
root.render(
<StrictMode>
<Provider config={rollbarConfig}>
<APIProvider apiKey={import.meta.env.VITE_GOOGLE_MAPS_API_KEY}>
<RollbarMiddleware>
<MapsMiddleware>
<NiceModal.Provider>
<BrowserRouter>
<Main />
</BrowserRouter>
</NiceModal.Provider>
</APIProvider>
</Provider>
</MapsMiddleware>
</RollbarMiddleware>
</StrictMode>
);

// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();
1 change: 1 addition & 0 deletions src/pages/dashboard/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useState, useEffect, lazy } from "react";
import "react-calendar/dist/Calendar.css";
import { auth } from "../../firebase";
import Loader from "../../components/statics/loader";
import { sendEmailVerification, signOut, User } from "firebase/auth";
Expand Down
2 changes: 1 addition & 1 deletion src/pages/frontpage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const FrontPage = () => {
setIsCreate(false);
} catch (err) {
setValidated(false);
errorHandler(errorMessage((err as FirebaseError).code), rollbar);
errorHandler(errorMessage(err as FirebaseError), rollbar);
} finally {
setIsCreating(false);
}
Expand Down
Loading

0 comments on commit 91e9b4d

Please sign in to comment.