diff options
| author | crupest <crupest@outlook.com> | 2020-09-01 02:32:06 +0800 | 
|---|---|---|
| committer | crupest <crupest@outlook.com> | 2020-09-01 02:32:06 +0800 | 
| commit | aa89b6cce7701a57b0c377d938788b4c940013d6 (patch) | |
| tree | ae95cb16698439ac825eb1d692ce14125b625ecb /Timeline/ClientApp/src/app/views/admin/Admin.tsx | |
| parent | c3e95a6cd7322c644159eed6350a20dfd1a002ff (diff) | |
| download | timeline-aa89b6cce7701a57b0c377d938788b4c940013d6.tar.gz timeline-aa89b6cce7701a57b0c377d938788b4c940013d6.tar.bz2 timeline-aa89b6cce7701a57b0c377d938788b4c940013d6.zip  | |
...
Diffstat (limited to 'Timeline/ClientApp/src/app/views/admin/Admin.tsx')
| -rw-r--r-- | Timeline/ClientApp/src/app/views/admin/Admin.tsx | 78 | 
1 files changed, 78 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..51dc5a3c --- /dev/null +++ b/Timeline/ClientApp/src/app/views/admin/Admin.tsx @@ -0,0 +1,78 @@ +import React, { Fragment } from "react"; +import { Nav, NavItem, NavLink } from "reactstrap"; +import { +  Redirect, +  Route, +  Switch, +  useRouteMatch, +  useHistory, +} from "react-router"; +import classnames from "classnames"; + +import AppBar from "../common/AppBar"; +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}`}> +        <AppBar /> +        <div style={{ height: 56 }} className="flex-fix-length" /> +        <Nav tabs> +          <NavItem> +            <NavLink +              className={classnames({ active: tabName === "users" })} +              onClick={() => { +                toggle("users"); +              }} +            > +              Users +            </NavLink> +          </NavItem> +          <NavItem> +            <NavLink +              className={classnames({ active: tabName === "more" })} +              onClick={() => { +                toggle("more"); +              }} +            > +              More +            </NavLink> +          </NavItem> +        </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;  | 
