2021-03-06 10:40:31 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2021 lingdocs.com
|
|
|
|
*
|
2022-11-05 11:38:40 +00:00
|
|
|
* This source code is licensed under the GPLv3 license found in the
|
2021-03-06 10:40:31 +00:00
|
|
|
* LICENSE file in the root directory of this source tree.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2021-10-11 00:39:59 +00:00
|
|
|
import { useState } from "react";
|
2023-02-04 12:20:48 +00:00
|
|
|
import { Route, Routes, useNavigate } from "react-router-dom";
|
2021-03-06 10:40:31 +00:00
|
|
|
import "./App.css";
|
|
|
|
import Page404 from "./pages/404";
|
|
|
|
import Chapter from "./components/Chapter";
|
|
|
|
import { content } from "./content/index";
|
|
|
|
import Sidebar from "./components/Sidebar";
|
|
|
|
import Header from "./components/Header";
|
2021-04-14 12:31:13 +00:00
|
|
|
import TableOfContentsPage from "./pages/TableOfContentsPage";
|
2022-09-10 19:10:54 +00:00
|
|
|
import LandingPage from "./pages/LandingPage";
|
2021-09-19 00:08:06 +00:00
|
|
|
import AccountPage from "./pages/AccountPage";
|
2021-03-06 10:40:31 +00:00
|
|
|
import { useEffect } from "react";
|
2022-05-11 03:52:31 +00:00
|
|
|
import { isProd } from "./lib/isProd";
|
2021-06-25 13:56:57 +00:00
|
|
|
import ReactGA from "react-ga";
|
2021-09-27 02:28:43 +00:00
|
|
|
import { useUser } from "./user-context";
|
2022-09-16 13:27:24 +00:00
|
|
|
import PrivacyPolicy from "./pages/PrivacyPolicy";
|
2023-02-14 07:52:25 +00:00
|
|
|
import SearchPage from "./pages/SearchPage";
|
2023-02-09 07:56:17 +00:00
|
|
|
|
2021-03-06 10:40:31 +00:00
|
|
|
const chapters = content.reduce((chapters, item) => (
|
|
|
|
item.content
|
|
|
|
? [...chapters, item]
|
|
|
|
: [...chapters, ...item.chapters]
|
|
|
|
), []);
|
|
|
|
|
2022-05-11 03:52:31 +00:00
|
|
|
if (isProd) {
|
2021-06-25 13:56:57 +00:00
|
|
|
ReactGA.initialize("UA-196576671-2");
|
|
|
|
ReactGA.set({ anonymizeIp: true });
|
|
|
|
}
|
|
|
|
|
2023-02-13 20:10:41 +00:00
|
|
|
function App() {
|
2021-03-06 10:40:31 +00:00
|
|
|
const [navOpen, setNavOpen] = useState(false);
|
2023-02-13 20:10:41 +00:00
|
|
|
// const [search, setSearch] = useState("");
|
2023-02-04 12:20:48 +00:00
|
|
|
const navigate = useNavigate();
|
2021-09-27 02:28:43 +00:00
|
|
|
const { user } = useUser();
|
2021-10-18 04:50:24 +00:00
|
|
|
function logAnalytics() {
|
2022-05-11 03:52:31 +00:00
|
|
|
if (isProd && !(user?.admin)) {
|
2021-10-18 04:50:24 +00:00
|
|
|
ReactGA.pageview(window.location.pathname);
|
|
|
|
};
|
|
|
|
}
|
2021-08-04 09:58:50 +00:00
|
|
|
useEffect(() => {
|
2021-10-18 04:50:24 +00:00
|
|
|
logAnalytics();
|
2023-02-04 12:20:48 +00:00
|
|
|
if (window.location.pathname === "/") {
|
2022-10-05 07:55:24 +00:00
|
|
|
if (localStorage.getItem("visitedOnce")) {
|
2023-02-04 12:20:48 +00:00
|
|
|
navigate("/table-of-contents", { replace: true })
|
2022-10-05 07:55:24 +00:00
|
|
|
} else {
|
|
|
|
localStorage.setItem("visitedOnce", "true");
|
|
|
|
}
|
|
|
|
}
|
2021-10-18 05:00:02 +00:00
|
|
|
// eslint-disable-next-line
|
2021-08-04 09:58:50 +00:00
|
|
|
}, []);
|
2021-03-06 10:40:31 +00:00
|
|
|
useEffect(() => {
|
|
|
|
window.scroll(0, 0);
|
2021-10-18 04:50:24 +00:00
|
|
|
logAnalytics();
|
2021-10-18 05:00:02 +00:00
|
|
|
// eslint-disable-next-line
|
2023-02-04 12:20:48 +00:00
|
|
|
}, [window.location.pathname]);
|
2021-03-06 10:40:31 +00:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Header setNavOpen={setNavOpen} />
|
|
|
|
<div className="container-fluid">
|
2023-02-14 07:52:25 +00:00
|
|
|
<div className="main-row row" style={{ minHeight: "calc(100vh - 62px)" }}>
|
2021-03-06 10:40:31 +00:00
|
|
|
<Sidebar
|
|
|
|
content={content}
|
|
|
|
navOpen={navOpen}
|
|
|
|
setNavOpen={setNavOpen}
|
2023-02-04 12:20:48 +00:00
|
|
|
pathname={window.location.pathname}
|
2021-03-06 10:40:31 +00:00
|
|
|
/>
|
2023-02-04 12:20:48 +00:00
|
|
|
<Routes>
|
|
|
|
<Route
|
|
|
|
path="/"
|
|
|
|
element={<LandingPage />}
|
|
|
|
/>
|
2023-02-14 07:52:25 +00:00
|
|
|
<Route
|
|
|
|
path="/search"
|
|
|
|
element={<SearchPage />}
|
|
|
|
/>
|
2023-02-04 12:20:48 +00:00
|
|
|
<Route
|
|
|
|
path="/privacy"
|
|
|
|
element={<PrivacyPolicy />}
|
|
|
|
/>
|
|
|
|
<Route
|
|
|
|
path="/table-of-contents"
|
|
|
|
element={<TableOfContentsPage />}
|
|
|
|
/>
|
2021-09-18 04:43:00 +00:00
|
|
|
{chapters.map((chapter: any) => (
|
2023-02-04 12:20:48 +00:00
|
|
|
<Route
|
|
|
|
key={chapter.path}
|
|
|
|
path={chapter.path}
|
|
|
|
element={<Chapter>{chapter}</Chapter>}
|
|
|
|
/>
|
2021-03-06 10:40:31 +00:00
|
|
|
))}
|
2023-02-04 12:20:48 +00:00
|
|
|
<Route
|
|
|
|
path="/account"
|
|
|
|
element={<AccountPage />}
|
|
|
|
/>
|
|
|
|
<Route path="*" element={<Page404 />} />
|
|
|
|
</Routes>
|
2021-03-06 10:40:31 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-02-04 12:20:48 +00:00
|
|
|
export default App;
|