Skip to content
Draft
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
486 changes: 482 additions & 4 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"chart.js": "^4.5.0",
"firebase": "^10.14.1",
"framer": "^2.4.1",
"isomorphic-dompurify": "^2.26.0",
"lucide-react": "^0.539.0",
"motion": "^12.23.12",
"next": "14.2.15",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import DOMPurify from 'isomorphic-dompurify';
import CircleSkeleton from "@/components/Skeletons/CircleSkeleton";
import RectangleSkeleton from "@/components/Skeletons/RectangleSkeleton";
import { auth, firestore } from "@/firebase/firebase";
Expand Down Expand Up @@ -305,7 +306,7 @@ const ProblemDescription: React.FC<ProblemDescriptionProps> = ({
</div>
<div className="p-4 overflow-y-auto h-[calc(100vh-100px)]">
<div className="prose prose-invert max-w-none">
<div dangerouslySetInnerHTML={{ __html: problem.problemStatement }} />
<div dangerouslySetInnerHTML={{ __html: DOMPurify.sanitize(problem.problemStatement) }} />
{problem.examples.length > 0 && (
<div className="mt-4">
{problem.examples.map((example, index) => (
Expand Down Expand Up @@ -336,7 +337,7 @@ const ProblemDescription: React.FC<ProblemDescriptionProps> = ({
<div className="mt-4">
<h3 className="text-softSilver font-medium">Constraints:</h3>
<ul className="list-disc list-inside text-softSilver">
<div dangerouslySetInnerHTML={{ __html: problem.constraints }} />
<div dangerouslySetInnerHTML={{ __html: DOMPurify.sanitize(problem.constraints) }} />
</ul>
</div>
</div>
Expand Down
6 changes: 4 additions & 2 deletions src/firebase/firebase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ const firebaseConfig = {
};

// Initialize Firebase
const app = !getApps.length ? initializeApp(firebaseConfig) : getApp();
const app = getApps().length === 0 ? initializeApp(firebaseConfig) : getApp();

const auth = getAuth(app);
// Avoid initializing Auth during SSR/build where browser APIs/env may be unavailable
const isBrowser = typeof window !== "undefined";
const auth = isBrowser ? getAuth(app) : (null as any);
const firestore = getFirestore(app);

export { auth, firestore, app };
2 changes: 1 addition & 1 deletion src/pages/api/judge0/result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { NextApiRequest, NextApiResponse } from 'next';

// Judge0 API configuration
const RAPIDAPI_HOST = process.env.RAPIDAPI_HOST || 'judge0-ce.p.rapidapi.com';
const RAPIDAPI_KEY = process.env.RAPIDAPI_KEY || process.env.NEXT_PUBLIC_RAPIDAPI_KEY;
const RAPIDAPI_KEY = process.env.RAPIDAPI_KEY;

interface Judge0ResultResponse {
stdout?: string;
Expand Down
2 changes: 1 addition & 1 deletion src/pages/api/judge0/submit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { NextApiRequest, NextApiResponse } from 'next';

// Judge0 API configuration
const RAPIDAPI_HOST = process.env.RAPIDAPI_HOST || 'judge0-ce.p.rapidapi.com';
const RAPIDAPI_KEY = process.env.RAPIDAPI_KEY || process.env.NEXT_PUBLIC_RAPIDAPI_KEY;
const RAPIDAPI_KEY = process.env.RAPIDAPI_KEY;

interface SubmitRequestBody {
source_code: string;
Expand Down
2 changes: 1 addition & 1 deletion src/pages/api/judge0/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { NextApiRequest, NextApiResponse } from 'next';

// Judge0 API configuration
const RAPIDAPI_HOST = process.env.RAPIDAPI_HOST || 'judge0-ce.p.rapidapi.com';
const RAPIDAPI_KEY = process.env.RAPIDAPI_KEY || process.env.NEXT_PUBLIC_RAPIDAPI_KEY;
const RAPIDAPI_KEY = process.env.RAPIDAPI_KEY;

interface TestResponse {
success: boolean;
Expand Down
10 changes: 8 additions & 2 deletions src/pages/dsa/article/[...slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,14 @@ export const getServerSideProps: GetServerSideProps = async (context) => {
const topicsRef = collection(firestore, 'topics');
const topicsSnapshot = await getDocs(firebaseQuery(topicsRef, orderBy('serial', 'asc')));

let articleData = null;
let allItems = [];
let articleData: {
title: string;
slug: string;
githubPath: string;
youtubePath: string;
content: any[];
} | null = null;
let allItems: Array<{ slug: string; title: string; serial: number }>= [];

// Process all topics and build a flat list for navigation
topicsSnapshot.forEach((doc) => {
Expand Down
4 changes: 2 additions & 2 deletions src/pages/dsa/topic/introduction/setup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const DSAEnvironmentSetup: React.FC = () => {
dataKey,
nameKey = "platform"
}: {
data: Array<{ [key: string]: string | number }>;
data: Array<{ [key: string]: string | number } & { color?: string }>;
title: string;
dataKey: string;
nameKey?: string;
Expand Down Expand Up @@ -52,7 +52,7 @@ const DSAEnvironmentSetup: React.FC = () => {
animate={{ width: `${item[dataKey]}%` }}
transition={{ duration: 1, delay: index * 0.1 }}
className="h-3 rounded-full"
style={{ backgroundColor: item.color }}
style={{ backgroundColor: typeof item.color === 'string' ? item.color : '#999' }}
/>
</div>
</motion.div>
Expand Down
4 changes: 2 additions & 2 deletions src/pages/dsa/topic/introduction/whyDsa.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const WhyDSA: React.FC = () => {
];

const CustomBarChart = ({ data, title, dataKey, nameKey = "topic" }: {
data: Array<{ [key: string]: string | number }>;
data: Array<{ [key: string]: string | number } & { color?: string }>;
title: string;
dataKey: string;
nameKey?: string;
Expand Down Expand Up @@ -65,7 +65,7 @@ const WhyDSA: React.FC = () => {
animate={{ width: `${item[dataKey]}%` }}
transition={{ duration: 1, delay: index * 0.1 }}
className="h-3 rounded-full"
style={{ backgroundColor: item.color }}
style={{ backgroundColor: typeof (item as any).color === 'string' ? (item as any).color : '#999' }}
/>
</div>
</motion.div>
Expand Down