relative page routing seems functional
This commit is contained in:
parent
84d06d9783
commit
05f7765f82
4 changed files with 73 additions and 32 deletions
|
|
@ -395,7 +395,6 @@ export default function ResponsiveTable<T extends Object>(props: Props<T>) {
|
||||||
})
|
})
|
||||||
:
|
:
|
||||||
Object.values(row).map((value, j) => {
|
Object.values(row).map((value, j) => {
|
||||||
console
|
|
||||||
return (
|
return (
|
||||||
<TableCell key={"row-"+index+"cell-"+j}>
|
<TableCell key={"row-"+index+"cell-"+j}>
|
||||||
{value ? value.toString() : ""}
|
{value ? value.toString() : ""}
|
||||||
|
|
@ -431,7 +430,7 @@ export default function ResponsiveTable<T extends Object>(props: Props<T>) {
|
||||||
<TablePagination
|
<TablePagination
|
||||||
rowsPerPageOptions={rowsPerPageOptions ? rowsPerPageOptions : [5, 10, 20]}
|
rowsPerPageOptions={rowsPerPageOptions ? rowsPerPageOptions : [5, 10, 20]}
|
||||||
component="div"
|
component="div"
|
||||||
count={total}
|
count={total ? total : 0}
|
||||||
rowsPerPage={pageSize}
|
rowsPerPage={pageSize}
|
||||||
page={page}
|
page={page}
|
||||||
onPageChange={(_event, page) => handlePageChange(page)}
|
onPageChange={(_event, page) => handlePageChange(page)}
|
||||||
|
|
|
||||||
|
|
@ -23,23 +23,56 @@ interface Props {
|
||||||
export default function Router(props: Props) {
|
export default function Router(props: Props) {
|
||||||
|
|
||||||
const {open, onOpen, onClose, toggleTheme } = props;
|
const {open, onOpen, onClose, toggleTheme } = props;
|
||||||
const { isAuthenticated, loginWithRedirect, isLoading } = useAuth0()
|
const { isAuthenticated, loginWithRedirect, isLoading } = useAuth0();
|
||||||
const isMobile = useMobile()
|
const isMobile = useMobile();
|
||||||
|
|
||||||
const hello = () => {
|
const RelativeRoutes = () => {
|
||||||
|
console.log("relative route")
|
||||||
return (
|
return (
|
||||||
<Typography>
|
<Routes>
|
||||||
Hello!
|
<Route path="teams/*" element={<TeamsRoute/>} />
|
||||||
</Typography>
|
<Route path="devices" element={<DevicesRoute/>} />
|
||||||
|
</Routes>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// useEffect(() => {
|
const TeamsRoute = () => {
|
||||||
// setAuthorized(isAuthenticated || offline);
|
console.log("teams route")
|
||||||
// if (isAuthenticated && !user.empty() && !user.status.finishedIntro) {
|
return (
|
||||||
// history.push("/welcome");
|
<Routes>
|
||||||
// }
|
<Route
|
||||||
// }, [history, isAuthenticated, offline, user]);
|
path="" // "/settings/basic"
|
||||||
|
element={<Teams />}
|
||||||
|
/>
|
||||||
|
<Route
|
||||||
|
path="/:teamID" // "/settings/basic"
|
||||||
|
element={<TeamPage />}
|
||||||
|
/>
|
||||||
|
<Route
|
||||||
|
path="/:teamID/*" // "/settings/basic"
|
||||||
|
element={<RelativeRoutes />}
|
||||||
|
/>
|
||||||
|
</Routes>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const DevicesRoute = () => {
|
||||||
|
console.log("devices route")
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Routes>
|
||||||
|
<Route
|
||||||
|
path="" // "/settings/basic"
|
||||||
|
element={<Devices />}
|
||||||
|
/>
|
||||||
|
{/* <Route
|
||||||
|
path="/:deviceID" // "/settings/basic"
|
||||||
|
element={<TeamPage />}
|
||||||
|
/> */}
|
||||||
|
</Routes>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
if (isLoading) return null;
|
if (isLoading) return null;
|
||||||
if (!isAuthenticated) {
|
if (!isAuthenticated) {
|
||||||
|
|
@ -65,22 +98,14 @@ export default function Router(props: Props) {
|
||||||
{/* Redirects */}
|
{/* Redirects */}
|
||||||
<Route path="/callback" element={<Navigate to="/" />} />
|
<Route path="/callback" element={<Navigate to="/" />} />
|
||||||
<Route path="/team/:teamID" element={<Navigate to="/teams/:teamID" />} />
|
<Route path="/team/:teamID" element={<Navigate to="/teams/:teamID" />} />
|
||||||
|
<Route path="/device/:deviceID" element={<Navigate to="/devices/:devicesID" />} />
|
||||||
|
|
||||||
{/* Page routes */}
|
{/* Page routes */}
|
||||||
<Route index element={hello()} />
|
<Route index element={<Typography>Hello!</Typography>} />
|
||||||
<Route path="/teams" element={<Teams/>} />
|
<Route path="users" element={<Users/>} />
|
||||||
<Route path="/teams/:teamID" element={<TeamPage/>} />
|
|
||||||
<Route path="/users" element={<Users/>} />
|
|
||||||
<Route path="*/devices" element={<Devices/>} />
|
|
||||||
<Route path="/devices" element={<Devices/>} />
|
|
||||||
{/* <Route
|
|
||||||
path="/teams/:teamID"
|
|
||||||
element={<Team />}
|
|
||||||
/> */}
|
|
||||||
{/* <Route path="blogs" element={<Blogs />} />
|
|
||||||
<Route path="contact" element={<Contact />} />
|
|
||||||
<Route path="*" element={<NoPage />} /> */}
|
|
||||||
<Route path="/logout" element={<Logout />} />
|
<Route path="/logout" element={<Logout />} />
|
||||||
|
<Route path="*" element={<RelativeRoutes/>} />
|
||||||
|
|
||||||
</Routes>
|
</Routes>
|
||||||
{isMobile && <BottomNavigator openSide={onOpen} sideIsOpen={open} />}
|
{isMobile && <BottomNavigator openSide={onOpen} sideIsOpen={open} />}
|
||||||
</BrowserRouter>
|
</BrowserRouter>
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ import PageContainer from "./PageContainer";
|
||||||
import { useMobile } from "hooks";
|
import { useMobile } from "hooks";
|
||||||
import { useLocation, useNavigate } from "react-router-dom";
|
import { useLocation, useNavigate } from "react-router-dom";
|
||||||
import { or } from "utils/types";
|
import { or } from "utils/types";
|
||||||
|
import { getContextKeys, getContextTypes } from "pbHelpers/Context";
|
||||||
|
|
||||||
const useStyles = makeStyles((theme: Theme) => {
|
const useStyles = makeStyles((theme: Theme) => {
|
||||||
return ({
|
return ({
|
||||||
|
|
@ -30,7 +31,7 @@ export default function Devices() {
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const deviceAPI = useDeviceAPI();
|
const deviceAPI = useDeviceAPI();
|
||||||
const [limit, setLimit] = useState(10);
|
const [limit, setLimit] = useState(10);
|
||||||
const [offset, setOffset] = useState(0);
|
const [page, setPage] = useState(0);
|
||||||
const [order, ] = useState<"asc" | "desc">("asc");
|
const [order, ] = useState<"asc" | "desc">("asc");
|
||||||
const [orderBy, ] = useState("name");
|
const [orderBy, ] = useState("name");
|
||||||
const [search, setSearch] = useState("");
|
const [search, setSearch] = useState("");
|
||||||
|
|
@ -47,7 +48,21 @@ export default function Devices() {
|
||||||
};
|
};
|
||||||
|
|
||||||
const loadDevices = () => {
|
const loadDevices = () => {
|
||||||
deviceAPI.list(limit, offset*limit, order, orderBy, search).then(resp => {
|
deviceAPI.list(
|
||||||
|
limit,
|
||||||
|
page*limit,
|
||||||
|
order,
|
||||||
|
orderBy,
|
||||||
|
search,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
getContextKeys(),
|
||||||
|
getContextTypes()
|
||||||
|
).then(resp => {
|
||||||
setDevices(resp.data.devices)
|
setDevices(resp.data.devices)
|
||||||
setTotal(resp.data.total)
|
setTotal(resp.data.total)
|
||||||
})
|
})
|
||||||
|
|
@ -55,7 +70,7 @@ export default function Devices() {
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
loadDevices()
|
loadDevices()
|
||||||
}, [limit, offset, order, orderBy, search])
|
}, [limit, page, order, orderBy, search])
|
||||||
|
|
||||||
const handleChange = (event: any) => {
|
const handleChange = (event: any) => {
|
||||||
setLimit(event.target.value);
|
setLimit(event.target.value);
|
||||||
|
|
@ -102,8 +117,8 @@ export default function Devices() {
|
||||||
columns={columns()}
|
columns={columns()}
|
||||||
total={total}
|
total={total}
|
||||||
pageSize={limit}
|
pageSize={limit}
|
||||||
page={offset}
|
page={page}
|
||||||
setPage={setOffset}
|
setPage={setPage}
|
||||||
handleRowsPerPageChange={handleChange}
|
handleRowsPerPageChange={handleChange}
|
||||||
onRowClick={toDevice}
|
onRowClick={toDevice}
|
||||||
setSearchText={setSearch}
|
setSearchText={setSearch}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import { useMobile } from "hooks";
|
import { useMobile } from "hooks";
|
||||||
import PageContainer from "pages/PageContainer";
|
import PageContainer from "pages/PageContainer";
|
||||||
|
import { Outlet } from "react-router-dom";
|
||||||
import TeamList from "teams/TeamList";
|
import TeamList from "teams/TeamList";
|
||||||
|
|
||||||
export default function Teams() {
|
export default function Teams() {
|
||||||
|
|
@ -7,6 +8,7 @@ export default function Teams() {
|
||||||
return (
|
return (
|
||||||
<PageContainer padding={isMobile ? 0 : 2}>
|
<PageContainer padding={isMobile ? 0 : 2}>
|
||||||
<TeamList />
|
<TeamList />
|
||||||
|
<Outlet/>
|
||||||
</PageContainer>
|
</PageContainer>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue