Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Release 1.0 #4

Merged
merged 4 commits into from
Dec 11, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
10.22.1
2 changes: 2 additions & 0 deletions src/__mocks__/@topcoder/micro-frontends-navbar-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ module.exports = {
setAppMenu: () => {},
getAuthUserTokens: () => new Promise(() => {}),
getAuthUserProfile: () => new Promise(() => {}),
disableSidebarForRoute: () => {},
enableSidebarForRoute: () => {},
};
38 changes: 38 additions & 0 deletions src/components/NoSidebarDemo/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* This component demonstrates how we can disable sidebar for some subroutes.
*
* For example this component disables sidebar for routes "/micro-frontends-react-route/no-sidebar/*".
*/
import React, { useLayoutEffect } from "react";
import {
disableSidebarForRoute,
enableSidebarForRoute,
} from "@topcoder/micro-frontends-navbar-app";

const COMPONENT_ROUTE = "/micro-frontends-react-route/no-sidebar/*";

const NoSidebarDemo = () => {
// use "useLayoutEffect" to remove the sidebar as early as possible
// without waiting the component to be rendered
useLayoutEffect(() => {
disableSidebarForRoute(COMPONENT_ROUTE);
}, []);

return (
<>
<h2>Sidebar</h2>
<div>Enable/disable sidebar for routes that match:</div>
<pre>{COMPONENT_ROUTE}</pre>
<div>
<button onClick={() => enableSidebarForRoute(COMPONENT_ROUTE)}>
Enable
</button>
<button onClick={() => disableSidebarForRoute(COMPONENT_ROUTE)}>
Disable
</button>
</div>
</>
);
};

export default NoSidebarDemo;
10 changes: 8 additions & 2 deletions src/constants/appMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,14 @@ const appMenu = [
activeIcon: reactActiveIcon,
},
{
title: "Home",
path: "/micro-frontends-react-route/home",
title: "Auth Demo",
path: "/micro-frontends-react-route/auth",
icon: homeIcon,
activeIcon: homeActiveIcon,
},
{
title: "No Sidebar Demo",
path: "/micro-frontends-react-route/no-sidebar",
icon: homeIcon,
activeIcon: homeActiveIcon,
},
Expand Down
8 changes: 6 additions & 2 deletions src/root.component.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React, { useEffect } from "react";
import { Link } from "@reach/router";
import { Link, Router } from "@reach/router";
import { setAppMenu } from "@topcoder/micro-frontends-navbar-app";
import appMenu from "./constants/appMenu";
import AuthDemo from "./components/AuthDemo";
import NoSidebarDemo from "./components/NoSidebarDemo";

export default function Root() {
useEffect(() => {
Expand Down Expand Up @@ -32,7 +33,10 @@ export default function Root() {
</Link>
</div>

<AuthDemo />
<Router>
<AuthDemo path="/micro-frontends-react-route/auth" />
<NoSidebarDemo path="/micro-frontends-react-route/no-sidebar" />
</Router>
</div>
);
}