Skip to content

Commit fa6f789

Browse files
authored
Merge pull request #172 from kashyap-harshit/staging
Staging
2 parents 1d49547 + a225d6e commit fa6f789

File tree

4 files changed

+63
-57
lines changed

4 files changed

+63
-57
lines changed

src/components/CatalogueContent.tsx

Lines changed: 52 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ const CatalogueContent = () => {
4848
const [filtersPulled, setFiltersPulled] = useState<boolean>(false);
4949
const [appliedFilters, setAppliedFilters] = useState<boolean>(false);
5050

51+
52+
const filtersNotPulled = ()=>{
53+
setFiltersPulled(false);
54+
}
5155
// Memoized effect to fetch papers
5256
useEffect(() => {
5357
if (!subject) return;
@@ -93,6 +97,7 @@ const CatalogueContent = () => {
9397
});
9498
setFilteredPapers(filtered.length > 0 ? filtered : papersData);
9599
} catch (error) {
100+
setPapers([]);
96101
if (axios.isAxiosError(error)) {
97102
const axiosError = error as AxiosError<{ message?: string }>;
98103
setError(
@@ -107,7 +112,7 @@ const CatalogueContent = () => {
107112
};
108113

109114
void fetchPapers();
110-
}, []); // just run on initial page render
115+
}, [subject]); // just run on initial page render
111116

112117
// Memoized handlers
113118
const handleSelectPaper = useCallback(
@@ -209,12 +214,13 @@ const CatalogueContent = () => {
209214
link.download = filename;
210215
link.click();
211216
window.URL.revokeObjectURL(link.href);
212-
} catch (error) { }
217+
} catch (error) {}
213218
}
214219

215220
return (
216221
<div className="relative flex min-h-screen justify-center p-0 md:justify-normal">
217222
<SideBar
223+
filtersNotPulled={filtersNotPulled}
218224
loading={loading}
219225
selectedExams={selectedExams}
220226
selectedSlots={selectedSlots}
@@ -235,67 +241,62 @@ const CatalogueContent = () => {
235241
/>
236242

237243
{/* {error && <p className="text-red-500">{error}</p>} */}
238-
{loading ? (
239-
<Loader />
240-
) : papers.length > 0 ? (
244+
<div className="w-full">
241245
<div
242-
className={`grid h-fit grid-cols-1 gap-8 px-[30px] py-[40px] md:grid-cols-4 ${filtersPulled ? "blur-xl" : ""}`}
246+
className={`justify-center mt-8 filter md:hidden ${filtersPulled ? "hidden" : "flex"}`}
243247
>
248+
<Button
249+
variant="outline"
250+
onClick={() => setFiltersPulled(true)}
251+
className="mr-2 border-2 border-black font-sans font-semibold hover:bg-slate-800 hover:text-white dark:border-[#434dba] dark:hover:border-white dark:hover:bg-slate-900"
252+
>
253+
Add Filters
254+
<Image
255+
src={filterIcon as string}
256+
width={30}
257+
height={30}
258+
alt="Filter Icon"
259+
className="invert dark:invert-0"
260+
/>
261+
262+
</Button>
263+
</div>
264+
{loading ? (
265+
<Loader />
266+
) : papers.length > 0 ? (
244267
<div
245-
className={`justify-center filter md:hidden ${filtersPulled ? "hidden" : "flex"}`}
268+
className={`grid h-fit grid-cols-1 gap-8 px-[30px] py-[40px] md:grid-cols-4 ${filtersPulled ? "blur-xl" : ""}`}
246269
>
247-
<Button
248-
variant="outline"
249-
onClick={() => setFiltersPulled(true)}
250-
className="mr-2 border-2 border-black font-sans font-semibold hover:bg-slate-800 hover:text-white dark:border-[#434dba] dark:hover:border-white dark:hover:bg-slate-900"
251-
>
252-
Add Filters
253-
<Image
254-
src={filterIcon as string}
255-
width={30}
256-
height={30}
257-
alt="Filter Icon"
258-
className="hidden dark:block"
259-
/>
260-
<Image
261-
src={filterd as string}
262-
height={30}
263-
width={30}
264-
alt="filter light"
265-
className="block dark:hidden"
266-
/>
267-
</Button>
268-
</div>
270+
269271

270-
{appliedFilters ? (
271-
filteredPapers.length > 0 ? (
272-
filteredPapers.map((paper: IPaper) => (
272+
{appliedFilters ? (
273+
filteredPapers.length > 0 ? (
274+
filteredPapers.map((paper: IPaper) => (
275+
<Card
276+
key={paper._id}
277+
paper={paper}
278+
onSelect={handleSelectPaper}
279+
isSelected={selectedPapers.some((p) => p._id === paper._id)}
280+
/>
281+
))
282+
) : (
283+
<p>No papers available with the applied filter</p>
284+
)
285+
) : (
286+
papers.map((paper: IPaper) => (
273287
<Card
274288
key={paper._id}
275289
paper={paper}
276290
onSelect={handleSelectPaper}
277291
isSelected={selectedPapers.some((p) => p._id === paper._id)}
278292
/>
279293
))
280-
) : (
281-
<p>No papers available with the applied filter</p>
282-
)
283-
) : (
284-
papers.map((paper: IPaper) => (
285-
<Card
286-
key={paper._id}
287-
paper={paper}
288-
onSelect={handleSelectPaper}
289-
isSelected={selectedPapers.some((p) => p._id === paper._id)}
290-
/>
291-
))
292-
)}
293-
</div>
294-
) : (
295-
<Error
296-
message={error ?? "No papers available for this subject."}
297-
/>
298-
)}
294+
)}
295+
</div>
296+
) : (
297+
<Error filtersPulled={filtersPulled} message={error ?? "No papers available for this subject."} />
298+
)}
299+
</div>
299300
</div>
300301
);
301302
};

src/components/Error.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ import React from "react";
22

33
interface ErrorProps {
44
message?: string;
5+
filtersPulled : boolean;
56
}
67

7-
const Error = ({ message = "Some error occured" }: ErrorProps) => {
8+
const Error = ({ message = "Some error occured", filtersPulled }: ErrorProps) => {
89
return (
9-
<div className="flex flex-1 items-center justify-center">
10+
<div className={`flex flex-1 items-center justify-center h-full ${filtersPulled ? "blur-xl" : ""}`}>
1011
<div className="-mt-32 text-center text-lg">
1112
{message}
1213
</div>

src/components/Searchbar/searchbar-child.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Search } from "lucide-react";
55
import { useRouter } from "next/navigation";
66
import { Input } from "@/components/ui/input";
77

8-
function SearchBarChild({ initialSubjects }: { initialSubjects: string[] }) {
8+
function SearchBarChild({ initialSubjects, filtersNotPulled }: { initialSubjects: string[]; filtersNotPulled: ()=>void; }) {
99
const router = useRouter();
1010
const [searchText, setSearchText] = useState("");
1111
const [suggestions, setSuggestions] = useState<string[]>([]);
@@ -25,8 +25,10 @@ function SearchBarChild({ initialSubjects }: { initialSubjects: string[] }) {
2525
};
2626

2727
const handleSelectSuggestion = (suggestion: string) => {
28+
suggestion = suggestion.replace(/\[.*?\]/g, '').trim();
2829
router.push(`/catalogue?subject=${encodeURIComponent(suggestion)}`);
2930
setSearchText(suggestion);
31+
filtersNotPulled();
3032
setSuggestions([]);
3133
};
3234

@@ -35,7 +37,7 @@ function SearchBarChild({ initialSubjects }: { initialSubjects: string[] }) {
3537
suggestionsRef.current &&
3638
!suggestionsRef.current.contains(event.target as Node)
3739
) {
38-
setSuggestions([]);
40+
// setSuggestions([]);
3941
}
4042
};
4143

@@ -74,7 +76,7 @@ function SearchBarChild({ initialSubjects }: { initialSubjects: string[] }) {
7476
(searchText.length > 1 && initialSubjects.length > 0)) && (
7577
<ul
7678
ref={suggestionsRef}
77-
className="absolute z-20 h-[250px] w-full max-w-xl overflow-y-scroll rounded-md rounded-t-none border border-t-0 bg-white text-center shadow-lg dark:bg-[#303771] md:mx-0 md:h-auto md:overflow-auto"
79+
className={`absolute z-20 h-[250px] w-full max-w-xl overflow-y-scroll rounded-md rounded-t-none border border-t-0 bg-white text-center shadow-lg dark:bg-[#303771] md:mx-0 ${suggestions.length>6?"h-[250px]" : "h-auto"} ${suggestions.length>10?"md:h-[400px]" : "md:h-auto"} `}
7880
>
7981
{suggestions.length > 0 ? (
8082
suggestions.map((suggestion, index) => (

src/components/SideBar.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import toast from "react-hot-toast";
2020
import SearchbarChild from "./Searchbar/searchbar-child";
2121

2222
function SideBar({
23+
filtersNotPulled,
2324
loading,
2425
selectedExams,
2526
selectedSlots,
@@ -38,6 +39,7 @@ function SideBar({
3839
handleApplyFilters,
3940
closeFilters,
4041
}: {
42+
filtersNotPulled: ()=>void;
4143
loading: boolean;
4244
selectedExams: string[];
4345
selectedSlots: string[];
@@ -112,7 +114,7 @@ function SideBar({
112114
/>
113115
</div>
114116
<div className="px-[10px] md:w-[100%]">{/* <SearchBar /> */}
115-
<SearchbarChild initialSubjects={subjects ?? []}></SearchbarChild>
117+
<SearchbarChild filtersNotPulled={filtersNotPulled} initialSubjects={subjects ?? []}></SearchbarChild>
116118

117119
</div>
118120
<div className="flex w-full gap-8 border-b-2 border-[#36266d] px-[10px] pb-4 pt-8">

0 commit comments

Comments
 (0)