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

Error Page Component added #255

Merged
merged 4 commits into from
Jun 5, 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
32 changes: 18 additions & 14 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useState, useEffect } from "react";
import Profile from "./components/Profile/Profile";
import Search from "./components/Search/Search";
import Sidebar from "./components/Sidebar/Sidebar";
import ErrorPage from "./components/ErrorPage/ErrorPage";
import NoResultFound from "./components/NoResultFound/NoResultFound";
import "./App.css";
import filenames from "./ProfilesList.json";
Expand All @@ -10,7 +11,7 @@ function App() {
const [profiles, setProfiles] = useState([]);
const [searching, setSearching] = useState(false);
const [combinedData, setCombinedData] = useState([]);

const currentUrl = window.location.pathname
useEffect(() => {
// Function to fetch data from a JSON file
const fetchData = async (file) => {
Expand Down Expand Up @@ -72,22 +73,25 @@ function App() {
};

const shuffledProfiles = shuffleProfiles(combinedData);

return (
<div className="App">
<Sidebar />
<Search onSearch={handleSearch} />
{profiles.length === 0 && searching ? (
<NoResultFound />
) : profiles.length === 0 && !searching ? (
shuffledProfiles.map((profile, index) => {
return <Profile data={profile} key={index} />;
})
) : (
profiles.map((profile, index) => {
return <Profile data={profile} key={index} />;
})
)}
{currentUrl === '/' ? <>
<Search onSearch={handleSearch} />
{profiles.length === 0 && searching ? (
<NoResultFound />
) : profiles.length === 0 && !searching ? (
shuffledProfiles.map((profile, index) => {
return <Profile data={profile} key={index} />;
})
) : (
profiles.map((profile, index) => {
return <Profile data={profile} key={index} />;
})
)}
</> : <ErrorPage />}


</div>
);
}
Expand Down
20 changes: 20 additions & 0 deletions src/components/ErrorPage/ErrorPage.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.error-page {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}

.error-page-content {
text-align: center;
color: #fff;
}

.error-page-content h1 {
font-size: 2.5rem;
margin-bottom: 1rem;
}

.error-page-content p {
font-size: 1.5rem;
}
14 changes: 14 additions & 0 deletions src/components/ErrorPage/ErrorPage.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react';
import './ErrorPage.css'

const ErrorPage = () => {
return <div className="error-page">
<div className="error-page-content">
<h1>404 - Page Not Found</h1>
<p>Oops! The page you're looking for does not exist.</p>
<p>Please check the Url.</p>
</div>
</div>;
};

export default ErrorPage;