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

Explore | Combine all the empty data fields #698

Merged
merged 3 commits into from
Mar 6, 2024
Merged
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
138 changes: 99 additions & 39 deletions src/components/Explore/Explore.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import Sidebar from "../Feeds/SocialSidebar/Sidebar";
import { FilterButton } from "../Feeds/FeedsElements";
import { HintIcon } from "../WebSecurity/Common/HintElements";
import { FaAngleDown, FaAngleUp } from "react-icons/fa";
import NotFound from "../../NotFound";

const FilterContainer = styled.div``;

Expand Down Expand Up @@ -210,6 +211,29 @@ const Explore = () => {
{ value: followers, label: "Followers" },
];

const renderNotFoundComponents = () => {
const dataTypes = ["Users", "Feeds", "Blogs", "Ctfs"];
const filteredData = {
Users: filteredUsers,
Feeds: filteredFeeds,
Blogs: filteredBlogs,
Ctfs: filteredCtf,
};
const missingDataTypes = dataTypes.filter((type) => !filteredData[type].length);

if (missingDataTypes.length === dataTypes.length) {
return <NotFound title="Not Found" description="There are no items" />;
} else if (missingDataTypes.length) {
const lastType = missingDataTypes.pop();
const missingDataTypesString = missingDataTypes.length
? `${missingDataTypes.join(", ")} and ${lastType}`
: lastType;
return <NotFound title="" description={`${missingDataTypesString} Not Found`} />;
}

return null;
};

if (isApiLoading || isCtfLoading) return <LoadingSpinner />;

if (!isApiWorking) return <UnderMaintenance />;
Expand All @@ -235,45 +259,81 @@ const Explore = () => {
</LeftContainer>

<RightContainer>
{selectedType === "all" || selectedType === "users" ? (
<Users
userDetails={filteredUsers}
isUserDetailLoading={isUserDetailLoading}
searchTerm={searchTerm}
displayAt={"explore"}
/>
) : null}

{selectedType === "all" || selectedType === "feeds" ? (
<FeedsExplore
feeds={filteredFeeds}
isFeedLoading={isFeedLoading}
searchTerm={searchTerm}
displayAt={"explore"}
/>
) : null}

{selectedType === "all" || selectedType === "blogs" ? (
<BlogCards
blogs={filteredBlogs}
isBlogLoading={isBlogLoading}
searchTerm={searchTerm}
displayAt={"explore"}
/>
) : null}

{/* {selectedType === "all" || selectedType === "forum" ? ( */}
{/* <ForumPosts forums={forums} searchTerm={searchTerm} displayAt={"explore"}/> */}
{/* ) : null} */}

{selectedType === "all" || selectedType === "ctf" ? (
<CtfChallenges
ctf={filteredCtf}
isCtfLoading={isCtfLoading}
searchTerm={searchTerm}
displayAt={"explore"}
/>
) : null}
{selectedType === "all" ? (
<>
{filteredUsers.length ? (
<Users
userDetails={filteredUsers}
isUserDetailLoading={isUserDetailLoading}
searchTerm={searchTerm}
displayAt={"explore"}
/>
) : null}
{filteredFeeds.length ? (
<FeedsExplore
feeds={filteredFeeds}
isFeedLoading={isFeedLoading}
searchTerm={searchTerm}
displayAt={"explore"}
/>
) : null}
{filteredBlogs.length ? (
<BlogCards
blogs={filteredBlogs}
isBlogLoading={isBlogLoading}
searchTerm={searchTerm}
displayAt={"explore"}
/>
) : null}
{filteredCtf.length ? (
<CtfChallenges
ctf={filteredCtf}
isCtfLoading={isCtfLoading}
searchTerm={searchTerm}
displayAt={"explore"}
/>
) : null}
{renderNotFoundComponents()}
</>
) : (
<>
{selectedType === "users" ? (
<Users
userDetails={filteredUsers}
isUserDetailLoading={isUserDetailLoading}
searchTerm={searchTerm}
displayAt={"explore"}
/>
) : null}

{selectedType === "feeds" ? (
<FeedsExplore
feeds={filteredFeeds}
isFeedLoading={isFeedLoading}
searchTerm={searchTerm}
displayAt={"explore"}
/>
) : null}

{selectedType === "blogs" ? (
<BlogCards
blogs={filteredBlogs}
isBlogLoading={isBlogLoading}
searchTerm={searchTerm}
displayAt={"explore"}
/>
) : null}

{selectedType === "ctf" ? (
<CtfChallenges
ctf={filteredCtf}
isCtfLoading={isCtfLoading}
searchTerm={searchTerm}
displayAt={"explore"}
/>
) : null}
</>
)}
</RightContainer>
</ExploreContainer>
</Wrapper>
Expand Down