Skip to content

Commit fc9e98b

Browse files
Merge pull request #424 from Advik-Gupta/staging
Fixed sidebar to side
2 parents ebb6683 + 789baa9 commit fc9e98b

File tree

2 files changed

+48
-25
lines changed

2 files changed

+48
-25
lines changed

src/components/Searchbar/searchbar-child.tsx

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,26 @@ function SearchBarChild({
1919
const [suggestions, setSuggestions] = useState<ICourseWithCount[]>([]);
2020
const suggestionsRef = useRef<HTMLUListElement | null>(null);
2121
const [fuzzy, setFuzzy] = useState(
22-
() => new Fuse<ICourseWithCount>([], { keys: ["name"], threshold: 0.3 }),
22+
() =>
23+
new Fuse<ICourseWithCount>([], {
24+
keys: ["name"],
25+
threshold: 0.3,
26+
ignoreLocation: true,
27+
}),
2328
);
2429
const [highlightedIndex, setHighlightedIndex] = useState<number>(-1);
2530

2631
useEffect(() => {
2732
if (initialSubjects && initialSubjects.length > 0) {
28-
setFuzzy(new Fuse(initialSubjects, { keys: ["name"], threshold: 0.3 }));
33+
setFuzzy(
34+
new Fuse(initialSubjects, {
35+
keys: ["name"],
36+
threshold: 0.3,
37+
ignoreLocation: true,
38+
}),
39+
);
2940
}
41+
console.log(initialSubjects);
3042
}, [initialSubjects]);
3143

3244
const handleSearchChange = (e: React.ChangeEvent<HTMLInputElement>) => {
@@ -95,24 +107,37 @@ function SearchBarChild({
95107
setHighlightedIndex((prev) => (prev + 1) % suggestions.length);
96108
} else if (e.key === "ArrowUp") {
97109
e.preventDefault();
98-
setHighlightedIndex((prev) => (prev - 1 + suggestions.length) % suggestions.length);
110+
setHighlightedIndex(
111+
(prev) =>
112+
(prev - 1 + suggestions.length) % suggestions.length,
113+
);
99114
} else if (e.key === "Enter") {
100115
e.preventDefault();
101-
if (highlightedIndex >= 0 && highlightedIndex < suggestions.length && suggestions[highlightedIndex] !== undefined) {
116+
if (
117+
highlightedIndex >= 0 &&
118+
highlightedIndex < suggestions.length &&
119+
suggestions[highlightedIndex] !== undefined
120+
) {
102121
handleSelectSuggestion(suggestions[highlightedIndex]);
103122
} else {
104-
router.push(`/catalogue?subject=${encodeURIComponent(searchText)}`);
123+
router.push(
124+
`/catalogue?subject=${encodeURIComponent(searchText)}`,
125+
);
105126
setSuggestions([]);
106127
}
107128
} else if (e.key === "Tab") {
108129
e.preventDefault();
109-
if(highlightedIndex == -1){
130+
if (highlightedIndex == -1) {
110131
if (suggestions.length > 0 && suggestions[0] != undefined) {
111132
setSearchText(suggestions[0].name || "");
112133
setSuggestions([]);
113134
}
114-
}else{
115-
if (highlightedIndex >= 0 && highlightedIndex < suggestions.length && suggestions[highlightedIndex] !== undefined) {
135+
} else {
136+
if (
137+
highlightedIndex >= 0 &&
138+
highlightedIndex < suggestions.length &&
139+
suggestions[highlightedIndex] !== undefined
140+
) {
116141
setSearchText(suggestions[highlightedIndex].name || "");
117142
setHighlightedIndex(-1);
118143
setSuggestions([]);
@@ -134,15 +159,16 @@ function SearchBarChild({
134159
className={`absolute z-20 w-full max-w-xl overflow-y-auto rounded-md rounded-t-none border border-t-0 bg-white text-center shadow-lg dark:bg-[#303771] md:mx-0`}
135160
style={{ maxHeight: "400px" }}
136161
>
137-
{suggestions.map((suggestion : ICourseWithCount, index) => (
162+
{suggestions.map((suggestion: ICourseWithCount, index) => (
138163
<li
139164
key={suggestion._id}
140165
onClick={() => handleSelectSuggestion(suggestion)}
141-
className={`flex cursor-pointer items-center rounded p-2
142-
${index === highlightedIndex
143-
? "bg-gray-200 dark:bg-gray-800"
144-
: "hover:bg-gray-200 dark:hover:bg-gray-800"}`}
145-
>
166+
className={`flex cursor-pointer items-center rounded p-2 ${
167+
index === highlightedIndex
168+
? "bg-gray-200 dark:bg-gray-800"
169+
: "hover:bg-gray-200 dark:hover:bg-gray-800"
170+
}`}
171+
>
146172
<div
147173
id="paper_count"
148174
className="mr-4 flex h-8 w-8 items-center justify-center rounded-md bg-[#171720] text-xs font-semibold text-white"

src/components/pdfViewer.tsx

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,11 @@ export default function PdfViewer({ url, name }: PdfViewerProps) {
107107
};
108108

109109
const zoomIn = () => {
110-
setScale((prev) => Math.min(prev + 0.25, 3));
110+
setScale((prev) => Math.min(prev + 0.1, 3));
111111
};
112112

113113
const zoomOut = () => {
114-
setScale((prev) => Math.max(prev - 0.25, 0.25));
114+
setScale((prev) => Math.max(prev - 0.1, 0.25));
115115
};
116116

117117
const downloadPDF = async () => {
@@ -195,7 +195,7 @@ export default function PdfViewer({ url, name }: PdfViewerProps) {
195195
}, []);
196196

197197
return (
198-
<div className="w-full flex-row justify-center gap-6 p-3 md:flex md:p-0">
198+
<div className="relative w-full gap-6 p-3 md:flex md:justify-center md:p-0">
199199
{!isFullscreen && (
200200
<div className="mx-auto mb-6 mt-2 flex w-full max-w-[480px] flex-col items-center gap-3 rounded-xl bg-[#F3F5FF] p-3 shadow dark:bg-[#262635] sm:flex-row md:hidden">
201201
<div className="flex items-center gap-2">
@@ -209,7 +209,6 @@ export default function PdfViewer({ url, name }: PdfViewerProps) {
209209
/>
210210

211211
<span className="text-sm font-medium">of {numPages ?? 1}</span>
212-
213212
</div>
214213

215214
<div className="flex items-center gap-2">
@@ -245,14 +244,14 @@ export default function PdfViewer({ url, name }: PdfViewerProps) {
245244
>
246245
{isFullscreen ? <Minimize2 /> : <Maximize2 />}
247246
</Button>
248-
<ReportButton/>
247+
<ReportButton />
249248
</div>
250249
</div>
251250
)}
252251

253252
<div
254253
ref={containerRef}
255-
className="max-h-[70vh] overflow-auto rounded-lg bg-[#F3F5FF] px-4 shadow-lg dark:bg-[#070114]"
254+
className="relative max-h-[70vh] overflow-auto rounded-lg bg-[#F3F5FF] px-4 shadow-lg dark:bg-[#070114]"
256255
>
257256
<Document
258257
file={url}
@@ -341,7 +340,7 @@ export default function PdfViewer({ url, name }: PdfViewerProps) {
341340
</div>
342341

343342
{!isFullscreen && (
344-
<div className="hidden h-fit flex-col items-center gap-4 rounded-lg bg-[#F3F5FF] p-4 shadow dark:bg-[#262635] md:flex">
343+
<div className="absolute right-4 top-1/2 z-20 hidden h-fit -translate-y-1/2 flex-col items-center gap-4 rounded-lg bg-[#F3F5FF] p-4 shadow dark:bg-[#262635] md:flex">
345344
<div className="flex flex-col items-center gap-3">
346345
<Button
347346
onClick={toggleFullscreen}
@@ -359,7 +358,6 @@ export default function PdfViewer({ url, name }: PdfViewerProps) {
359358

360359
<ShareButton />
361360
</div>
362-
363361
<div className="flex flex-col items-center gap-3">
364362
<Button
365363
onClick={zoomOut}
@@ -379,7 +377,6 @@ export default function PdfViewer({ url, name }: PdfViewerProps) {
379377
<ZoomIn />
380378
</Button>
381379
</div>
382-
383380
<div className="mt-2 flex flex-col items-center gap-3">
384381
<div className="flex flex-col items-center">
385382
<input
@@ -393,8 +390,8 @@ export default function PdfViewer({ url, name }: PdfViewerProps) {
393390
<span className="mt-1 text-sm">of {numPages ?? 1}</span>
394391
</div>
395392
</div>
396-
<ReportButton/>
397-
</div>
393+
<ReportButton />
394+
</div>
398395
)}
399396
</div>
400397
);

0 commit comments

Comments
 (0)