From 6fad123deccb7ef633d2db506c513e4badd5eda2 Mon Sep 17 00:00:00 2001 From: Hayden Hargreaves Date: Thu, 26 Mar 2026 12:56:17 -0700 Subject: [PATCH] feat: implemented JSON download --- .../components/analysis/AnalysisActions.tsx | 49 ++++++++++++++++++- web/src/pages/results.tsx | 3 +- 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/web/src/components/analysis/AnalysisActions.tsx b/web/src/components/analysis/AnalysisActions.tsx index 38691ec..31153d9 100644 --- a/web/src/components/analysis/AnalysisActions.tsx +++ b/web/src/components/analysis/AnalysisActions.tsx @@ -1,4 +1,5 @@ import { Link } from 'react-router-dom'; +import type { ResumeAnalysisResult } from '../../types/resumeAnalysis'; interface AnalysisActionsProps { primaryAction?: { @@ -9,17 +10,61 @@ interface AnalysisActionsProps { label: string; to: string; }; + analysisData?: ResumeAnalysisResult; } -export default function AnalysisActions({ +/** + * AnalysisActions component with navigation and download options + * Trace: SRD_FuncReq_0018 - Allow user to download response as JSON file + * Trace: SDD_LLD_0019 - Marshal evaluation data structure into formatted JSON for local user storage + */ +export default function AnalysisActions({ primaryAction = { label: 'Analyze Another Resume', to: '/upload' }, - secondaryAction = { label: 'Back to Home', to: '/' } + secondaryAction = { label: 'Back to Home', to: '/' }, + analysisData }: AnalysisActionsProps) { + + /** + * Downloads the analysis results as a JSON file + * Trace: SRD_FuncReq_0018 - Allow user to download response as JSON file + * Trace: SDD_LLD_0019 - Marshal completed evaluation data structure into formatted JSON + */ + const handleDownloadJSON = () => { + if (!analysisData) return; + + // Create formatted JSON string + const jsonString = JSON.stringify(analysisData, null, 2); + + // Create blob and download link + const blob = new Blob([jsonString], { type: 'application/json' }); + const url = URL.createObjectURL(blob); + + // Create temporary link and trigger download + const link = document.createElement('a'); + link.href = url; + link.download = `resume-analysis-${new Date().toISOString().split('T')[0]}.json`; + document.body.appendChild(link); + link.click(); + + // Cleanup + document.body.removeChild(link); + URL.revokeObjectURL(url); + }; + return (
{primaryAction.label} + {analysisData && ( + + )} {secondaryAction.label} diff --git a/web/src/pages/results.tsx b/web/src/pages/results.tsx index 500630d..12c003b 100644 --- a/web/src/pages/results.tsx +++ b/web/src/pages/results.tsx @@ -72,7 +72,8 @@ export default function ResultsPage() { {/* Trace: SRD_InterfaceReq_0010 - Display rating of grammar and spelling errors */} - + {/* Trace: SRD_FuncReq_0018 - Allow user to download response as JSON file */} +
);