Skip to content

Commit d2a2ad7

Browse files
committed
PEER-249 Add common layout for question details
Signed-off-by: SeeuSim <[email protected]>
1 parent 79492aa commit d2a2ad7

File tree

5 files changed

+9
-31
lines changed

5 files changed

+9
-31
lines changed

frontend/src/components/blocks/layout.tsx

Lines changed: 0 additions & 13 deletions
This file was deleted.

frontend/src/components/blocks/route-guard.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ export const loader =
1919
async ({ request }: LoaderFunctionArgs) => {
2020
const route = new URL(request.url);
2121
const path = route.pathname;
22-
const authedRoutes = [ROUTES.HOME];
22+
const unAuthedRoutes = [ROUTES.LOGIN, ROUTES.SIGNUP, ROUTES.FORGOT_PASSWORD];
23+
const unAuthedRoute = unAuthedRoutes.includes(path);
2324

2425
return defer({
2526
isAuthed: await queryClient.ensureQueryData({
@@ -33,7 +34,7 @@ export const loader =
3334
return Math.max(expiresAt.getTime() - now.getTime(), 0);
3435
},
3536
}),
36-
authedRoute: authedRoutes.includes(path),
37+
authedRoute: !unAuthedRoute,
3738
path,
3839
});
3940
};

frontend/src/lib/router.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { createBrowserRouter } from 'react-router-dom';
22

3-
import { Layout } from '@/components/blocks/layout';
3+
import { AuthedLayout } from '@/components/blocks/authed-layout';
4+
import { RootLayout } from '@/components/blocks/root-layout';
45
import { RouteGuard, loader as routeGuardLoader } from '@/components/blocks/route-guard';
56

67
import { ForgotPassword } from '@/routes/forgot-password';
7-
import { Landing } from '@/routes/landing';
88
import { Login } from '@/routes/login';
99
import { loader as qnDetailsLoader, QuestionDetails } from '@/routes/questions/details';
1010
import { SignUp } from '@/routes/signup';
@@ -14,15 +14,15 @@ import { ROUTES } from './routes';
1414

1515
export const router = createBrowserRouter([
1616
{
17-
element: <Layout />,
17+
element: <RootLayout />,
1818
children: [
1919
{
2020
element: <RouteGuard />,
2121
loader: routeGuardLoader(queryClient),
2222
children: [
2323
{
2424
path: ROUTES.HOME,
25-
element: <Landing />,
25+
element: <AuthedLayout />,
2626
children: [
2727
{
2828
path: ROUTES.QUESTION_DETAILS,

frontend/src/routes/landing.tsx

Lines changed: 0 additions & 10 deletions
This file was deleted.

frontend/src/routes/questions/details.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export const QuestionDetails = () => {
6868
const { questionId } = useLoaderData() as Awaited<ReturnType<ReturnType<typeof loader>>>;
6969
const { data: details } = useSuspenseQuery(questionDetailsQuery(questionId));
7070
return (
71-
<div className='flex h-[calc(100dvh-64px)] w-full flex-col'>
71+
<>
7272
<div className='bg-secondary/50 flex w-full p-4 px-6'>
7373
<Breadcrumb>
7474
<BreadcrumbList>
@@ -131,6 +131,6 @@ export const QuestionDetails = () => {
131131
</Card>
132132
<div className='flex flex-1 flex-col' />
133133
</div>
134-
</div>
134+
</>
135135
);
136136
};

0 commit comments

Comments
 (0)