diff --git a/app/dashboard/components/elimination-tree/candidate-list-bar.tsx b/app/dashboard/components/elimination-tree/candidate-list-bar.tsx index bf5990f..967cea3 100644 --- a/app/dashboard/components/elimination-tree/candidate-list-bar.tsx +++ b/app/dashboard/components/elimination-tree/candidate-list-bar.tsx @@ -6,6 +6,7 @@ import { import { Candidate } from "./constants"; import SearchDropdown from "./search-dropdown"; import { TooltipTrigger } from "@radix-ui/react-tooltip"; +import { useState } from "react"; type CandidateListBarProps = { selectedWinnerId: number; @@ -20,6 +21,14 @@ function CandidateListBar({ useAvatar, candidateList, }: CandidateListBarProps) { + const [selectedCandidateId, setSelectedCandidateId] = useState( + null, + ); + + const handleCandidateSelect = (candidateId: number) => { + setSelectedCandidateId(candidateId); + handleSelectWinner(candidateId); // Call to display the tree or other action + }; return (
@@ -27,9 +36,20 @@ function CandidateListBar({
+ {/* handleSelectWinner(candidate.id)}*/} + {/* className="leading-9 w-10 h-10 rounded-full cursor-pointer text-center border-2 border-black text-xs overflow-hidden whitespace-nowrap text-ellipsis"*/} + {/*>*/} + {/* {candidate.name}*/} + {/**/} + handleSelectWinner(candidate.id)} - className="leading-9 w-10 h-10 rounded-full cursor-pointer text-center border-2 border-black text-xs overflow-hidden whitespace-nowrap text-ellipsis" + onClick={() => handleCandidateSelect(candidate.id)} + className={`leading-9 w-10 h-10 rounded-full cursor-pointer text-center border-2 text-xs overflow-hidden whitespace-nowrap text-ellipsis ${ + selectedCandidateId === candidate.id + ? "border-blue-500" // Outer blue circle when selected + : "border-black" + }`} > {candidate.name} @@ -39,7 +59,11 @@ function CandidateListBar({
))}
- + {/**/} +
); } diff --git a/app/dashboard/components/elimination-tree/search-dropdown.tsx b/app/dashboard/components/elimination-tree/search-dropdown.tsx index 1ab661f..2dc5348 100644 --- a/app/dashboard/components/elimination-tree/search-dropdown.tsx +++ b/app/dashboard/components/elimination-tree/search-dropdown.tsx @@ -6,27 +6,49 @@ import { Candidate } from "./constants"; import { Card, CardContent } from "@/components/ui/card"; import Image from "next/image"; -function SearchDropdown({ candidateList }: { candidateList: Candidate[] }) { +// function SearchDropdown({ candidateList }: { candidateList: Candidate[] }) { +// const [searchTerm, setSearchTerm] = useState(""); +// const [selectedCandidate, setSelectedCandidate] = useState( +// null, +// ); +// const [isOpen, setIsOpen] = useState(false); +// //不能用shadcn的popover,因为他的popover弹出瞬间会让input失去焦点 +// +// const filteredList = candidateList.filter((candidate) => +// candidate.name.toLowerCase().includes(searchTerm.toLowerCase()), +// ); +// const handleSelect = (candidate: Candidate) => { +// setSelectedCandidate(candidate); +// setSearchTerm(candidate.name); +// console.log("Selected Candidate:", candidate.name); +// setIsOpen(false); +// }; + +function SearchDropdown({ + candidateList, + onSelect, +}: { + candidateList: Candidate[]; + onSelect: (candidateId: number) => void; +}) { const [searchTerm, setSearchTerm] = useState(""); - const [selectedCandidate, setSelectedCandidate] = useState( - null, - ); const [isOpen, setIsOpen] = useState(false); - //不能用shadcn的popover,因为他的popover弹出瞬间会让input失去焦点 const filteredList = candidateList.filter((candidate) => candidate.name.toLowerCase().includes(searchTerm.toLowerCase()), ); + const handleSelect = (candidate: Candidate) => { - setSelectedCandidate(candidate); setSearchTerm(candidate.name); - console.log("Selected Candidate:", candidate.name); + onSelect(candidate.id); setIsOpen(false); }; return (
setSearchTerm(e.target.value)} onFocus={() => setIsOpen(true)} onBlur={() => setIsOpen(false)}