Skip to content

Commit e01bf65

Browse files
committed
Enlarge The Resume Template Previews
Signed-off-by: Tal Jacob <taljacob2@gmail.com>
1 parent 02cab00 commit e01bf65

1 file changed

Lines changed: 18 additions & 62 deletions

File tree

nextstep-frontend/src/pages/Resume.tsx

Lines changed: 18 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ const TemplateCard = styled(Card)(({ theme }) => ({
112112
flexDirection: 'column',
113113
position: 'relative',
114114
'& .MuiCardMedia-root': {
115-
height: 300,
115+
height: '70vh',
116+
minHeight: '500px',
116117
backgroundSize: 'contain',
117118
backgroundPosition: 'center',
118119
backgroundColor: theme.palette.grey[100],
@@ -129,8 +130,6 @@ const Resume: React.FC = () => {
129130
const [error, setError] = useState('');
130131
const [templates, setTemplates] = useState<Array<{ name: string; content: string; type: string }>>([]);
131132
const [selectedTemplate, setSelectedTemplate] = useState<number | null>(null);
132-
const [previewOpen, setPreviewOpen] = useState(false);
133-
const [previewTemplate, setPreviewTemplate] = useState<{ name: string; content: string; type: string } | null>(null);
134133
const [previewUrl, setPreviewUrl] = useState<string | null>(null);
135134
const fileInputRef = useRef<HTMLInputElement>(null);
136135
const feedbackEndRef = useRef<HTMLDivElement>(null);
@@ -146,6 +145,10 @@ const Resume: React.FC = () => {
146145
try {
147146
const response = await api.get('/resume/templates');
148147
setTemplates(response.data);
148+
// Initialize preview for the first template if it's a Word document
149+
if (response.data.length > 0 && response.data[0].type.includes('word')) {
150+
handlePreviewOpen(response.data[0]);
151+
}
149152
} catch (error) {
150153
console.error('Error fetching templates:', error);
151154
}
@@ -281,9 +284,6 @@ const Resume: React.FC = () => {
281284
};
282285

283286
const handlePreviewOpen = async (template: { name: string; content: string; type: string }) => {
284-
setPreviewTemplate(template);
285-
setPreviewOpen(true);
286-
287287
if (template.type.includes('word')) {
288288
try {
289289
const fileName = `${template.name}${template.type.includes('docx') ? '.docx' : '.doc'}`;
@@ -298,42 +298,9 @@ const Resume: React.FC = () => {
298298
};
299299

300300
const handlePreviewClose = () => {
301-
setPreviewOpen(false);
302-
setPreviewTemplate(null);
303301
setPreviewUrl(null);
304302
};
305303

306-
const renderTemplatePreview = (template: { name: string; content: string; type: string }) => {
307-
if (template.type === 'application/pdf') {
308-
const base64Data = `data:${template.type};base64,${template.content}`;
309-
return (
310-
<iframe
311-
src={base64Data}
312-
style={{ width: '100%', height: '100%', border: 'none' }}
313-
title={template.name}
314-
/>
315-
);
316-
} else if (template.type.includes('word')) {
317-
if (previewUrl) {
318-
return (
319-
<iframe
320-
src={previewUrl}
321-
style={{ width: '100%', height: '100%', border: 'none' }}
322-
title={template.name}
323-
/>
324-
);
325-
} else {
326-
return (
327-
<Box sx={{ p: 2, textAlign: 'center' }}>
328-
<Typography variant="h6">Loading Preview...</Typography>
329-
<CircularProgress />
330-
</Box>
331-
);
332-
}
333-
}
334-
return null;
335-
};
336-
337304
const renderStepContent = (step: number) => {
338305
switch (step) {
339306
case 0:
@@ -432,9 +399,7 @@ const Resume: React.FC = () => {
432399
justifyContent: 'center',
433400
position: 'relative',
434401
height: '100%',
435-
cursor: 'pointer'
436402
}}
437-
onClick={() => handlePreviewOpen(template)}
438403
>
439404
{template.type === 'application/pdf' ? (
440405
<iframe
@@ -443,12 +408,18 @@ const Resume: React.FC = () => {
443408
title={template.name}
444409
/>
445410
) : (
446-
<Box sx={{ p: 2, textAlign: 'center' }}>
447-
<Typography variant="h6">Word Document</Typography>
448-
<Typography variant="body2" color="text.secondary">
449-
Click to preview
450-
</Typography>
451-
</Box>
411+
previewUrl ? (
412+
<iframe
413+
src={previewUrl}
414+
style={{ width: '100%', height: '100%', border: 'none' }}
415+
title={template.name}
416+
/>
417+
) : (
418+
<Box sx={{ p: 2, textAlign: 'center' }}>
419+
<Typography variant="h6">Loading Preview...</Typography>
420+
<CircularProgress />
421+
</Box>
422+
)
452423
)}
453424
</CardMedia>
454425
<CardContent>
@@ -475,21 +446,6 @@ const Resume: React.FC = () => {
475446
</TemplateCard>
476447
))}
477448
</Carousel>
478-
479-
<PreviewModal
480-
open={previewOpen}
481-
onClose={handlePreviewClose}
482-
closeAfterTransition
483-
>
484-
<Zoom in={previewOpen}>
485-
<ModalContent>
486-
<CloseButton onClick={handlePreviewClose}>
487-
<CloseIcon />
488-
</CloseButton>
489-
{previewTemplate && renderTemplatePreview(previewTemplate)}
490-
</ModalContent>
491-
</Zoom>
492-
</PreviewModal>
493449
</Box>
494450
);
495451
case 2:

0 commit comments

Comments
 (0)