Skip to content

Commit

Permalink
Loading Status Added
Browse files Browse the repository at this point in the history
  • Loading branch information
yasinuysal33 committed Jan 14, 2023
1 parent f05cca8 commit ff8b046
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 5 deletions.
21 changes: 17 additions & 4 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import {
Environment,
OrbitControls,
PerspectiveCamera,
Html,
useProgress,
} from "@react-three/drei";
import { Canvas } from "@react-three/fiber";
import {
Expand All @@ -19,6 +21,17 @@ import { FloatingGrid } from "./FloatinGrid";
import { Ground } from "./Ground";
import { Rings } from "./Rings";
import "./style.css";
import LoadingSpinner from "./ui/LoadingSpinner";

function Loader() {
const { progress } = useProgress();
return (
<Html center>
<LoadingSpinner />
<div className="loading">{Math.round(progress)}%</div>
</Html>
);
}

function CarShow() {
return (
Expand Down Expand Up @@ -95,11 +108,11 @@ function CarShow() {

function App() {
return (
<Suspense fallback={null}>
<Canvas shadows>
<Canvas shadows>
<Suspense fallback={<Loader />}>
<CarShow />
</Canvas>
</Suspense>
</Suspense>
</Canvas>
);
}

Expand Down
1 change: 0 additions & 1 deletion src/Boxes.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ function Box({ color }) {
const [scale] = useState(() => Math.pow(Math.random(), 2.0) * 0.5 + 0.05);

const [position, setPosition] = useState(getInitialPosition());
console.log(position);

function getInitialPosition() {
let v = new Vector3(
Expand Down
12 changes: 12 additions & 0 deletions src/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,15 @@ canvas {
margin: 0;
overflow: hidden;
}

.loading {
color: rgb(155, 155, 155);
font-family: Verdana, Geneva, Tahoma, sans-serif;
font-size: 12px;
font-weight: 900;
position: absolute;
text-align: center;
margin-top: 20px;
margin-left: 5px;
height: 40px;
}
7 changes: 7 additions & 0 deletions src/ui/LoadingSpinner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import classes from "./LoadingSpinner.module.css";

const LoadingSpinner = () => {
return <div className={classes.spinner}></div>;
};

export default LoadingSpinner;
29 changes: 29 additions & 0 deletions src/ui/LoadingSpinner.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
.spinner {
/* margin: auto;
padding-top: 0; */
/* width: 50%; */
width: 50px;
height: 50px;
position: absolute;
}
.spinner:after {
margin: auto;
width: 50%;
content: "";
display: block;
width: 45px;
height: 45px;

border-radius: 50%;
border: 4px solid teal;
border-color: #05385a transparent rgb(0, 162, 255) transparent;
animation: spinner 1.2s linear infinite;
}
@keyframes spinner {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}

0 comments on commit ff8b046

Please sign in to comment.