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

#95 empty state search #96

Merged
merged 21 commits into from
Nov 30, 2024
Merged
Show file tree
Hide file tree
Changes from 20 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
19 changes: 12 additions & 7 deletions apps/web/src/app/(pages)/(dashboard)/companies/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { unstable_noStore as noStore } from "next/cache";

import NoResults from "~/app/_components/no-results";
import { RoleReviewCard } from "~/app/_components/reviews/role-review-card";
import SearchFilter from "~/app/_components/search/search-filter";
import { api } from "~/trpc/server";
Expand All @@ -20,13 +21,17 @@ export default async function Companies() {
return (
<>
<SearchFilter />
<div className="mb-8 grid h-[70dvh] w-3/4 grid-cols-1 gap-4 overflow-y-scroll md:grid-cols-2 xl:grid-cols-3">
{roles.map((role) => {
return (
<RoleReviewCard key={role.id} roleObj={role} className="mb-4" />
);
})}
</div>
{roles.length > 0 ? (
<div className="mb-8 grid h-[70dvh] w-3/4 grid-cols-1 gap-4 overflow-y-scroll md:grid-cols-2 xl:grid-cols-3">
{roles.map((role) => {
return (
<RoleReviewCard key={role.id} roleObj={role} className="mb-4" />
);
})}
</div>
) : (
<NoResults />
)}
</>
);
}
6 changes: 5 additions & 1 deletion apps/web/src/app/(pages)/(dashboard)/roles/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { WorkEnvironment, WorkTerm } from "@cooper/db/schema";
import { cn } from "@cooper/ui";
import { useToast } from "@cooper/ui/hooks/use-toast";

import LoadingResults from "~/app/_components/loading-results";
import NoResults from "~/app/_components/no-results";
import { ReviewCard } from "~/app/_components/reviews/review-card";
import { ReviewCardPreview } from "~/app/_components/reviews/review-card-preview";
import SearchFilter from "~/app/_components/search/search-filter";
Expand Down Expand Up @@ -79,7 +81,7 @@ export default function Roles({
return (
<>
<SearchFilter search={searchParams?.search} {...validationResult.data} />
{reviews.isSuccess && (
{reviews.isSuccess && reviews.data.length > 0 && (
<div className="mb-8 grid h-[70dvh] w-4/5 grid-cols-5 gap-4 lg:w-3/4">
<div className="col-span-2 gap-3 overflow-scroll pr-4">
{reviews.data.map((review, i) => {
Expand All @@ -106,6 +108,8 @@ export default function Roles({
</div>
</div>
)}
{reviews.isSuccess && reviews.data.length === 0 && <NoResults />}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally a nit but thoughts on doing this above the "main" return statement?

if (review.isPending) return <LoadingResult />

if (reviews.isSuccess && !reviews.data.length) return <NoResult />

So then you can remove all of the checks from Line 85.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

beautiful

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok so i lied, if we do this then the search bar isn't rendered and adding it to the above return statements duplicates like an extra 15 lines of code so I think it might be better to leave where they are?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're right i didn't realize that this was a page and that we have the SearchFilter component on it

{reviews.isPending && <LoadingResults />}
</>
);
}
16 changes: 16 additions & 0 deletions apps/web/src/app/_components/cooper-logo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import Image from "next/image";

interface CooperLogoProps {
width?: number;
}

export default function CooperLogo({ width }: CooperLogoProps) {
return (
<Image
src="/svg/hidingLogo.svg"
width={width ?? 137}
height={width ? width / 2.28 : 60} // 2.28 is the approximate ratio in the hidingLogo.svg file
alt="Logo Picture"
/>
);
}
9 changes: 2 additions & 7 deletions apps/web/src/app/_components/header.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"use client";

import Image from "next/image";
import Link from "next/link";
import { usePathname } from "next/navigation";

Expand All @@ -9,6 +8,7 @@ import { cn } from "@cooper/ui";

import { NewReviewDialog } from "~/app/_components/reviews/new-review-dialogue";
import { altivoFont } from "~/app/styles/font";
import CooperLogo from "./cooper-logo";

interface HeaderProps {
session: Session | null;
Expand All @@ -29,12 +29,7 @@ export default function Header({ session, auth }: HeaderProps) {
{/* Logo + Cooper */}
<Link href="/" className={cn("flex flex-grow items-end", outerWidth)}>
<div className="mx-4 flex h-20 items-end">
<Image
src="/svg/hidingLogo.svg"
alt="Logo Picture"
width={137}
height={60}
/>
<CooperLogo />
</div>
<h1
className={cn(
Expand Down
12 changes: 12 additions & 0 deletions apps/web/src/app/_components/loading-results.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import CooperLogo from "./cooper-logo";

export default function LoadingResults() {
return (
<section className="flex h-[50dvh] w-full flex-col items-center justify-center">
<CooperLogo width={200} />
<div className="rounded-lg border-2 border-cooper-blue-600 px-16 pb-4 pt-6 text-xl font-bold text-cooper-blue-700">
<h2 className="">Loading ...</h2>
</div>
</section>
);
}
33 changes: 33 additions & 0 deletions apps/web/src/app/_components/no-results.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"use client";

import { usePathname, useRouter } from "next/navigation";

import { Button } from "@cooper/ui/button";

import CooperLogo from "./cooper-logo";

export default function NoResults() {
const router = useRouter();
const pathname = usePathname();

function clearFilters() {
router.push(pathname);
}

return (
<section className="flex h-[50dvh] w-full flex-col items-center justify-center">
<CooperLogo width={200} />
<div className="rounded-lg border-2 border-cooper-blue-600 px-16 pb-4 pt-6 text-xl font-bold">
<h2 className="text-cooper-blue-700">No Results Found</h2>
<Button
type="button"
variant="ghost"
onClick={clearFilters}
className="text-cooper-blue-600"
>
Clear Filters
</Button>
Comment on lines +22 to +29
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This button might not be centered. See this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

def not xD

</div>
</section>
);
}