|
| 1 | +import { |
| 2 | + AiSettingsPanel, |
| 3 | + AnalysisResultsContainer, |
| 4 | + ModelSelector, |
| 5 | + QueryControls, |
| 6 | + SessionControls, |
| 7 | + PromptSuggestions, |
| 8 | +} from '@sqlrooms/ai'; |
| 9 | +import { |
| 10 | + Button, |
| 11 | + Dialog, |
| 12 | + DialogContent, |
| 13 | + DialogHeader, |
| 14 | + DialogTitle, |
| 15 | + DialogTrigger, |
| 16 | + SkeletonPane, |
| 17 | + Tabs, |
| 18 | + TabsContent, |
| 19 | + TabsList, |
| 20 | + TabsTrigger, |
| 21 | + useDisclosure, |
| 22 | +} from '@sqlrooms/ui'; |
| 23 | +import {Settings} from 'lucide-react'; |
| 24 | +import {useRoomStore} from '../store'; |
| 25 | + |
| 26 | +export const MainView: React.FC = () => { |
| 27 | + const currentSessionId = useRoomStore( |
| 28 | + (s) => s.ai.config.currentSessionId || null, |
| 29 | + ); |
| 30 | + const isDataAvailable = useRoomStore((state) => state.room.initialized); |
| 31 | + |
| 32 | + const settingsPanelOpen = useDisclosure(); |
| 33 | + |
| 34 | + return ( |
| 35 | + <div className="flex h-full w-full flex-col gap-0 overflow-hidden p-4"> |
| 36 | + <div className="mb-4 flex items-center justify-between gap-2"> |
| 37 | + <SessionControls className="w-full" /> |
| 38 | + {currentSessionId && ( |
| 39 | + <Dialog |
| 40 | + open={settingsPanelOpen.isOpen} |
| 41 | + onOpenChange={(open) => { |
| 42 | + if (open) { |
| 43 | + settingsPanelOpen.onOpen(); |
| 44 | + } else { |
| 45 | + settingsPanelOpen.onClose(); |
| 46 | + } |
| 47 | + }} |
| 48 | + > |
| 49 | + <DialogTrigger asChild> |
| 50 | + <Button |
| 51 | + variant="outline" |
| 52 | + className="flex items-center justify-center transition-colors hover:bg-accent" |
| 53 | + title="Configuration" |
| 54 | + size="sm" |
| 55 | + > |
| 56 | + <Settings className="h-4 w-4" /> |
| 57 | + </Button> |
| 58 | + </DialogTrigger> |
| 59 | + <DialogContent className="flex h-[80vh] w-[90vw] max-w-3xl flex-col overflow-hidden"> |
| 60 | + <DialogHeader> |
| 61 | + <DialogTitle>AI Assistant Settings</DialogTitle> |
| 62 | + </DialogHeader> |
| 63 | + <Tabs |
| 64 | + defaultValue="providers" |
| 65 | + className="flex min-h-0 flex-1 flex-col" |
| 66 | + > |
| 67 | + <TabsList className="grid w-full flex-shrink-0 grid-cols-3"> |
| 68 | + <TabsTrigger value="providers">Providers</TabsTrigger> |
| 69 | + <TabsTrigger value="models">Models</TabsTrigger> |
| 70 | + <TabsTrigger value="parameters">Parameters</TabsTrigger> |
| 71 | + </TabsList> |
| 72 | + <TabsContent |
| 73 | + value="providers" |
| 74 | + className="flex-1 overflow-y-auto" |
| 75 | + > |
| 76 | + <AiSettingsPanel.ProvidersSettings /> |
| 77 | + </TabsContent> |
| 78 | + <TabsContent value="models" className="flex-1 overflow-y-auto"> |
| 79 | + <AiSettingsPanel.ModelsSettings /> |
| 80 | + </TabsContent> |
| 81 | + <TabsContent |
| 82 | + value="parameters" |
| 83 | + className="flex-1 overflow-y-auto" |
| 84 | + > |
| 85 | + <AiSettingsPanel.ModelParametersSettings /> |
| 86 | + </TabsContent> |
| 87 | + </Tabs> |
| 88 | + </DialogContent> |
| 89 | + </Dialog> |
| 90 | + )} |
| 91 | + </div> |
| 92 | + <div className="print-container flex-grow overflow-auto"> |
| 93 | + {!currentSessionId ? ( |
| 94 | + <div className="flex h-full w-full flex-col items-center justify-center"> |
| 95 | + <p className="mt-4 text-muted-foreground">No session selected</p> |
| 96 | + </div> |
| 97 | + ) : isDataAvailable ? ( |
| 98 | + <AnalysisResultsContainer key={currentSessionId} /> |
| 99 | + ) : ( |
| 100 | + <div className="flex h-full w-full flex-col items-center justify-center"> |
| 101 | + <SkeletonPane className="p-4" /> |
| 102 | + <p className="mt-4 text-muted-foreground">Loading database...</p> |
| 103 | + </div> |
| 104 | + )} |
| 105 | + </div>{' '} |
| 106 | + <PromptSuggestions.Container> |
| 107 | + <PromptSuggestions.Item text="What questions can I ask to get insights from my data?" /> |
| 108 | + <PromptSuggestions.Item text="Show me a summary of the data" /> |
| 109 | + <PromptSuggestions.Item text="What are the key trends?" /> |
| 110 | + <PromptSuggestions.Item text="Help me understand the data structure" /> |
| 111 | + </PromptSuggestions.Container> |
| 112 | + <QueryControls placeholder="What would you like to learn about the data?"> |
| 113 | + <div className="flex items-center justify-end gap-2"> |
| 114 | + <PromptSuggestions.VisibilityToggle /> |
| 115 | + <ModelSelector /> |
| 116 | + </div> |
| 117 | + </QueryControls> |
| 118 | + </div> |
| 119 | + ); |
| 120 | +}; |
0 commit comments