diff --git a/components/settings/components/report-settings.tsx b/components/settings/components/report-settings.tsx new file mode 100644 index 00000000..d5d510b7 --- /dev/null +++ b/components/settings/components/report-settings.tsx @@ -0,0 +1,68 @@ +'use client' + +import React, { useState } from 'react' +import { Button } from '@/components/ui/button' +import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card' +import { FileDown, Loader2 } from 'lucide-react' +import { useAIState } from 'ai/rsc' +import { useMapData } from '@/components/map/map-data-context' +import { useMap } from '@/components/map/map-context' +import { generateReport } from '@/lib/utils/report-generator' +import { toast } from 'sonner' + +export function ReportSettings() { + const [aiState] = useAIState() + const { mapData } = useMapData() + const { map } = useMap() + const [isGenerating, setIsGenerating] = useState(false) + + const handleDownloadReport = async () => { + if (isGenerating) return + + setIsGenerating(true) + try { + const mapSnapshot = map ? map.getCanvas().toDataURL('image/png') : '' + const chatTitle = aiState.chatId ? `Chat-${aiState.chatId.substring(0, 8)}` : 'QCX-Analysis' + + await generateReport({ + messages: aiState.messages, + drawnFeatures: mapData.drawnFeatures || [], + mapSnapshot, + chatTitle + }) + + toast.success('Report generated successfully') + } catch (error) { + console.error('Failed to generate report:', error) + toast.error('Failed to generate report') + } finally { + setIsGenerating(false) + } + } + + return ( + + + Reports + + Generate and download a PDF report of your current analysis session, including chat history, map snapshot, and drawn feature measurements. + + + + + + + ) +} \ No newline at end of file diff --git a/components/settings/components/settings.tsx b/components/settings/components/settings.tsx index 8806664d..2e0e0a28 100644 --- a/components/settings/components/settings.tsx +++ b/components/settings/components/settings.tsx @@ -15,10 +15,8 @@ import { SystemPromptForm } from './system-prompt-form' import { ModelSelectionForm } from './model-selection-form' import { UserManagementForm } from './user-management-form'; import { Form } from "@/components/ui/form" -import { useSettingsStore, MapProvider } from "@/lib/store/settings"; -import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"; -import { Label } from "@/components/ui/label"; import { useToast } from "@/components/ui/hooks/use-toast" +import { ReportSettings } from './report-settings' import { getSystemPrompt, saveSystemPrompt } from "../../../lib/actions/chat" import { getSelectedModel, saveSelectedModel } from "../../../lib/actions/users" import { useCurrentUser } from "@/lib/auth/use-current-user" @@ -67,7 +65,6 @@ export function Settings({ initialTab = "system-prompt" }: SettingsProps) { const router = useRouter() const [isSaving, setIsSaving] = useState(false) const [currentTab, setCurrentTab] = useState(initialTab); - const { mapProvider, setMapProvider } = useSettingsStore(); const { user, loading: authLoading } = useCurrentUser(); useEffect(() => { @@ -166,7 +163,7 @@ export function Settings({ initialTab = "system-prompt" }: SettingsProps) { System Prompt Model Selection User Management - Map + Reports - - - - Map Provider - Choose the map provider to use in the application. - - - setMapProvider(value as MapProvider)} - className="space-y-2" - > -
- - -
-
- - -
-
-
-
+ +
- +