feat: implemented JSON download
This commit is contained in:
parent
c101d49d19
commit
6fad123dec
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 (
|
||||
<div className="demo-actions">
|
||||
<Link to={primaryAction.to} className="btn btn-primary btn-large">
|
||||
{primaryAction.label}
|
||||
</Link>
|
||||
{analysisData && (
|
||||
<button
|
||||
onClick={handleDownloadJSON}
|
||||
className="btn btn-secondary"
|
||||
title="Download analysis results as JSON file"
|
||||
>
|
||||
Download JSON
|
||||
</button>
|
||||
)}
|
||||
<Link to={secondaryAction.to} className="btn btn-secondary">
|
||||
{secondaryAction.label}
|
||||
</Link>
|
||||
|
||||
@ -72,7 +72,8 @@ export default function ResultsPage() {
|
||||
{/* Trace: SRD_InterfaceReq_0010 - Display rating of grammar and spelling errors */}
|
||||
<GrammarSection grammarSpelling={analysisData.grammar_spelling} />
|
||||
|
||||
<AnalysisActions />
|
||||
{/* Trace: SRD_FuncReq_0018 - Allow user to download response as JSON file */}
|
||||
<AnalysisActions analysisData={analysisData} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user