@@ -12,6 +12,8 @@ import { ChevronRight } from "lucide-react"
1212import { DEFAULT_MDX_CONTENT } from "./DefaultContent"
1313import ChatWindow from "@/components/ChatWindow"
1414import { MDXFileInfo } from "@/lib/chatService"
15+ import { publishProject , getPublishStatus } from '@/lib/publishService' ;
16+ import { toast } from "sonner" ;
1517
1618export default function EditorPage ( ) {
1719 const router = useRouter ( )
@@ -29,6 +31,8 @@ export default function EditorPage() {
2931 const [ selectedSection , setSelectedSection ] = useState < string | undefined > ( undefined )
3032 const [ allMdxFiles , setAllMdxFiles ] = useState < MDXFileInfo [ ] > ( [ ] )
3133 const [ isChatOpen , setIsChatOpen ] = useState ( false ) // Add this state for chat window
34+ const [ isPublishing , setIsPublishing ] = useState ( false ) ;
35+ const [ publishedUrl , setPublishedUrl ] = useState < string | undefined > ( ) ;
3236
3337 // Check if we're on mobile
3438 useEffect ( ( ) => {
@@ -585,6 +589,55 @@ Add detailed reference documentation...
585589 return ( ) => window . removeEventListener ( 'keydown' , handleKeyDown ) ;
586590 } , [ saveVersion ] ) ; // Add saveVersion to dependencies
587591
592+ // Add effect to check initial publish status
593+ useEffect ( ( ) => {
594+ async function checkPublishStatus ( ) {
595+ if ( ! projectId ) return ;
596+
597+ try {
598+ const status = await getPublishStatus ( projectId ) ;
599+ if ( status . status === 'published' && status . url ) {
600+ setPublishedUrl ( status . url ) ;
601+ }
602+ } catch ( error ) {
603+ console . error ( 'Error checking publish status:' , error ) ;
604+ }
605+ }
606+
607+ checkPublishStatus ( ) ;
608+ } , [ projectId ] ) ;
609+
610+ // Add publish handler
611+ const handlePublish = async ( ) => {
612+ if ( ! projectId ) {
613+ toast . error ( 'No project selected' ) ;
614+ return ;
615+ }
616+
617+ console . log ( 'Starting publish process...' ) ;
618+ setIsPublishing ( true ) ;
619+
620+ try {
621+ console . log ( 'Calling publishProject with ID:' , projectId ) ;
622+ const result = await publishProject ( projectId ) ;
623+ console . log ( 'Publish result:' , result ) ;
624+
625+ if ( result . status === 'published' && result . url ) {
626+ setPublishedUrl ( result . url ) ;
627+ toast . success ( 'Documentation published successfully!' ) ;
628+ } else if ( result . error ) {
629+ console . error ( 'Publish error:' , result . error ) ;
630+ toast . error ( result . error ) ;
631+ }
632+ } catch ( error ) {
633+ console . error ( 'Publish error:' , error ) ;
634+ toast . error ( 'Failed to publish documentation' ) ;
635+ } finally {
636+ console . log ( 'Publish process complete' ) ;
637+ setIsPublishing ( false ) ;
638+ }
639+ } ;
640+
588641 return (
589642 < div className = "flex h-full overflow-hidden" >
590643 < div className = { cn ( "flex transition-all duration-300" , sidebarCollapsed ? "w-8" : "" ) } >
@@ -632,6 +685,9 @@ Add detailed reference documentation...
632685 currentVersionIndex = { currentVersionIndex }
633686 onProjectSelect = { handleProjectSelect }
634687 currentProjectId = { projectId || undefined }
688+ isPublishing = { isPublishing }
689+ onPublish = { handlePublish }
690+ publishedUrl = { publishedUrl }
635691 />
636692 < div className = "flex flex-1 overflow-hidden" >
637693 { view !== "preview" && (
0 commit comments