Skip to content

Commit 51b59fa

Browse files
Merge remote-tracking branch 'refs/remotes/origin/staging' into staging
2 parents fc182e0 + 43de743 commit 51b59fa

File tree

4 files changed

+35
-3
lines changed

4 files changed

+35
-3
lines changed

src/components/PinButton.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,19 @@ import { Pin, PinOff } from "lucide-react";
55
export default function PinButton({
66
isPinned,
77
onToggle,
8+
disabled,
89
}: {
910
isPinned: boolean;
1011
onToggle?: () => void;
12+
disabled?: boolean;
1113
}) {
1214
return (
1315
<button
1416
onClick={onToggle}
1517
className={`ml-2 flex items-center gap-2 rounded-full px-4 py-2 text-sm font-medium ${
1618
isPinned ? "bg-purple-700 text-white" : "bg-[#2B2B30] text-white/80"
1719
} transition hover:bg-purple-600`}
20+
disabled={disabled}
1821
>
1922
{isPinned ? <Pin className="h-4 w-4" /> : <PinOff className="h-4 w-4" />}
2023
<span className="hidden sm:inline">{isPinned ? "Pinned" : "Pin"}</span>

src/components/PinnedPapersCarousel.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,12 @@ function PinnedPapersCarousel({
172172
))}
173173

174174
{isLastChunk && displayPapers.length < 8 && (
175-
<div className="h-full">
175+
<div
176+
className="h-full"
177+
onClick={() => {
178+
window.dispatchEvent(new Event("addButtonClicked"));
179+
}}
180+
>
176181
<AddPapers />
177182
</div>
178183
)}

src/components/Searchbar/pinned-searchbar.tsx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ function PinnedSearchBar({
2525
const [pinned, setPinned] = useState<boolean>(false);
2626
const [open, setOpen] = useState(false);
2727
const [showControls, setShowControls] = useState(false);
28+
const searchRef = useRef<HTMLInputElement>(null);
2829

2930
const fuzzy = new Fuse(initialSubjects);
3031

@@ -74,6 +75,18 @@ function PinnedSearchBar({
7475
}
7576
};
7677

78+
useEffect(() => {
79+
const handleAddClicked = () => {
80+
searchRef.current?.focus();
81+
};
82+
83+
window.addEventListener("addButtonClicked", handleAddClicked);
84+
85+
return () => {
86+
window.removeEventListener("addButtonClicked", handleAddClicked);
87+
};
88+
}, []);
89+
7790
const handlePinToggle = () => {
7891
const current = !pinned;
7992
setPinned(current);
@@ -154,6 +167,7 @@ function PinnedSearchBar({
154167
<Input
155168
type="text"
156169
value={searchText}
170+
ref={searchRef}
157171
onChange={handleSearchChange}
158172
placeholder="Search subject to pin..."
159173
className={`text-md w-full rounded-lg bg-[#B2B8FF] px-4 py-6 pr-10 font-play tracking-wider text-black shadow-sm ring-0 placeholder:text-black focus:outline-none focus:ring-0 dark:bg-[#7480FF66] dark:text-white placeholder:dark:text-white ${
@@ -189,7 +203,11 @@ function PinnedSearchBar({
189203
</div>
190204

191205
<div className="hidden md:block">
192-
<PinButton isPinned={pinned} onToggle={handlePinToggle} />
206+
<PinButton
207+
isPinned={pinned}
208+
onToggle={handlePinToggle}
209+
disabled={!showControls && searchText.trim() === ""}
210+
/>
193211
</div>
194212

195213
<div
@@ -210,6 +228,7 @@ function PinnedSearchBar({
210228
handlePinToggle();
211229
setOpen(false);
212230
}}
231+
disabled={!showControls && searchText.trim() === ""}
213232
/>
214233
<button
215234
onClick={() => {

src/components/Searchbar/searchbar.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"use server";
22

3+
import React from "react";
34
import axios from "axios";
45
import { type ICourses } from "@/interface";
56
import SearchBarChild from "./searchbar-child";
@@ -18,7 +19,11 @@ export async function fetchSubjects() {
1819
}
1920
}
2021

21-
export default async function SearchBar({ type = "default" }) {
22+
export default async function SearchBar({
23+
type = "default",
24+
}: {
25+
type?: "default" | "pinned";
26+
}) {
2227
const subjects = await fetchSubjects();
2328

2429
return type === "pinned" ? (

0 commit comments

Comments
 (0)