@@ -18,6 +18,7 @@ import {
1818 DownloadIcon ,
1919 Upload ,
2020 Linkedin ,
21+ Share ,
2122} from "lucide-react"
2223import { Button , buttonVariants } from "@/components/ui/button"
2324import { Separator } from "@/components/ui/separator"
@@ -26,9 +27,12 @@ import { ConfirmDialog } from "./confirm-dialog"
2627import { cn } from "@/lib/utils"
2728import { useTheme } from "next-themes"
2829import { clearAllChats } from "@/actions/chat"
29- import { signOut } from "next-auth/react"
30- import { redirect } from "next/navigation"
30+ import { signOut , useSession } from "next-auth/react"
31+ import { redirect , usePathname } from "next/navigation"
3132import Link from "next/link"
33+ import { CollaborationAdDialog } from "./CollaborationAdDialog"
34+ import { RoomSharingDialog } from "./RoomSharingDialog"
35+ import CollaborationStartdDialog from "./CollaborationStartdDialog"
3236
3337interface SidebarProps {
3438 isOpen : boolean
@@ -44,10 +48,13 @@ interface SidebarProps {
4448}
4549
4650export function MainMenuStack ( { isOpen, onClose, canvasColor, setCanvasColor, isMobile, roomName, isStandalone = false , onClearCanvas, onExportCanvas, onImportCanvas } : SidebarProps ) {
47- const [ clearDialogOpen , setClearDialogOpen ] = useState ( false )
48- const { theme, setTheme } = useTheme ( )
51+ const [ clearDialogOpen , setClearDialogOpen ] = useState ( false ) ;
52+ const { theme, setTheme } = useTheme ( ) ;
53+ const { data : session } = useSession ( ) ;
4954
50- console . log ( 'isOpen = ' , isOpen ) ;
55+ const pathname = usePathname ( ) ;
56+ const [ isShareOpen , setIsShareOpen ] = useState ( false ) ;
57+ const decodedPathname = decodeURIComponent ( pathname ) ;
5158
5259 useEffect ( ( ) => {
5360 const handleOutsideClick = ( e : MouseEvent ) => {
@@ -93,7 +100,12 @@ export function MainMenuStack({ isOpen, onClose, canvasColor, setCanvasColor, is
93100 < SidebarItem icon = { TrashIcon } label = "Clear canvas" onClick = { ( ) => setClearDialogOpen ( true ) } />
94101 < SidebarItem icon = { DownloadIcon } label = "Export Drawing" onClick = { onExportCanvas } />
95102 < SidebarItem icon = { Upload } label = "Import Drawing" onClick = { onImportCanvas } />
96- < SidebarItem icon = { UserPlus } onClick = { ( ) => redirect ( '/auth/signup' ) } label = "Sign up" className = "text-color-promo hover:text-color-promo font-bold" />
103+ < SidebarItem icon = { Share } label = "Live collaboration" onClick = { ( ) => setIsShareOpen ( true ) } />
104+ { session ?. user && session ?. user . id ? (
105+ < CollaborationStartdDialog open = { isShareOpen } onOpenChange = { setIsShareOpen } />
106+ ) : (
107+ < CollaborationAdDialog open = { isShareOpen } onOpenChange = { setIsShareOpen } />
108+ ) }
97109 </ >
98110 ) : (
99111 < >
@@ -106,12 +118,16 @@ export function MainMenuStack({ isOpen, onClose, canvasColor, setCanvasColor, is
106118 Room Name: < span > { roomName } </ span >
107119 </ Button >
108120 < SidebarItem icon = { Trash } label = "Reset the canvas" onClick = { ( ) => setClearDialogOpen ( true ) } />
109- < SidebarItem icon = { LogOut } label = "Log Out" onClick = { ( ) => signOut ( { callbackUrl : '/' } ) } />
121+ < RoomSharingDialog open = { isShareOpen } onOpenChange = { setIsShareOpen } link = { ` ${ process . env . NODE_ENV !== 'production' ? 'http://localhost:3000' : 'https://collabydraw.com' } / ${ decodedPathname } ` } />
110122 </ >
111123 ) }
124+ { session ?. user && session ?. user . id ? (
125+ < SidebarItem icon = { LogOut } label = "Log Out" onClick = { ( ) => signOut ( { callbackUrl : '/' } ) } />
126+ ) : (
127+ < SidebarItem icon = { UserPlus } onClick = { ( ) => redirect ( '/auth/signup' ) } label = "Sign up" className = "text-color-promo hover:text-color-promo font-bold" />
128+ ) }
112129
113130 < Separator className = "my-4 dark:bg-default-border-color-dark" />
114-
115131 < SidebarLinkItem icon = { Github } label = "GitHub" url = "https://github.com/coderomm" />
116132 < SidebarLinkItem icon = { Twitter } label = "Twitter / X" url = "https://x.com/1omsharma" />
117133 < SidebarLinkItem icon = { Linkedin } label = "Linkedin" url = "https://www.linkedin.com/in/1omsharma/" />
@@ -165,8 +181,7 @@ function SidebarItem({ icon: Icon, label, shortcut, className, onClick }: Sideba
165181 className ,
166182 ) }
167183 onClick = { onClick }
168- target = "_blank"
169- rel = "noopener noreferrer"
184+ title = { label }
170185 >
171186 < Icon className = "h-4 w-4" />
172187 < span > { label } </ span >
@@ -196,6 +211,9 @@ function SidebarLinkItem({ icon: Icon, label, shortcut, className, url }: Sideba
196211 className ,
197212 ) }
198213 href = { url }
214+ target = "_blank"
215+ rel = "noopener noreferrer"
216+ title = { label }
199217 >
200218 < Icon className = "h-4 w-4" />
201219 < span > { label } </ span >
0 commit comments