You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
2.6 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. import React, {useContext, useLayoutEffect} from 'react';
  2. import {HookRouter, navigate, usePath, useRoutes} from "hookrouter";
  3. import {Page, Tabs} from "./primitives/Layout";
  4. import {IconElement} from "./primitives/Elements";
  5. import SettingsPage from "./pages/SettingsPage";
  6. import {LuciferIcon} from "./models/Icons";
  7. import ReactModal from "react-modal";
  8. import DialogContext, {DialogContextProvider, makeDialog} from "./contexts/DialogContext";
  9. const routeObj: HookRouter.RouteObject = {
  10. "/": () => (
  11. <Page>
  12. <h1>&nbsp;</h1>
  13. <h1>Enheter</h1>
  14. </Page>
  15. ),
  16. "/devices": () => (
  17. <div>
  18. <IconElement icon={LuciferIcon.Hexagon} caption="Grønn" color={{h: 125, s: 0.5}}/>
  19. <IconElement icon={LuciferIcon.Square} caption="Kelvin 1k" color={{kelvin: 1000}}/>
  20. <IconElement icon={LuciferIcon.Bulb} caption="Kelvin 2k" color={{kelvin: 2000}}/>
  21. <IconElement icon={LuciferIcon.BulbGroup} caption="Kelvin 3k" color={{kelvin: 3000}}/>
  22. <IconElement icon={LuciferIcon.Bridge} caption="Kelvin 4k" color={{kelvin: 4000}}/>
  23. <IconElement icon={LuciferIcon.Cog} caption="Kelvin 5k" color={{kelvin: 5000}}/>
  24. <IconElement icon={LuciferIcon.Switch} caption="Kelvin 6k" color={{kelvin: 6000}}/>
  25. <IconElement icon={LuciferIcon.Triangle} caption="Kelvin 7k" color={{kelvin: 7000}}/>
  26. <IconElement icon={LuciferIcon.HexagonGroup} caption="Kelvin 8k" color={{kelvin: 8000}}/>
  27. <IconElement icon={LuciferIcon.Router} caption="Kelvin 9k" color={{kelvin: 9000}}/>
  28. <IconElement icon={LuciferIcon.Check} caption="Kelvin 10k" color={{kelvin: 10000}}/>
  29. <IconElement icon={LuciferIcon.Cross} caption="Kelvin 10k" color={{kelvin: 10000}}/>
  30. <IconElement caption="Mer" color="hs-gradient"/>
  31. <IconElement caption="Mer" color="k-gradient"/>
  32. </div>
  33. ),
  34. "/settings": () => <SettingsPage/>,
  35. }
  36. const routeList = ["/", "/devices", "/settings"];
  37. const tabNames = ["Lucifer", "Enheter", "Oppsett"];
  38. function App() {
  39. return (
  40. <DialogContextProvider>
  41. <AppInContext/>
  42. </DialogContextProvider>
  43. );
  44. }
  45. function AppInContext() {
  46. const route = useRoutes(routeObj);
  47. const path = usePath();
  48. const {dialog} = useContext(DialogContext);
  49. useLayoutEffect(() => {
  50. ReactModal.setAppElement("#root");
  51. }, []);
  52. return (
  53. <div className="App">
  54. <Tabs tabNames={tabNames}
  55. index={routeList.indexOf(path)}
  56. onChange={i => navigate(routeList[i])}
  57. large boldIndex={0}
  58. />
  59. {route || <Page>404</Page>}
  60. {makeDialog(dialog)}
  61. </div>
  62. );
  63. }
  64. export default App;