Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEV to PROD Deployment: Imporvements #2

Merged
merged 1 commit into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/assets/images/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import DownloadIcon from "./DownloadIcon.png";
import FallbackResetIcon from "./FallbackResetIcon.png";
import FallbackExpandIcon from "./FallbackExpandIcon.png";
import FallbackDownloadIcon from "./FallbackDownloadIcon.png";
import Wallpaper from "./Wallpaper.jpg";

export {
ResetIcon,
Expand All @@ -13,3 +14,13 @@ export {
FallbackExpandIcon,
FallbackDownloadIcon,
};

export const imageSources = [
ResetIcon,
ExpandIcon,
DownloadIcon,
FallbackResetIcon,
FallbackExpandIcon,
FallbackDownloadIcon,
Wallpaper,
];
6 changes: 4 additions & 2 deletions src/components/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
initialHtmlContent,
initialJsContent,
} from "../constants";
import { imageSources } from "../assets/images";
import ImagePreloader from "../utilities/ImagePreloader";

function App() {
/*
Expand Down Expand Up @@ -41,7 +43,7 @@ function App() {
const handleTopPaneAnimationEnd = () => setShowIframe(true);

return (
<>
<ImagePreloader images={imageSources}>
<div
className="container primary-container"
onAnimationEnd={handleTopPaneAnimationEnd}
Expand Down Expand Up @@ -80,7 +82,7 @@ function App() {
/>
</div>
)}
</>
</ImagePreloader>
);
}

Expand Down
28 changes: 28 additions & 0 deletions src/components/CircularLoader.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
.loader-container{
display: flex;
width:100vw;
height: 100vh;
justify-content: center;
align-items: center;
}

.spin{
width:6vw;
height:6vw;
border-radius:50%;
box-shadow: 2px 2px 8px white,
4px 4px 8px #fff;
border:10px solid #fff;
border-bottom:10px solid transparent;
border-top:10px solid transparent;
animation: spin 1.4s linear infinite;
}

@keyframes spin{
0%{
transform: rotate(0deg);
}
100%{
transform: rotate(-360deg);
}
}
11 changes: 11 additions & 0 deletions src/components/CircularLoader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import "./CircularLoader.css";

const CircularLoader = () => {
return (
<div class="loader-container">
<div class="spin"></div>
</div>
);
};

export default CircularLoader;
32 changes: 3 additions & 29 deletions src/constants/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ export const initialHtmlContent = `<html>
<body>
<div>RESET THE EDITORS & START CODING!!!</div>
<div class="spin">
<div class="inner"></div>
</div>
<div class="note-container">
<div class="note">To reset, click/hover on RED button on toolbar</div>
Expand All @@ -15,7 +14,7 @@ export const initialHtmlContent = `<html>
</html> `;

export const initialCssContent = `body,.spin{
position:relative;
position:relative;
display:flex;
justify-content:space-evenly;
flex-direction:column;
Expand All @@ -30,8 +29,8 @@ body{
overflow:hidden;
}
.spin{
width:150px;
height:150px;
width:6vw;
height:6vw;
border-radius:50%;
box-shadow: 2px 2px 8px white,
4px 4px 8px #fff;
Expand All @@ -49,31 +48,6 @@ body{
font-size:15px;
margin-top:10px;
}
.inner{
width: 120px;
height:120px;
border-radius: 50%;
border: 8px solid #eee;
border-right:10px solid transparent;
animation: inner 1s linear infinite;
}
@keyframes inner{
0%{
transform: rotate(0deg);
}
20%{
transform: rotate(10deg);
}
50%{
transform: rotate(100deg);
}
75%{
transform: rotate(200deg);
}
100%{
transform: rotate(360deg);
}
}
@keyframes spin{
0%{
transform: rotate(0deg);
Expand Down
1 change: 1 addition & 0 deletions src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ body {

iframe{
border: none;
overflow: scroll;
}

.container {
Expand Down
30 changes: 30 additions & 0 deletions src/utilities/ImagePreloader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { useEffect, useState } from "react";
import CircularLoader from "../components/CircularLoader";

const ImagePreloader = ({ images, children }) => {
const [isLoading, setIsLoading] = useState(true);

useEffect(() => {
const imagePromises = images.map((src) => {
return new Promise((resolve, reject) => {
const img = new Image();
img.src = src;
img.onload = resolve;
img.onerror = reject;
});
});

Promise.all(imagePromises)
.then(() => {
setIsLoading(false);
})
.catch((error) => {
console.error("Error preloading images:", error);
setIsLoading(false);
});
}, [images]);

return isLoading ? <CircularLoader /> : children;
};

export default ImagePreloader;