From ed47ee47bf65a3b6f1d3cd4cebee9b16cd1fe6ee Mon Sep 17 00:00:00 2001 From: JohnDoe6345789 Date: Fri, 26 Dec 2025 00:19:36 +0000 Subject: [PATCH] code: nextjs,frontends,users (2 files) --- .../src/components/ScreenshotAnalyzer.tsx | 134 +++++++++--------- frontends/nextjs/src/lib/api/users.ts | 30 +--- 2 files changed, 70 insertions(+), 94 deletions(-) diff --git a/frontends/nextjs/src/components/ScreenshotAnalyzer.tsx b/frontends/nextjs/src/components/ScreenshotAnalyzer.tsx index 795444ecd..08e1f9e59 100644 --- a/frontends/nextjs/src/components/ScreenshotAnalyzer.tsx +++ b/frontends/nextjs/src/components/ScreenshotAnalyzer.tsx @@ -7,8 +7,9 @@ import { CardHeader, Chip, CircularProgress, + Stack, Typography, - Grid, + Grid2 as Grid, } from '@mui/material' import { CameraAlt as CameraIcon, @@ -17,35 +18,25 @@ import { Refresh as RefreshIcon, } from '@mui/icons-material' import { toast } from 'sonner' +import { captureDomSnapshot } from '@/lib/screenshot/capture-dom-snapshot' +import { requestScreenshotAnalysis } from '@/lib/screenshot/request-screenshot-analysis' +import type { ScreenshotAnalysisResult } from '@/lib/screenshot/types' export function ScreenshotAnalyzer() { const [isCapturing, setIsCapturing] = useState(false) const [screenshotData, setScreenshotData] = useState(null) - const [analysis, setAnalysis] = useState('') + const [analysisReport, setAnalysisReport] = useState('') + const [analysisResult, setAnalysisResult] = useState(null) const [isAnalyzing, setIsAnalyzing] = useState(false) const captureScreenshot = async () => { setIsCapturing(true) try { toast.info('Capturing screenshot...') - - const canvas = document.createElement('canvas') - const ctx = canvas.getContext('2d') - - canvas.width = window.innerWidth - canvas.height = document.documentElement.scrollHeight - - if (!ctx) { - throw new Error('Failed to get canvas context') - } - - const response = await fetch(window.location.href) - const blob = await response.blob() - const dataUrl = canvas.toDataURL('image/png') - + const dataUrl = await captureDomSnapshot() setScreenshotData(dataUrl) toast.success('Screenshot captured!') - + await analyzeScreenshot() } catch (error) { console.error('Error capturing screenshot:', error) @@ -58,38 +49,27 @@ export function ScreenshotAnalyzer() { const analyzeScreenshot = async () => { setIsAnalyzing(true) try { - const bodyContent = document.body.innerText.substring(0, 3000) - const htmlStructure = document.body.innerHTML.substring(0, 2000) - - // TODO: Replace with Next.js API route that calls an LLM service - const placeholderAnalysis = `**Screenshot Analysis Feature Unavailable**\n\nThe AI-powered screenshot analysis feature is currently being migrated to work with Next.js. This will be available soon.\n\n**Page**: ${document.title}\n**URL**: ${window.location.href}\n**Viewport**: ${window.innerWidth}x${window.innerHeight}` - - // Original Spark LLM code (commented out): - // const prompt = spark.llmPrompt`Analyze this webpage and provide a detailed assessment: - // - // Page Title: ${document.title} - // URL: ${window.location.href} - // Viewport: ${window.innerWidth}x${window.innerHeight} - // - // Body Text Preview (first 3000 chars): - // ${bodyContent} - // - // HTML Structure Preview (first 2000 chars): - // ${htmlStructure} - // - // Please provide: - // 1. A summary of what this page does - // 2. Key UI elements visible - // 3. Any potential issues or improvements - // 4. Overall assessment of the design and functionality` - // - // const result = await spark.llm(prompt) - // setAnalysis(result) - - setAnalysis(placeholderAnalysis) - toast.info('Analysis feature temporarily disabled during migration') + const textSample = document.body.innerText.substring(0, 3000) + const htmlSample = document.body.innerHTML.substring(0, 3000) + + const result = await requestScreenshotAnalysis({ + title: document.title, + url: window.location.href, + viewport: { + width: window.innerWidth, + height: window.innerHeight, + }, + textSample, + htmlSample, + }) + + setAnalysisReport(result.report) + setAnalysisResult(result) + toast.success('Analysis complete') } catch (error) { console.error('Error analyzing:', error) + setAnalysisReport('') + setAnalysisResult(null) toast.error('Failed to analyze screenshot') } finally { setIsAnalyzing(false) @@ -98,7 +78,7 @@ export function ScreenshotAnalyzer() { const downloadScreenshot = () => { if (!screenshotData) return - + const link = document.createElement('a') link.href = screenshotData link.download = `screenshot-${Date.now()}.png` @@ -113,17 +93,17 @@ export function ScreenshotAnalyzer() { Screenshot Analyzer Capture and analyze the current page - + - - + {screenshotData && ( <> - - -