correct user button in editor

This commit is contained in:
Ishaan Dey 2024-04-18 15:32:27 -04:00
parent a765eea5d8
commit 5f5125cccd
5 changed files with 44 additions and 45 deletions

View File

@ -1,21 +1,28 @@
"use client"
import Navbar from "@/components/editor/navbar" import Navbar from "@/components/editor/navbar"
import { useClerk } from "@clerk/nextjs" import { User } from "@/lib/types"
import { currentUser } from "@clerk/nextjs"
import dynamic from "next/dynamic" import dynamic from "next/dynamic"
import { redirect } from "next/navigation"
const CodeEditor = dynamic(() => import("@/components/editor"), { const CodeEditor = dynamic(() => import("@/components/editor"), {
ssr: false, ssr: false,
}) })
export default function CodePage() { export default async function CodePage() {
const clerk = useClerk() const user = await currentUser()
if (!user) {
redirect("/")
}
const userRes = await fetch(`http://localhost:8787/api/user?id=${user.id}`)
const userData = (await userRes.json()) as User
return ( return (
<div className="overflow-hidden overscroll-none w-screen flex flex-col h-screen bg-background"> <div className="overflow-hidden overscroll-none w-screen flex flex-col h-screen bg-background">
<Navbar /> <Navbar userData={userData} />
<div className="w-screen flex grow"> <div className="w-screen flex grow">
{clerk.loaded ? <CodeEditor /> : null} <CodeEditor />
</div> </div>
</div> </div>
) )

View File

@ -2,7 +2,7 @@ import Image from "next/image"
import Link from "next/link" import Link from "next/link"
import Logo from "@/assets/logo.svg" import Logo from "@/assets/logo.svg"
import DashboardNavbarSearch from "./search" import DashboardNavbarSearch from "./search"
import DashboardUserButton from "./userButton" import UserButton from "../../ui/userButton"
import { User } from "@/lib/types" import { User } from "@/lib/types"
export default function DashboardNavbar({ userData }: { userData: User }) { export default function DashboardNavbar({ userData }: { userData: User }) {
@ -19,7 +19,7 @@ export default function DashboardNavbar({ userData }: { userData: User }) {
</div> </div>
<div className="flex items-center space-x-4"> <div className="flex items-center space-x-4">
<DashboardNavbarSearch /> <DashboardNavbarSearch />
<DashboardUserButton userData={userData} /> <UserButton userData={userData} />
</div> </div>
</div> </div>
) )

View File

@ -22,6 +22,7 @@ import {
} from "lucide-react" } from "lucide-react"
import Tab from "../ui/tab" import Tab from "../ui/tab"
import Sidebar from "./sidebar" import Sidebar from "./sidebar"
import { useClerk } from "@clerk/nextjs"
export default function CodeEditor() { export default function CodeEditor() {
const editorRef = useRef<null | monaco.editor.IStandaloneCodeEditor>(null) const editorRef = useRef<null | monaco.editor.IStandaloneCodeEditor>(null)
@ -52,17 +53,11 @@ export default function CodeEditor() {
}, },
]) ])
const handleEditorMount: OnMount = (editor, monaco) => { // const handleEditorMount: OnMount = (editor, monaco) => {
editorRef.current = editor // editorRef.current = editor
// }
// import("monaco-themes/themes/Blackboard.json").then((data) => { const clerk = useClerk()
// monaco.editor.defineTheme(
// "Blackboard",
// data as monaco.editor.IStandaloneThemeData
// )
// })
// monaco.editor.setTheme("Blackboard")
}
return ( return (
<> <>
@ -79,10 +74,11 @@ export default function CodeEditor() {
<Tab>style.css</Tab> <Tab>style.css</Tab>
</div> </div>
<div className="grow w-full overflow-hidden rounded-md"> <div className="grow w-full overflow-hidden rounded-md">
{clerk.loaded ? (
<Editor <Editor
height="100%" height="100%"
defaultLanguage="typescript" defaultLanguage="typescript"
onMount={handleEditorMount} // onMount={handleEditorMount}
options={{ options={{
minimap: { minimap: {
enabled: false, enabled: false,
@ -95,6 +91,7 @@ export default function CodeEditor() {
}} }}
theme="vs-dark" theme="vs-dark"
/> />
) : null}
</div> </div>
</ResizablePanel> </ResizablePanel>
<ResizableHandle /> <ResizableHandle />

View File

@ -1,11 +1,11 @@
import Image from "next/image" import Image from "next/image"
import Logo from "@/assets/logo.svg" import Logo from "@/assets/logo.svg"
import { Pencil } from "lucide-react" import { Pencil } from "lucide-react"
import { UserButton } from "@clerk/nextjs"
import Link from "next/link" import Link from "next/link"
import { dark } from "@clerk/themes" import { User } from "@/lib/types"
import UserButton from "@/components/ui/userButton"
export default function Navbar() { export default function Navbar({ userData }: { userData: User }) {
return ( return (
<div className="h-14 px-2 w-full flex items-center justify-between border-b border-border"> <div className="h-14 px-2 w-full flex items-center justify-between border-b border-border">
<div className="flex items-center space-x-4"> <div className="flex items-center space-x-4">
@ -22,12 +22,7 @@ export default function Navbar() {
</div> </div>
</div> </div>
</div> </div>
<UserButton <UserButton userData={userData} />
appearance={{
baseTheme: dark,
}}
afterSignOutUrl="/"
/>
</div> </div>
) )
} }

View File

@ -11,7 +11,7 @@ import {
import { User } from "@/lib/types" import { User } from "@/lib/types"
import { LogOut, Pencil } from "lucide-react" import { LogOut, Pencil } from "lucide-react"
export default function DashboardUserButton({ userData }: { userData: User }) { export default function UserButton({ userData }: { userData: User }) {
return ( return (
<DropdownMenu> <DropdownMenu>
<DropdownMenuTrigger> <DropdownMenuTrigger>