diff options
author | crupest <crupest@outlook.com> | 2020-09-03 23:09:03 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-03 23:09:03 +0800 |
commit | 1966351eb2046b9edfb3f9ccb50cb8921f1a08dc (patch) | |
tree | 792ee4899e7e00d518ea37d6ddd68555a83ac51e /Timeline/ClientApp/src/app/views/admin/Admin.tsx | |
parent | 3e7e533016b04df4993df66842409cf5857983ee (diff) | |
parent | 5a0adf596988efe8c3e49efcba7594f134a9cb0d (diff) | |
download | timeline-1966351eb2046b9edfb3f9ccb50cb8921f1a08dc.tar.gz timeline-1966351eb2046b9edfb3f9ccb50cb8921f1a08dc.tar.bz2 timeline-1966351eb2046b9edfb3f9ccb50cb8921f1a08dc.zip |
Merge pull request #159 from crupest/dev
Development on front end.
Diffstat (limited to 'Timeline/ClientApp/src/app/views/admin/Admin.tsx')
-rw-r--r-- | Timeline/ClientApp/src/app/views/admin/Admin.tsx | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/Timeline/ClientApp/src/app/views/admin/Admin.tsx b/Timeline/ClientApp/src/app/views/admin/Admin.tsx new file mode 100644 index 00000000..9c0250e7 --- /dev/null +++ b/Timeline/ClientApp/src/app/views/admin/Admin.tsx @@ -0,0 +1,75 @@ +import React, { Fragment } from "react"; +import { + Redirect, + Route, + Switch, + useRouteMatch, + useHistory, +} from "react-router"; +import { Nav } from "react-bootstrap"; + +import { UserWithToken } from "@/services/user"; + +import UserAdmin from "./UserAdmin"; + +interface AdminProps { + user: UserWithToken; +} + +const Admin: React.FC<AdminProps> = (props) => { + const match = useRouteMatch(); + const history = useHistory(); + type TabNames = "users" | "more"; + + const tabName = history.location.pathname.replace(match.path + "/", ""); + + function toggle(newTab: TabNames): void { + history.push(`${match.url}/${newTab}`); + } + + const createRoute = ( + name: string, + body: React.ReactNode + ): React.ReactNode => { + return ( + <Route path={`${match.path}/${name}`}> + <div style={{ height: 56 }} className="flex-fix-length" /> + <Nav variant="tabs"> + <Nav.Item> + <Nav.Link + active={tabName === "users"} + onClick={() => { + toggle("users"); + }} + > + Users + </Nav.Link> + </Nav.Item> + <Nav.Item> + <Nav.Link + active={tabName === "more"} + onClick={() => { + toggle("more"); + }} + > + More + </Nav.Link> + </Nav.Item> + </Nav> + {body} + </Route> + ); + }; + + return ( + <Fragment> + <Switch> + <Redirect from={match.path} to={`${match.path}/users`} exact /> + {createRoute("users", <UserAdmin user={props.user} />)} + {createRoute("more", <div>More Page Works</div>)} + </Switch> + </Fragment> + ); +}; + +export default Admin; |