diff --git a/src/components/Sidebar copy.js b/src/components/Sidebar copy.js deleted file mode 100644 index b08e231..0000000 --- a/src/components/Sidebar copy.js +++ /dev/null @@ -1,29 +0,0 @@ -import React from 'react'; -import '../css/components/Sidebar.css'; -import NavLink from '../structures/NavLink'; - -const Sidebar = ({children}) => { - - return
- {children} -
; - -}; - -// Nav menu -const SidebarMenu = ({menuItems, children}) => { - - let key = 0; - return
- {menuItems.map(link => { - const { label, ...rest } = link; - return { label}; - })} - - {children} -
; - -}; - -export {SidebarMenu, Sidebar}; -export default Sidebar; \ No newline at end of file diff --git a/src/components/Table.js b/src/components/Table.js new file mode 100644 index 0000000..034a794 --- /dev/null +++ b/src/components/Table.js @@ -0,0 +1,24 @@ +import React from "react"; + +export const TableListEntry = ({onClick, item, itemKeys}) => { + + return + {itemKeys.map(key => {item[key]})} + ; +}; + +export const Table = ({headerItems, children, items, itemKeys, maxWidth = '30em'}) => { + + let i = 0; + return + + + {headerItems.map(item => )} + + + + {children ? children : items.map(item => )} + +
{item}
; + +}; \ No newline at end of file diff --git a/src/pages/Users.js b/src/pages/Users.js index 29a8138..4d5b3ff 100644 --- a/src/pages/Users.js +++ b/src/pages/Users.js @@ -3,6 +3,7 @@ import { Route, Routes, useNavigate, useParams } from "react-router"; import ErrorBoundary from "../util/ErrorBoundary"; import { get } from '../util/Util'; import '../css/pages/Users.css'; +import { Table, TableListEntry } from "../components/Table"; const Permission = ({name, value}) => { return
  • @@ -59,9 +60,19 @@ const Permissions = ({ perms }) => { ; }; -// TODO: Make generic table list component and use it here and the user list const ApplicationList = ({ apps }) => { + const navigate = useNavigate(); + return + {apps.map(app => { + navigate(`${window.location.pathname}/applications/${app.id}`); + }} + key={app.id} + item={app} + itemKeys={['name', 'id']} + />)} +
    ; }; @@ -80,7 +91,14 @@ const User = ({ user }) => { const response = await get(`/api/users/${user._id}/applications`); if(response.status === 200) updateApps(response.data); })(); - }, [user]); + }, []); + + const ApplicationWrapper = () => { + const { appid } = useParams(); + const app = apps.find(a => a._id === appid); + if (!app) return null; + return ; + }; return
    @@ -106,8 +124,9 @@ const User = ({ user }) => {

    Applications

    } /> + } /> - {apps.map(app => )} + {/* {apps.map(app => )} */}
    @@ -123,37 +142,37 @@ const User = ({ user }) => { ; }; -const UserListEntry = ({ user }) => { +// const UserListEntry = ({ user }) => { - const navigate = useNavigate(); +// const navigate = useNavigate(); - const onClick = () => { - navigate(`/users/${user._id}`); - }; +// const onClick = () => { +// navigate(`/users/${user._id}`); +// }; - return - {user.username} - {user._id} - ; +// return +// {user.username} +// {user._id} +// ; -}; +// }; -// TODO: Make table list generic component -const UserList = ({ users }) => { +// // TODO: Make table list generic component +// const UserList = ({ users }) => { - return - - - - - - - - {users.map(user => )} - -
    UsernameID
    ; +// return +// +// +// +// +// +// +// +// {users.map(user => )} +// +//
    UsernameID
    ; -}; +// }; const Users = () => { @@ -178,9 +197,20 @@ const Users = () => { return ; }; + const navigate = useNavigate(); const UserListWrapper = () => { return
    - + + + {users.map(user => { + navigate(`/users/${user._id}`); + }} + key={user._id} + item={user} + itemKeys={['username', '_id']} />)} +
    +

    Page: {page}

    @@ -188,6 +218,7 @@ const Users = () => { if (users.length === 10) setPage(page + 1); }}>Next
    +
    ; };