Skip to content

Commit

Permalink
adding loading component and apply it
Browse files Browse the repository at this point in the history
  • Loading branch information
No0ne003 committed May 15, 2024
1 parent 1d10953 commit 89c0a0a
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 21 deletions.
3 changes: 2 additions & 1 deletion src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Header from "@/layouts/header";
// components
import Starfield from "react-starfield";
import Cursor from "./components/Cursor";
import Loading from "./components/ui/Loading";
// Data
import menus from "./pages/tree-view/data";

Expand Down Expand Up @@ -61,7 +62,7 @@ function App() {
</div>

<Header setCursorVariant={setCursorVariant} />
<Suspense fallback={<div>Loading...</div>}>
<Suspense fallback={<Loading />}>
<Routes>
<Route path="React-Projects">
<Route
Expand Down
10 changes: 10 additions & 0 deletions src/components/ui/Loading.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

const Loading = () => {
return (
<div className="absolute inset-0 m-auto flex justify-center items-center">
<div className="loader"></div>
</div>
);
};

export default Loading;
6 changes: 1 addition & 5 deletions src/pages/CustomHooks/use-fetch/test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ const UseFetchHookTest = () => {
<h1 className="text-2xl font-mono text-center mb-2">
<span className="text-primary font-bold">useFetch</span> Hook
</h1>
{pending ? (
<div className="absolute inset-0 m-auto flex justify-center items-center">
<div className="loader "></div>
</div>
) : error ? <h3 className="text-rose-500 text-lg">{error}</h3> : data && data.products && data.products.length ? (
{pending ? <Loading /> : error ? <h3 className="text-rose-500 text-lg">{error}</h3> : data && data.products && data.products.length ? (
data.products.map((productItem) => (
<p key={productItem.key} className="text-center">{productItem.title}</p>
))
Expand Down
7 changes: 2 additions & 5 deletions src/pages/GithubProfileFinder/GithubProfileFinder.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { useEffect, useState } from "react";
import { User } from "./User";
import Loading from "@/components/ui/Loading";

const GithubProfileFinder = () => {
const [userName, setUserName] = useState("No0ne003");
Expand Down Expand Up @@ -44,11 +45,7 @@ const GithubProfileFinder = () => {
Search
</Button>
</div>
{loading ? (
<div className="absolute inset-0 m-auto flex justify-center items-center">
<div className="loader "></div>
</div>
) : userData !== null ? (
{loading ? <Loading /> : userData !== null ? (
<User user={userData} />
) : null}
</div>
Expand Down
7 changes: 2 additions & 5 deletions src/pages/LoadMoreData.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Loading from "@/components/ui/Loading";
import { Button } from "@/components/ui/button";
import { useEffect, useState } from "react";

Expand Down Expand Up @@ -34,11 +35,7 @@ function LoadMoreData() {
}, [products]);

if (loading) {
return (
<div className="absolute inset-0 m-auto flex justify-center items-center">
<div className="loader "></div>
</div>
);
return <Loading />
}
console.log(products);

Expand Down
7 changes: 2 additions & 5 deletions src/pages/SearchAutoComplete/SearchAutoComplete.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Input } from "@/components/ui/input";
import { useEffect, useState } from "react";
import { Suggesstions } from "./Suggesstions";
import Loading from "@/components/ui/Loading";

const SearchAutoComplete = () => {
const [loading, setLoading] = useState(false);
Expand Down Expand Up @@ -65,11 +66,7 @@ const SearchAutoComplete = () => {
name="search"
placeholder="Search Users Here..."
/>
{loading ? (
<div className="absolute inset-0 m-auto flex justify-center items-center">
<div className="loader "></div>
</div>
) : showDropDown && <Suggesstions handleClick={handleClick} data={filteredUsers} /> }
{loading ? <Loading /> : showDropDown && <Suggesstions handleClick={handleClick} data={filteredUsers} /> }
</div>
);
};
Expand Down

0 comments on commit 89c0a0a

Please sign in to comment.