Skip to content

Commit

Permalink
Merge branch 'master' into dsa_loop
Browse files Browse the repository at this point in the history
  • Loading branch information
Vishal-raj-1 authored Oct 6, 2023
2 parents a999b02 + bd7da89 commit 5de5884
Show file tree
Hide file tree
Showing 50 changed files with 863 additions and 135 deletions.
7 changes: 0 additions & 7 deletions app/(batches)/batch/[[...batchID]]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import { allBatches } from "@/.contentlayer/generated";
import { DocsHeader } from "@/components/docs-header";
import { Mdx } from "@/components/markdown/mdx";
import {
Accordion,
AccordionItem,
AccordionContent,
AccordionTrigger,
} from "@/components/ui/accordion";
import { cn } from "@/lib/utils";
import { notFound } from "next/navigation";

type Props = {
Expand Down
6 changes: 5 additions & 1 deletion app/(batches)/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ import { CommandMenu } from "@/components/command-menu";
import { Icons } from "@/components/icons";
import MainNav from "@/components/layout/main-nav";
import { DocsSidebarNav } from "@/components/layout/sidebar-nav";

import { ModeToggle } from "@/components/mode-toggle";
import { navConfig } from "@/config/nav";
import { docsConfig } from "@/config/sidebar";
import Link from "next/link";


interface BatchRootLayoutProps {
children: React.ReactNode;
}
Expand All @@ -15,7 +18,7 @@ const CourseRootLayout = ({ children }: BatchRootLayoutProps) => {
<div className="flex min-h-screen flex-col">
<header className="sticky top-0 z-40 w-full border-b bg-background">
<div className="container flex h-16 items-center space-x-4 sm:justify-between sm:space-x-0">
<MainNav items={docsConfig.mainNav}>
<MainNav items={navConfig}>
<DocsSidebarNav items={docsConfig.sidebarNav} />
</MainNav>

Expand All @@ -24,6 +27,7 @@ const CourseRootLayout = ({ children }: BatchRootLayoutProps) => {
<div className=" px-3 hidden md:flex">
<CommandMenu />
</div>
<ModeToggle/>
<Link href="https://github.com/FrontendFreaks" target="_blank" rel="noreferrer">
<Icons.gitHub className="h-7 w-7" />
<span className="sr-only">GitHub</span>
Expand Down
5 changes: 4 additions & 1 deletion app/(docs)/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { CommandMenu } from "@/components/command-menu";
import { Icons } from "@/components/icons";
import { DocSideNav } from "@/components/layout/docs-nav";
import MainNav from "@/components/layout/main-nav";
import { ModeToggle } from "@/components/mode-toggle";
import { navConfig } from "@/config/nav";
import { DocumentationConfig } from "@/config/docs";
import { docsConfig } from "@/config/sidebar";
import Link from "next/link";
Expand All @@ -15,7 +17,7 @@ const CourseRootLayout = ({ children }: BatchRootLayoutProps) => {
<div className="flex min-h-screen flex-col">
<header className="sticky top-0 z-40 w-full border-b bg-background">
<div className="container flex h-16 items-center space-x-4 justify-between sm:space-x-0">
<MainNav items={docsConfig.mainNav}>
<MainNav items={navConfig}>
<DocSideNav items={DocumentationConfig} />
</MainNav>

Expand All @@ -24,6 +26,7 @@ const CourseRootLayout = ({ children }: BatchRootLayoutProps) => {
<div className=" px-3 hidden md:flex">
<CommandMenu />
</div>
<ModeToggle/>
<Link href="https://github.com/FrontendFreaks" target="_blank" rel="noreferrer">
<Icons.gitHub className="h-7 w-7" />
<span className="sr-only">GitHub</span>
Expand Down
1 change: 0 additions & 1 deletion app/(marketing)/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Faq } from "@/components/faq";
import Tracks from "@/components/tracks";
import { Button, buttonVariants } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { cn } from "@/lib/utils";
import Image from "next/image";
import Link from "next/link";
Expand Down
140 changes: 140 additions & 0 deletions components/code-editor.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
"use client";

import { useEffect, useState } from "react";
import Editor from "@monaco-editor/react";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faHtml5, faCss3, faJs } from "@fortawesome/free-brands-svg-icons";
import { faPlay, faCircleXmark } from "@fortawesome/free-solid-svg-icons";

interface File {
name: string;
language: string;
value: string;
}

const files: Record<string, File> = {
"index.html": {
name: "index.html",
language: "html",
value: `<!-- Your HTML code goes here -->\n<!DOCTYPE html>\n<html>\n<head>\n <title>My Page</title>\n</head>\n<body>\n <h1>Hello, HTML!</h1>\n</body>\n</html>`,
},
"style.css": {
name: "style.css",
language: "css",
value: `/* Your CSS code goes here */\nbody { background-color: #f0f0f0; }`,
},
"script.js": {
name: "script.js",
language: "javascript",
value: `// Your JavaScript code goes here\nconsole.log('Hello, JavaScript!');`,
},

};


export default function CodeEditor() {
const [fileName, setFileName] = useState("index.html");
const [htmlCode, setHtmlCode] = useState("");
const [cssCode, setCssCode] = useState("");
const [jsCode, setJsCode] = useState("");
const [outputVisible, setOutputVisible] = useState(false);

useEffect(() => {
const runBtn = document.getElementById("runCode");
const clsBtn = document.getElementById("closeWindow");

runBtn?.addEventListener("click", () => {
setHtmlCode(files["index.html"].value);
setCssCode(files["style.css"].value);
setJsCode(files["script.js"].value);

setOutputVisible(true);
});

clsBtn?.addEventListener("click", () => {
setOutputVisible(false);
});
}, []);

const file = files[fileName];

const handleEditorChange: import("@monaco-editor/react").OnChange = (value) => {
if (value !== undefined) {
files[fileName].value = value;
}
};

return (
<>
<div className="bg-gray-900 bg-opacity-90 p-4 flex gap-4">
{Object.keys(files).map((fileKey) => (
<button
key={fileKey}
className={`px-2 py-1 rounded ${fileName === fileKey
? "bg-gray-500 cursor-not-allowed text-white"
: "bg-gray-700 hover:bg-gray-600 text-white"
}`}
disabled={fileName === fileKey}
onClick={() => setFileName(fileKey)}
>
<div className="flex items-center">
<div className="mr-2">
{file.language === "javascript" && <FontAwesomeIcon icon={faJs} />}
{file.language === "css" && <FontAwesomeIcon icon={faCss3} />}
{file.language === "html" && <FontAwesomeIcon icon={faHtml5} />}
</div>
<div>{fileKey}</div>
</div>
</button>
))}
<button
className="flex items-center bg-blue-500 hover:bg-blue-600 text-white px-2 py-1 rounded"
id="runCode"
>
<div className="mr-2">
<FontAwesomeIcon icon={faPlay} />
</div>
Run
</button>
</div>

<Editor
height="70vh"
theme="vs-dark"
saveViewState={true}
path={file.name}
defaultLanguage={file.language}
defaultValue={file.value}
onChange={handleEditorChange}
value={file.value}
/>

{outputVisible && (
<div className="fixed min-h-[40vh] min-w-[40vh] inset-0 flex items-center justify-center bg-black bg-opacity-70 z-50">
<div className="bg-white relative p-4 rounded-lg shadow-lg text-center">
<button
className="absolute top-1 right-1 px-1 rounded-2xl bg-gray-400"
id="closeWindow"
onClick={() => setOutputVisible(false)}
>
<div>
<FontAwesomeIcon icon={faCircleXmark} />
</div>
</button>
<iframe
title="output"
srcDoc={`
<html>
<body>${htmlCode}</body>
<style>${cssCode}</style>
<script>${jsCode}</script>
</html>
`}
className="w-full h-96 py-5 mx-auto"
/>
</div>
</div>
)}
</>
);
}
2 changes: 2 additions & 0 deletions components/icons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
LogOut,
LucideProps,
Moon,
Menu,
MoreVertical,
Pizza,
Plus,
Expand All @@ -41,6 +42,7 @@ export type Icon = LucideIcon;

export const Icons = {
logo: Anchor,
menu: Menu,
logout: LogOut,
link: Link,
comment: MessageSquare,
Expand Down
2 changes: 1 addition & 1 deletion components/layout/docs-nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function DocSideNav({ items }: DocsSidebarNavProps) {
<div className="dark:text-gray-400">
{item.items ? (
<DocsSidebarNavItems items={item.items} pathname={pathname} />
) : null}
) : null}
</div>
</div>
))}
Expand Down
4 changes: 2 additions & 2 deletions components/layout/main-nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default function MainNav({ items, children }: MainNavProps) {
<div className="flex gap-6 md:gap-10 w-full">
<Link href="/" className="hidden items-center space-x-2 md:flex">
<span className="hidden text-lg font-bold sm:inline-block">
Frontend Freaks
Frontend Freaks
</span>
</Link>

Expand All @@ -48,7 +48,7 @@ export default function MainNav({ items, children }: MainNavProps) {
className="flex items-center space-x-2 md:hidden"
onClick={() => setShowMobileMenu(!showMobileMenu)}
>
{/* {showMobileMenu ? <Icons.close /> : <Icons.logo />} */}
{showMobileMenu ? <Icons.close /> : <Icons.menu />}
<span className="font-bold">Frontend Freaks</span>
</button>
{showMobileMenu && items && (
Expand Down
38 changes: 19 additions & 19 deletions components/layout/sidebar-nav.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
"use client"
"use client";

import Link from "next/link"
import { usePathname } from "next/navigation"
import Link from "next/link";
import { usePathname } from "next/navigation";

import { cn } from "@/lib/utils"
import { NavItem, SidebarNav, SidebarNavItem } from "@/types"
import { cn } from "@/lib/utils";
import { NavItem, SidebarNav, SidebarNavItem } from "@/types";
import {
Accordion,
AccordionContent,
AccordionItem,
AccordionTrigger,
} from "../ui/accordion"
} from "../ui/accordion";

export interface DocsSidebarNavProps {
items: SidebarNav[]
items: SidebarNav[];
}

export function DocsSidebarNav({ items }: DocsSidebarNavProps) {
const pathname = usePathname()
const pathname = usePathname();

return items.length ? (
<div className="w-full text-slate-800 ">
Expand All @@ -33,8 +33,8 @@ export function DocsSidebarNav({ items }: DocsSidebarNavProps) {
<AccordionContent>
{item.items ? (
<div className="dark:text-gray-400">
{item.items.map(item => (
<>
{item.items.map((item,index) => (
<div key={index}>
{item.href ? (
<DocsSidebarNavItem item={item} pathname={pathname} />
) : (
Expand All @@ -58,7 +58,7 @@ export function DocsSidebarNav({ items }: DocsSidebarNavProps) {
</AccordionItem>
</Accordion>
)}
</>
</div>
))}
</div>
) : null}
Expand All @@ -68,12 +68,12 @@ export function DocsSidebarNav({ items }: DocsSidebarNavProps) {
</div>
))}
</div>
) : null
) : null;
}

interface DocsSidebarNavItemsProps {
items: NavItem[] | undefined
pathname: string | null
items: NavItem[] | undefined;
pathname: string | null;
}

export function DocsSidebarNavItems({
Expand All @@ -85,15 +85,15 @@ export function DocsSidebarNavItems({
{items.map((item, index) => {
return (
<DocsSidebarNavItem key={index} item={item} pathname={pathname} />
)
);
})}
</div>
) : null
) : null;
}

interface DocsSidebarNavItemsrops {
item: NavItem | SidebarNavItem
pathname: string | null
item: NavItem | SidebarNavItem;
pathname: string | null;
}

export function DocsSidebarNavItem({
Expand All @@ -113,5 +113,5 @@ export function DocsSidebarNavItem({
<span className="flex w-full cursor-not-allowed items-center rounded-md p-2 opacity-60">
{item.title}
</span>
)
);
}
4 changes: 3 additions & 1 deletion components/layout/site-header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ export default function SiteHeader({}: Props) {
<MainNav items={navConfig} />
<ModeToggle />
<a href="https://discord.com/invite/vee94km4Wh" target="_blank">
<Button className="rounded-full">Mentorship</Button>
<Button className="hidden md:inline-block rounded-full">
Mentorship
</Button>
</a>
</div>
</header>
Expand Down
2 changes: 2 additions & 0 deletions components/markdown/mdx.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useMDXComponent } from "next-contentlayer/hooks";

import { cn } from "@/lib/utils";
import { Callout } from "./callout";
import CodeEditor from "../code-editor";
import { MdxCard } from "./mdx-card";
import { Tabs, TabsList, TabsTrigger, TabsContent } from "../ui/tabs";
import VideoPlayer from "../video-player";
Expand Down Expand Up @@ -153,6 +154,7 @@ const components = {
),
Image,
Callout,
CodeEditor,
Card: MdxCard,
VideoPlayer,
HeadingWithLink,
Expand Down
2 changes: 1 addition & 1 deletion config/nav.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ export const navConfig: NavItem[] = [
},
{
title: "Docs",
href: "https://frontendfreaks.vercel.app/docs",
href: "/docs",
},
];
Loading

0 comments on commit 5de5884

Please sign in to comment.