Skip to content

Commit

Permalink
performance: preload background image during loading screen
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristoGrab committed Jun 12, 2023
1 parent 5493e80 commit d099781
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 11 deletions.
1 change: 1 addition & 0 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<head>
<meta charset="utf-8" />
<link rel="icon" href="./favicon.png" />
<link rel="preload" as="image" href="./images/night-sky.webp">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
Expand Down
8 changes: 4 additions & 4 deletions src/components/InfoCard/InfoCard.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
top: 15%;
right: 2%;
background: #13080e;
border: 2px solid #e8ab8c;
border: 2px solid var(--space-orange);
height: clamp(300px, 48vh, 600px);
width: clamp(200px, 20%, 400px);
z-index: 10;
border-radius: 10px;
box-shadow: 1px 1px 10px #e8ab8c inset;
box-shadow: 1px 1px 10px var(--space-orange) inset;
animation: fadeIn 2s linear;
display: flex;
flex-direction: column;
Expand All @@ -29,7 +29,7 @@
position: relative;
background-color: #e8ab8c;
border: none;
color: white;
color: #ffffff;
height: 40px;
width: clamp(40px, 50px, 50px);
font-weight: bold;
Expand All @@ -45,7 +45,7 @@

.infocard-back-button::before {
content: "";
background-color: white;
background-color: #ffffff;
width: 100%;
height: 100%;
position: absolute;
Expand Down
19 changes: 13 additions & 6 deletions src/components/LoadingScreen/LoadingScreen.css
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
.loading-screen {
background: var(--);
height: 100vh;
width: 100vw;
background: var(--menu-brown);
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}

.loading-text {

.loading-title, .loading-text, .loading-subtitle {
color: var(--space-orange);
font-family: "SpaceFont";
}

.loading-bar {
width: 200px;
height: 35px;
background: var(--space-black);
width: 15em;
height: 2em;
border: 2px solid var(--space-orange);
border-radius: 5px;
margin: 0 auto;
margin-top: 20px;
position: relative;
}

.loading-text {
font-size: 1em;
margin-top: 1em;
}

.loading-bar::before {
content: '';
position: absolute;
Expand Down
8 changes: 7 additions & 1 deletion src/components/LoadingScreen/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import { useState } from "react";
import "./LoadingScreen.css";

// This loading screen will be displayed for 3 seconds when the app is first loaded
// This gives the app time to load the assets to avoid the white flash on first load

const LoadingScreen = () => {

// Some flavor text to display while the app is loading
const loadingText = ["Fetching planetary data...", "Parsing atmospheric variables...", "Populating universe..."];

// A state variable to hold the index of the loading text
const [loadingTextIndex, setLoadingTextIndex] = useState(0);

// A timeout to change the loading text every second
setTimeout(() => {
if (loadingTextIndex < 2) setLoadingTextIndex(loadingTextIndex + 1);
else setLoadingTextIndex(0);
Expand All @@ -16,7 +22,7 @@ const LoadingScreen = () => {
<div className="loading-screen">
<h1 className="loading-title">Welcome to Solarium</h1>
<div className="loading-bar"></div>
<div className="loading-update">{loadingText[loadingTextIndex]}</div>
<div className="loading-text">{loadingText[loadingTextIndex]}</div>
</div>
)
}
Expand Down
6 changes: 6 additions & 0 deletions src/components/Viewport/Viewport.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
animation: rotate 500s infinite linear;
display: flex;
justify-content: flex-end;
transition: fadeFromBlack 1s;
}

@keyframes fadeFromBlack {
0% { background-color: black; }
100% { background-color: transparent; }
}

@keyframes rotate {
Expand Down

0 comments on commit d099781

Please sign in to comment.