feat: implemented JSON download
This commit is contained in:
parent
c101d49d19
commit
6fad123dec
@ -1,4 +1,5 @@
|
|||||||
import { Link } from 'react-router-dom';
|
import { Link } from 'react-router-dom';
|
||||||
|
import type { ResumeAnalysisResult } from '../../types/resumeAnalysis';
|
||||||
|
|
||||||
interface AnalysisActionsProps {
|
interface AnalysisActionsProps {
|
||||||
primaryAction?: {
|
primaryAction?: {
|
||||||
@ -9,17 +10,61 @@ interface AnalysisActionsProps {
|
|||||||
label: string;
|
label: string;
|
||||||
to: 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' },
|
primaryAction = { label: 'Analyze Another Resume', to: '/upload' },
|
||||||
secondaryAction = { label: 'Back to Home', to: '/' }
|
secondaryAction = { label: 'Back to Home', to: '/' },
|
||||||
|
analysisData
|
||||||
}: AnalysisActionsProps) {
|
}: 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 (
|
return (
|
||||||
<div className="demo-actions">
|
<div className="demo-actions">
|
||||||
<Link to={primaryAction.to} className="btn btn-primary btn-large">
|
<Link to={primaryAction.to} className="btn btn-primary btn-large">
|
||||||
{primaryAction.label}
|
{primaryAction.label}
|
||||||
</Link>
|
</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">
|
<Link to={secondaryAction.to} className="btn btn-secondary">
|
||||||
{secondaryAction.label}
|
{secondaryAction.label}
|
||||||
</Link>
|
</Link>
|
||||||
|
|||||||
@ -72,7 +72,8 @@ export default function ResultsPage() {
|
|||||||
{/* Trace: SRD_InterfaceReq_0010 - Display rating of grammar and spelling errors */}
|
{/* Trace: SRD_InterfaceReq_0010 - Display rating of grammar and spelling errors */}
|
||||||
<GrammarSection grammarSpelling={analysisData.grammar_spelling} />
|
<GrammarSection grammarSpelling={analysisData.grammar_spelling} />
|
||||||
|
|
||||||
<AnalysisActions />
|
{/* Trace: SRD_FuncReq_0018 - Allow user to download response as JSON file */}
|
||||||
|
<AnalysisActions analysisData={analysisData} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user