fix: search

feat/discover
Arik Chakma 5 months ago
parent c2682e84ce
commit 4f6fa1d5c3
  1. 235
      src/components/DiscoverRoadmaps/DiscoverRoadmaps.tsx

@ -111,125 +111,130 @@ export function DiscoverRoadmaps(props: DiscoverRoadmapsProps) {
const loadingIndicator = isLoading && <LoadingRoadmaps />; const loadingIndicator = isLoading && <LoadingRoadmaps />;
return ( return (
<> <>
{isCreatingRoadmap && ( {isCreatingRoadmap && (
<CreateRoadmapModal <CreateRoadmapModal
onClose={() => { onClose={() => {
setIsCreatingRoadmap(false); setIsCreatingRoadmap(false);
}} }}
/> />
)} )}
<div className="border-b bg-white py-7"> <div className="border-b bg-white py-7">
<div className="container text-left"> <div className="container text-left">
<div className="flex flex-col items-start bg-white"> <div className="flex flex-col items-start bg-white">
<h1 className="mb-1 text-2xl font-bold sm:text-3xl"> <h1 className="mb-1 text-2xl font-bold sm:text-3xl">
Community Roadmaps Community Roadmaps
</h1> </h1>
<p className="text-base text-gray-500"> <p className="text-base text-gray-500">
Browse the roadmaps created by the community or{' '} Browse the roadmaps created by the community or{' '}
<button <button
onClick={() => { onClick={() => {
setIsCreatingRoadmap(true); setIsCreatingRoadmap(true);
}} }}
className="rounded text-blue-600 underline" className="rounded text-blue-600 underline"
> >
create your own roadmap create your own roadmap
</button> </button>
</p> </p>
</div> </div>
</div> </div>
</div>
<div className="bg-gray-50 py-3">
<section className="container mx-auto py-3">
<div className="mb-3.5 flex items-stretch justify-between gap-2.5">
<SearchRoadmap
total={roadmapsResponse?.totalCount || 0}
value={pageState.searchTerm}
isLoading={isLoading}
onValueChange={(value) => {
setPageState({
...pageState,
searchTerm: value,
currentPage: 1,
});
}}
/>
<DiscoverRoadmapSorting
sortBy={pageState.sortBy}
onSortChange={(sortBy) => {
setPageState({
...pageState,
sortBy,
});
}}
/>
</div> </div>
<div className="py-3 bg-gray-50">
<section className="container mx-auto py-3"> {loadingIndicator}
<div className="mb-3.5 flex items-stretch justify-between gap-2.5"> {roadmaps.length === 0 && !isLoading && <EmptyDiscoverRoadmaps />}
<SearchRoadmap {roadmaps.length > 0 && !isLoading && (
total={roadmapsResponse?.totalCount || 0} <>
value={pageState.searchTerm} <ul className="mb-4 grid grid-cols-1 items-stretch gap-3 sm:grid-cols-2 lg:grid-cols-3">
isLoading={isLoading} {roadmaps.map((roadmap) => {
onValueChange={(value) => { const roadmapLink = `/r/${roadmap.slug}`;
}} const totalRatings = Object.keys(
/> roadmap.ratings?.breakdown || [],
).reduce(
<DiscoverRoadmapSorting (acc: number, key: string) =>
sortBy={pageState.sortBy} acc + roadmap.ratings.breakdown[key as any],
onSortChange={(sortBy) => { 0,
setPageState({ );
...pageState, return (
sortBy, <li key={roadmap._id} className="h-full min-h-[175px]">
}); <a
}} key={roadmap._id}
/> href={roadmapLink}
</div> className="flex h-full flex-col rounded-lg border bg-white p-3.5 transition-colors hover:border-gray-300 hover:bg-gray-50"
target={'_blank'}
{loadingIndicator} >
{roadmaps.length === 0 && !isLoading && <EmptyDiscoverRoadmaps/>} <div className="grow">
{roadmaps.length > 0 && !isLoading && ( <h2 className="text-balance text-base font-bold leading-tight">
<> {roadmap.title}
<ul className="mb-4 grid grid-cols-1 items-stretch gap-3 sm:grid-cols-2 lg:grid-cols-3"> </h2>
{roadmaps.map((roadmap) => { <p className="mt-2 text-sm text-gray-500">
const roadmapLink = `/r/${roadmap.slug}`; {roadmap.description}
const totalRatings = Object.keys( </p>
roadmap.ratings?.breakdown || [], </div>
).reduce(
(acc: number, key: string) => <div className="flex items-center justify-between gap-2">
acc + roadmap.ratings.breakdown[key as any],
0,
);
return (
<li key={roadmap._id} className="h-full min-h-[175px]">
<a
key={roadmap._id}
href={roadmapLink}
className="flex h-full flex-col rounded-lg border bg-white p-3.5 transition-colors hover:border-gray-300 hover:bg-gray-50"
target={'_blank'}
>
<div className="grow">
<h2 className="text-balance text-base font-bold leading-tight">
{roadmap.title}
</h2>
<p className="mt-2 text-sm text-gray-500">
{roadmap.description}
</p>
</div>
<div className="flex items-center justify-between gap-2">
<span className="flex items-center gap-1 text-xs text-gray-400"> <span className="flex items-center gap-1 text-xs text-gray-400">
<Shapes size={15} className="inline-block"/> <Shapes size={15} className="inline-block" />
{Intl.NumberFormat('en-US', { {Intl.NumberFormat('en-US', {
notation: 'compact', notation: 'compact',
}).format(roadmap.topicCount)}{' '} }).format(roadmap.topicCount)}{' '}
</span> </span>
<Rating <Rating
rating={roadmap?.ratings?.average || 0} rating={roadmap?.ratings?.average || 0}
readOnly={true} readOnly={true}
starSize={16} starSize={16}
total={totalRatings} total={totalRatings}
/>
</div>
</a>
</li>
);
})}
</ul>
<Pagination
currPage={roadmapsResponse?.currPage || 1}
totalPages={roadmapsResponse?.totalPages || 1}
perPage={roadmapsResponse?.perPage || 0}
totalCount={roadmapsResponse?.totalCount || 0}
onPageChange={(page) => {
setPageState({
...pageState,
currentPage: page,
});
}}
/> />
</> </div>
)} </a>
</section> </li>
</div> );
</> })}
</ul>
<Pagination
currPage={roadmapsResponse?.currPage || 1}
totalPages={roadmapsResponse?.totalPages || 1}
perPage={roadmapsResponse?.perPage || 0}
totalCount={roadmapsResponse?.totalCount || 0}
onPageChange={(page) => {
setPageState({
...pageState,
currentPage: page,
});
}}
/>
</>
)}
</section>
</div>
</>
); );
} }

Loading…
Cancel
Save