Advertisement
zidniryi

authlayout.jsx

Sep 24th, 2021
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.10 KB | None | 0 0
  1. import React from "react";
  2. import { connect } from "react-redux";
  3. import { Route, Switch, Redirect } from "react-router-dom";
  4. import ThemeAuth from "../routes/routingAuth.jsx";
  5.  
  6. const mapStateToProps = (state) => ({
  7. ...state,
  8. });
  9.  
  10. class Authlayout extends React.Component {
  11. constructor(props) {
  12. super(props);
  13. this.updateDimensions = this.updateDimensions.bind(this);
  14. this.state = {
  15. isOpen: false,
  16. width: window.innerWidth,
  17. };
  18.  
  19. this.props.history.listen((location, action) => {
  20. if (
  21. window.innerWidth < 767 &&
  22. document
  23. .getElementById("main-wrapper")
  24. .className.indexOf("show-sidebar") !== -1
  25. ) {
  26. document
  27. .getElementById("main-wrapper")
  28. .classList.toggle("show-sidebar");
  29. }
  30. });
  31. }
  32. /*--------------------------------------------------------------------------------*/
  33. /*Life Cycle Hook, Applies when loading or resizing App */
  34. /*--------------------------------------------------------------------------------*/
  35. componentDidMount() {
  36. window.addEventListener("load", this.updateDimensions);
  37. window.addEventListener("resize", this.updateDimensions);
  38. }
  39. /*--------------------------------------------------------------------------------*/
  40. /*Function that handles sidebar, changes when resizing App */
  41. /*--------------------------------------------------------------------------------*/
  42. updateDimensions() {
  43. let element = document.getElementById("main-wrapper");
  44. this.setState({
  45. width: window.innerWidth,
  46. });
  47. switch (this.props.settings.activeSidebarType) {
  48. case "full":
  49. case "iconbar":
  50. if (this.state.width < 1170) {
  51. element.setAttribute("data-sidebartype", "mini-sidebar");
  52. element.classList.add("mini-sidebar");
  53. } else {
  54. element.setAttribute(
  55. "data-sidebartype",
  56. this.props.settings.activeSidebarType
  57. );
  58. element.classList.remove("mini-sidebar");
  59. }
  60. break;
  61.  
  62. case "overlay":
  63. if (this.state.width < 767) {
  64. element.setAttribute("data-sidebartype", "mini-sidebar");
  65. } else {
  66. element.setAttribute(
  67. "data-sidebartype",
  68. this.props.settings.activeSidebarType
  69. );
  70. }
  71. break;
  72.  
  73. default:
  74. }
  75. }
  76. /*--------------------------------------------------------------------------------*/
  77. /*Life Cycle Hook */
  78. /*--------------------------------------------------------------------------------*/
  79. componentWillUnmount() {
  80. window.removeEventListener("load", this.updateDimensions);
  81. window.removeEventListener("resize", this.updateDimensions);
  82. }
  83. render() {
  84. /*--------------------------------------------------------------------------------*/
  85. /* Theme Setting && Layout Options wiil be Change From Here */
  86. /*--------------------------------------------------------------------------------*/
  87. return (
  88. <div>
  89. {/* // <div
  90. // id="main-wrapper"
  91. // dir={this.props.settings.activeDir}
  92. // data-theme={this.props.settings.activeTheme}
  93. // data-layout={this.props.settings.activeThemeLayout}
  94. // data-sidebartype={this.props.settings.activeSidebarType}
  95. // data-sidebar-position={this.props.settings.activeSidebarPos}
  96. // data-header-position={this.props.settings.activeHeaderPos}
  97. // data-boxed-layout={this.props.settings.activeLayout}
  98. // > */}
  99.  
  100. {/*--------------------------------------------------------------------------------*/}
  101. {/* Header */}
  102. {/*--------------------------------------------------------------------------------*/}
  103. {/* <Header /> */}
  104. {/*--------------------------------------------------------------------------------*/}
  105. {/* Sidebar */}
  106. {/*--------------------------------------------------------------------------------*/}
  107. {/* <Sidebar {...this.props} routes={ThemeAuth} /> */}
  108. {/*--------------------------------------------------------------------------------*/}
  109. {/* Page Main-Content */}
  110. {/*--------------------------------------------------------------------------------*/}
  111. {/* <div
  112. className="page-wrapper d-block"
  113. style={{ backgroundColor: "white" }}
  114. > */}
  115. <div>
  116. <Switch>
  117. {ThemeAuth.map((prop, key) => {
  118. if (prop.navlabel) {
  119. return null;
  120. } else if (prop.collapse) {
  121. return prop.child.map((prop2, key2) => {
  122. if (prop2.collapse) {
  123. return prop2.subchild.map((prop3, key3) => {
  124. return (
  125. <Route
  126. path={prop3.path}
  127. component={prop3.component}
  128. key={key3}
  129. />
  130. );
  131. });
  132. }
  133. return (
  134. <Route
  135. path={prop2.path}
  136. component={prop2.component}
  137. key={key2}
  138. />
  139. );
  140. });
  141. } else if (prop.redirect) {
  142. return <Redirect from={prop.path} to={prop.pathTo} key={key} />;
  143. } else {
  144. return (
  145. <Route
  146. path={prop.path}
  147. component={prop.component}
  148. key={key}
  149. />
  150. );
  151. }
  152. })}
  153. </Switch>
  154. </div>
  155. </div>
  156. );
  157. }
  158. }
  159. export default connect(mapStateToProps)(Authlayout);
  160.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement