Skip to content

Commit

Permalink
Fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Krzemien97 committed May 9, 2024
1 parent 93dade6 commit e4d5432
Showing 1 changed file with 68 additions and 73 deletions.
141 changes: 68 additions & 73 deletions src/components/FusionEmbed/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,81 +2,76 @@ import React, { useState } from 'react';
import styles from './styles.module.css';

export interface FusionEmbedProps {
url: string;
embedTitle: string;
loading?: 'lazy' | 'eager';
img?: string;
alt?: string;
img_width?: number;
img_height?: number;
}
url: string;
embedTitle: string;
loading?: 'lazy' | 'eager';
img?: string;
alt?: string;
img_width?: number;
img_height?: number;
}

export default function FusionEmbed( props: FusionEmbedProps ) {
export default function FusionEmbed(props: FusionEmbedProps) {
const url = props.url;
const loading = props.loading || 'lazy';
const img = props.img || '/img/misc/cube.webp';
const alt = props.alt || 'placeholder for 3D model';
const img_width = props.img_width || 1920;
const img_height = props.img_height || 1080;
const title = props.embedTitle || '3D CAD model';
const [buttonClicked, setButtonClicked] = useState(false);
const [imageHide, setImageHide] = useState(false);
const [iframeLoaded, setiframeLoaded] = useState(false);

const url = props.url;
const loading = props.loading || 'lazy';
const img = props.img || '/img/misc/cube.webp';
const alt = props.alt || 'placeholder for 3D model';
const img_width = props.img_width || 1920;
const img_height = props.img_height || 1080;
const title = props.embedTitle || "3D CAD model";
const [buttonClicked, setButtonClicked] = useState(false);
const [imageHide, setImageHide] = useState(false);
const [iframeLoaded, setiframeLoaded] = useState(false);
if (props.img) {
if (!props.img_width) throw 'No image width specified!';
if (!props.img_height) throw 'No image height specified!';
}

if( props.img ) {
if( !props.img_width )
throw 'No image width specified!'
if( !props.img_height )
throw 'No image height specified!'
}
const handleButtonClick = () => {
setButtonClicked(true);
setImageHide(false);
};


const handleButtonClick = () => {
setButtonClicked(true);
setImageHide(false);
};
const handleIframeLoad = () => {
setTimeout(() => {
setiframeLoaded(true);
}, 1000);
setTimeout(() => {
setImageHide(true);
}, 2000);
};

const handleIframeLoad = () => {
setTimeout(() => {
setiframeLoaded(true);
}, 1000);
setTimeout(() => {
setImageHide(true);
}, 2000);
}

return (
<div className={styles.embedContainer}>
<div className={styles.embed}>
{buttonClicked && (
<iframe
className={`${styles.iframe} ${iframeLoaded ? styles.iframeVisible : ''}`}
src={url + '?mode=embed'}
title={title}
allowFullScreen={true}
onLoad={handleIframeLoad}
/>
)}
{!imageHide && (
<a
className={styles.a}
onClick={handleButtonClick}
>
<img
loading={loading}
className={`${styles.image} ${iframeLoaded ? styles.imageHidden : ''}`}
src={img}
alt={alt}
width={img_width}
height={img_height}
/>
<span className={`${styles.text} ${iframeLoaded ? styles.imageHidden : ''}`}>
Click to load 3D model
</span>
</a>
)}
</div>
</div>
);
}
return (
<div className={styles.embedContainer}>
<div className={styles.embed}>
{buttonClicked && (
<iframe
className={`${styles.iframe} ${iframeLoaded ? styles.iframeVisible : ''}`}
src={url + '?mode=embed'}
title={title}
allowFullScreen={true}
onLoad={handleIframeLoad}
/>
)}
{!imageHide && (
<a className={styles.a} onClick={handleButtonClick}>
<img
loading={loading}
className={`${styles.image} ${iframeLoaded ? styles.imageHidden : ''}`}
src={img}
alt={alt}
width={img_width}
height={img_height}
/>
<span
className={`${styles.text} ${iframeLoaded ? styles.imageHidden : ''}`}
>
Click to load 3D model
</span>
</a>
)}
</div>
</div>
);
}

0 comments on commit e4d5432

Please sign in to comment.