import { useStore } from '@nanostores/react'; import { workbenchStore } from '~/lib/stores/workbench'; import { useState, useCallback } from 'react'; import { streamingState } from '~/lib/stores/streaming'; import { ExportChatButton } from '~/components/chat/chatExportAndImport/ExportChatButton'; import { useChatHistory } from '~/lib/persistence'; import { DeployButton } from '~/components/deploy/DeployButton'; import { toast } from 'react-toastify'; import { classNames } from '~/utils/classNames'; import * as DropdownMenu from '@radix-ui/react-dropdown-menu'; interface HeaderActionButtonsProps { chatStarted: boolean; } export function HeaderActionButtons({ chatStarted }: HeaderActionButtonsProps) { const [activePreviewIndex] = useState(0); const previews = useStore(workbenchStore.previews); const activePreview = previews[activePreviewIndex]; const isStreaming = useStore(streamingState); const { exportChat } = useChatHistory(); const [isSyncing, setIsSyncing] = useState(false); const shouldShowButtons = !isStreaming && activePreview; const handleSyncFiles = useCallback(async () => { setIsSyncing(true); try { const directoryHandle = await window.showDirectoryPicker(); await workbenchStore.syncFiles(directoryHandle); toast.success('Files synced successfully'); } catch (error) { console.error('Error syncing files:', error); toast.error('Failed to sync files'); } finally { setIsSyncing(false); } }, []); return (
{/* Export Chat Button */} {chatStarted && shouldShowButtons && } {/* Sync Button */} {shouldShowButtons && (
{isSyncing ? 'Syncing...' : 'Sync'}
{isSyncing ?
:
} {isSyncing ? 'Syncing...' : 'Sync Files'}
)} {/* Deploy Button */} {shouldShowButtons && } {/* Bug Report Button */} {shouldShowButtons && (
)}
); }