|
| 1 | +import React, { useState } from "react"; |
| 2 | + |
| 3 | +import { BrowserRouter as Router, Route, Switch } from "react-router-dom"; |
| 4 | +import Header from "./components/header/Header"; |
| 5 | +import Footer from "./components/footer/Footer"; |
| 6 | +import Home from "./pages/Home"; |
| 7 | +import Simulator from "./pages/Simulator"; |
| 8 | +import FullSimulator from "./pages/simulator/FullSimulator"; |
| 9 | +import Releases from "./pages/Releases"; |
| 10 | +import Policy from "./pages/Policy"; |
| 11 | +import Install from "./pages/Install"; |
| 12 | +import IDEMain from "./pages/IDE"; |
| 13 | +import IDEEditor from "./pages/omega-ide/src/ide/Editor"; |
| 14 | +import IDESimulator from "./pages/omega-ide/src/ide/Simulator"; |
| 15 | +import NotFound from "./pages/NotFound"; |
| 16 | +import GithubConnector from "./GithubConnector"; |
| 17 | +import CookiesConsent from "./components/cookiesconsent/CookiesConsent"; |
| 18 | + |
| 19 | +import { IntlProvider } from "react-intl"; |
| 20 | +import translations from "./i18n/locales"; |
| 21 | +import classNames from "classnames"; |
| 22 | +import { getCookie, setCookie } from "./cookies"; |
| 23 | + |
| 24 | +import "./sass/omega.library.sass"; |
| 25 | + |
| 26 | +function App() { |
| 27 | + const getLang = () => { |
| 28 | + if (navigator.languages !== undefined) return navigator.languages[0]; |
| 29 | + else return navigator.language; |
| 30 | + }; |
| 31 | + |
| 32 | + let initLang: any = localStorage.getItem("locale"); |
| 33 | + if (initLang == null) initLang = getLang(); |
| 34 | + if (!(initLang in translations)) { |
| 35 | + initLang = "en"; |
| 36 | + } |
| 37 | + |
| 38 | + const [theme, setTheme] = useState(getCookie("theme") || "light"); |
| 39 | + const [lang, setLang] = useState(initLang); |
| 40 | + // @ts-ignore |
| 41 | + const [messages, setMessages] = useState(translations[initLang]); |
| 42 | + |
| 43 | + const onChangeLanguage = (lang: string) => { |
| 44 | + localStorage.setItem("locale", lang); |
| 45 | + setLang(lang); |
| 46 | + // @ts-ignore |
| 47 | + setMessages(translations[lang]); |
| 48 | + }; |
| 49 | + |
| 50 | + const toggleTheme = () => { |
| 51 | + var newTheme = theme === "light" ? "dark" : "light"; |
| 52 | + |
| 53 | + setTheme(newTheme); |
| 54 | + setCookie("theme", newTheme); |
| 55 | + }; |
| 56 | + |
| 57 | + return ( |
| 58 | + <IntlProvider locale={lang} messages={messages}> |
| 59 | + <Router> |
| 60 | + <div className={classNames("body", theme)}> |
| 61 | + {!window.location.pathname.includes("/simulator/run") && ( |
| 62 | + <React.Fragment> |
| 63 | + <CookiesConsent linkToPolicy="/policy" /> |
| 64 | + <Header theme={theme} toggleTheme={toggleTheme} /> |
| 65 | + </React.Fragment> |
| 66 | + )} |
| 67 | + <Switch> |
| 68 | + <Route path="/simulator" component={Simulator} exact /> |
| 69 | + <Route |
| 70 | + path="/simulator/run/full" |
| 71 | + component={FullSimulator} |
| 72 | + exact |
| 73 | + /> |
| 74 | + <Route path="/releases" component={Releases} exact /> |
| 75 | + {/* <Route path="/beta" component={Beta} exact /> */} |
| 76 | + <Route path="/install" component={Install} exact /> |
| 77 | + <Route path="/install/:version" component={Install} /> |
| 78 | + <Route path="/policy" component={Policy} exact /> |
| 79 | + <Route path="/ide/" component={IDEMain} exact /> |
| 80 | + <Route |
| 81 | + path="/ide/editor" |
| 82 | + component={() => ( |
| 83 | + <IDEEditor |
| 84 | + base="/ide/" |
| 85 | + connector={GithubConnector} |
| 86 | + vercel={true} |
| 87 | + /> |
| 88 | + )} |
| 89 | + exact |
| 90 | + /> |
| 91 | + <Route |
| 92 | + path="/ide/simulator" |
| 93 | + component={IDESimulator} |
| 94 | + exact |
| 95 | + /> |
| 96 | + {/* <Route path="/wiki" component={Wiki} exact /> */} |
| 97 | + <Route |
| 98 | + path="/" |
| 99 | + component={() => <Home theme={theme} />} |
| 100 | + exact |
| 101 | + /> |
| 102 | + <Route component={NotFound} /> |
| 103 | + </Switch> |
| 104 | + {!window.location.pathname.includes("/simulator/run") && ( |
| 105 | + <Footer |
| 106 | + locale={lang} |
| 107 | + onChangeLanguage={onChangeLanguage} |
| 108 | + /> |
| 109 | + )} |
| 110 | + </div> |
| 111 | + </Router> |
| 112 | + </IntlProvider> |
| 113 | + ); |
| 114 | +} |
| 115 | + |
| 116 | +export default App; |
0 commit comments