Skip to content

Commit

Permalink
Merge pull request #244 from UTDNebula/JUP-61-club-search-page
Browse files Browse the repository at this point in the history
feature: club search page
  • Loading branch information
nl32 authored Oct 22, 2024
2 parents 91d7678 + 21c5895 commit fe58b65
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 3 deletions.
35 changes: 35 additions & 0 deletions src/app/directory/search/ClubSearch.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
'use client';
import { api } from '@src/trpc/react';
import type { SelectClub as Club } from '@src/server/db/models';
import { type Session } from 'next-auth';
import ClubCard from '@src/components/club/ClubCard';

interface ClubSearchComponentProps {
userSearch: string;
session: Session | null;
}

export const ClubSearchComponent = ({
userSearch,
session,
}: ClubSearchComponentProps) => {
const { data } = api.club.byNameNoLimit.useQuery(
{ name: userSearch },
{ enabled: !!userSearch },
);

if (!data) {
return <p />;
}
if (data.length === 0) {
return <p>No results found</p>;
}

return (
<div className="grid w-full auto-rows-fr grid-cols-[repeat(auto-fill,320px)] justify-center gap-16 pb-4">
{data.map((club: Club) => (
<ClubCard key={club.id} club={club} session={session} priority />
))}
</div>
);
};
24 changes: 24 additions & 0 deletions src/app/directory/search/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import Header from '@src/components/header/BaseHeader';
import { ClubSearchComponent } from './ClubSearch';
import { getServerAuthSession } from '@src/server/auth';

type Params = {
searchParams: { [key: string]: string | undefined };
};

const clubSearch = async (props: Params) => {
const { searchParams } = props;
const userSearch = searchParams['search'] || '';
const session = await getServerAuthSession();

return (
<main className="md:pl-72">
<div>
<Header />
<ClubSearchComponent userSearch={userSearch} session={session} />
</div>
</main>
);
};

export default clubSearch;
4 changes: 1 addition & 3 deletions src/components/searchBar/ClubSearchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ export const ClubSearchBar = () => {
onClick={onClickSearchResult}
submitButton
submitLogic={() => {
if (data && data[0]) {
onClickSearchResult(data[0]);
}
router.push(`/directory/search?search=${encodeURIComponent(search)}`);
}}
/>
);
Expand Down
11 changes: 11 additions & 0 deletions src/server/api/routers/club.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,17 @@ export const clubRouter = createTRPCRouter({

return clubs.slice(0, 5);
}),
byNameNoLimit: publicProcedure
.input(byNameSchema)
.query(async ({ input, ctx }) => {
const { name } = input;
const clubs = await ctx.db.query.club.findMany({
where: (club) =>
and(ilike(club.name, `%${name}%`), eq(club.approved, 'approved')),
});

return clubs;
}),
byId: publicProcedure.input(byIdSchema).query(async ({ input, ctx }) => {
const { id } = input;
try {
Expand Down

0 comments on commit fe58b65

Please sign in to comment.