Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions apps/web/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
import { getServerSession } from "next-auth";
import { Landing } from "../screens/Landing";
import { authOptions } from "../lib/auth";
import { redirect } from "next/navigation";

export default async function Page(): Promise<JSX.Element> {
const session = await getServerSession(authOptions);

if (!session?.user) {
return redirect("/auth");
}

return (
<main>
<Landing />
</main>
);
}
}
2 changes: 1 addition & 1 deletion packages/ui/src/BlogAppbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const BlogAppbar = ({
}, [track, problem]);

let totalPages = Array.from({ length: track.problems.length }, (_, i) => i + 1);

localStorage.setItem('problemIndex', (problemIndex+1).toString());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why here?
Also why localStorage?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Figured we could use problemIndex in other places so why not have it on hand in the parent component i.e BlogAppbar.

function setTheme(arg0: string) {
throw new Error("Function not implemented.");
}
Expand Down
61 changes: 37 additions & 24 deletions packages/ui/src/NotionRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,47 @@ import { NotionRenderer as NotionRendererLib } from "react-notion-x";
// import { Code } from "react-notion-x/build/third-party/code";
import CodeBlock from "./CodeBlock";
import { useTheme } from "next-themes";
import { useSession } from "next-auth/react";
import RedirectToLoginCard from "./RedirectToLoginCard";

// Week-4-1-647987d9b1894c54ba5c822978377910
export const NotionRenderer = ({ recordMap }: { recordMap: any }) => {
const { resolvedTheme } = useTheme();
const session = useSession();
const isAuthenticated = session.status === 'authenticated' && session.data !== null;
const storedProblemIndex = localStorage.getItem('problemIndex');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NotionRenderer isn't the only renderer we have
There is the coding renderer as well for example
This'll not work if the third page is a coding problem

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I missed that scenario. Mb. I can try implementing similar functionality in LessionView.tsx and pass a variable (trackVisible) to the components(Blog, CodeRenderer, MCQRenderer). That would be a better way of doing this for now and if and when new components are added

const number = storedProblemIndex !== null ? parseInt(storedProblemIndex) : 1;
const isPageNumberGreaterThanTwo = !isNaN(number) && number > 2;

return (
<div className="w-full">
<style>
{`
.notion-header {
display: none !important;
}
let contentToRender;
if (isPageNumberGreaterThanTwo && !isAuthenticated) {
contentToRender = <RedirectToLoginCard />;
} else {
contentToRender = (
<div className="w-full">
<style>
{`
.notion-header {
display: none !important;
}

.notion-page: {
padding: 0px !important;
}
`}
</style>
<div className="rounded-full">
<NotionRendererLib
components={{
Code: CodeBlock,
}}
recordMap={recordMap}
fullPage={true}
darkMode={resolvedTheme === "dark"}
/>
.notion-page: {
padding: 0px !important;
}
`}
</style>
<div className="rounded-full">
<NotionRendererLib
components={{
Code: CodeBlock,
}}
recordMap={recordMap}
fullPage={true}
darkMode={resolvedTheme === "dark"}
/>
</div>
</div>
</div>
);
};
);
}
return <>{contentToRender}</>;
};
4 changes: 2 additions & 2 deletions packages/ui/src/RedirectToLoginCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ const RedirectToLoginCard = () => {
router.push("/auth");
};
return (
<Card className="absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 shadow-lg w-1/4">
<Card className="absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 shadow-lg w-1/2">
<CardHeader>
<CardTitle>Login to access the content</CardTitle>
<CardDescription>You'll be redirected back to this page after login</CardDescription>
</CardHeader>
<CardContent className="px-4">
<Button className="w-1/2 mt-4" onClick={redirectToLogin}>
<Button className="w-full mt-4" onClick={redirectToLogin}>
Go to Login Page
</Button>
</CardContent>
Expand Down