Skip to content

Commit

Permalink
Fixed router resert problem that was caused in the protected-route co…
Browse files Browse the repository at this point in the history
…mponent - made an empty call page and added it to the router
  • Loading branch information
PezhmanGhavami committed Jun 1, 2023
1 parent 0e48c07 commit ff105dc
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions client/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import ProtectedRoute from "./components/protected-route/protected-route";

import Index from "./pages/index/index.page";
import Chat from "./pages/chat/chat.page";
import Call from "./pages/call/call.page";
import Signin from "./pages/signin/signin.page";
import Signup from "./pages/signup/signup.page";
import NotFound from "./pages/not-found/not-found.page";
Expand Down Expand Up @@ -49,6 +50,7 @@ function App() {
>
<Route index element={<Index />} />
<Route path="chat/:chatId" element={<Chat />} />
<Route path="call/:chatId" element={<Chat />} />
</Route>

<Route path="/auth" element={<AuthLayout />}>
Expand Down
12 changes: 11 additions & 1 deletion client/src/components/protected-route/protected-route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,21 @@ import { Navigate, useLocation } from "react-router-dom";

import useUser from "../../hooks/useUser";

import LoadingSpinner from "../loading-spinner/loading-spinner.component";

function ProtectedRoute({ children }: { children: JSX.Element }) {
const { user } = useUser();
const location = useLocation();

if (user?.isLoggedIn) {
if (!user) {
return (
<div className="h-screen text-4xl">
<LoadingSpinner />
</div>
);
}

if (user.isLoggedIn) {
return children;
}

Expand Down
5 changes: 5 additions & 0 deletions client/src/pages/call/call.page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function Call() {
return <div></div>;
}

export default Call;

0 comments on commit ff105dc

Please sign in to comment.