Advertisement
justfrenzy

CrackFlix - frontend /src/components/App/SearchSuggestions.tsx

May 12th, 2024
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { Button, Image } from "@nextui-org/react";
  2. import { useNavigate } from "react-router-dom";
  3. import { mediaType } from "./props.interface";
  4. import { AppContext, AppContextTypes } from "../../utils/AppContext";
  5. import { useContext } from "react";
  6. import circleCheck from "../../assets/circle-check.svg";
  7. import { Plus, PlusCircle } from "lucide-react";
  8.  
  9. interface SearchSuggestionsProps {
  10.     data: mediaType[] | [];
  11.     selected: boolean;
  12.     search: string;
  13.     isLoading: boolean;
  14.     handleClicked: (
  15.         mediaId: number,
  16.         mediaType: "movie" | "tv" | "person"
  17.     ) => void;
  18. }
  19.  
  20. const SearchSuggestions: React.FC<SearchSuggestionsProps> = ({
  21.     data,
  22.     selected,
  23.     search,
  24.     isLoading,
  25.     handleClicked,
  26. }) => {
  27.     const navigate = useNavigate();
  28.  
  29.     const { theme, systemTheme, defaultLanguage, accessToken, onOpen } =
  30.         useContext<AppContextTypes>(AppContext);
  31.  
  32.     const themeKey: AppContextTypes["theme"] =
  33.         theme === "system" ? (systemTheme ? "dark" : "light") : theme;
  34.     return (
  35.         <div>
  36.             {data.length > 0 && selected ? (
  37.                 <div
  38.                     className={`flex flex-col z-50 mt-1 gap-1 absolute py-4 px-2 rounded-2xl ${themeKey === "dark" ? "bg-[#00022A]" : "bg-[#ECECEC]"} w-[95vw] sm:w-[50vw] max-h-[520px] overflow-x-auto`}
  39.                 >
  40.                     {data.map((item: mediaType, idx: number) => (
  41.                         <div key={idx}>
  42.                             {item.media_type === "movie" || item.media_type === "tv" ? (
  43.                                 <div
  44.                                     key={item.id}
  45.                                     onClick={() =>
  46.                                         isLoading
  47.                                             ? null
  48.                                             : navigate(
  49.                                                     `/${item.media_type === "movie" ? "movie" : "tv"}/${item.id}${item.media_type === "tv" ? `/1/1` : ""}`
  50.                                                 )
  51.                                     }
  52.                                     className="flex flex-row justify-between gap-2 hover:bg-[#452fde]/15 hover:text-white rounded-md cursor-pointer p-2"
  53.                                 >
  54.                                     <div className="flex flex-row gap-2 items-center justify-center">
  55.                                         <Image
  56.                                             width={30}
  57.                                             radius="md"
  58.                                             src={`https://www.themoviedb.org/t/p/w94_and_h141_bestv2/${item.poster_path}`}
  59.                                         />
  60.                                         <div>
  61.                                             <h1>{item.title || item.name}</h1>
  62.                                             <div className="flex flex-row gap-1">
  63.                                                 <p>{item.release_date || item.first_air_date}</p>
  64.                                                 <p>
  65.                                                     {item.media_type === "movie"
  66.                                                         ? defaultLanguage === "bg-BG"
  67.                                                             ? "филм"
  68.                                                             : "movie"
  69.                                                         : defaultLanguage === "bg-BG"
  70.                                                             ? "сериал"
  71.                                                             : "tv show"}
  72.                                                 </p>
  73.                                             </div>
  74.                                         </div>
  75.                                     </div>
  76.                                     <div className="flex flex-row items-center justify-center text-white">
  77.                                         <Button
  78.                                             isDisabled={isLoading}
  79.                                             isLoading={isLoading}
  80.                                             onPress={() => {
  81.                                                 if (accessToken) {
  82.                                                     handleClicked(item.id, item.media_type);
  83.                                                 } else {
  84.                                                     onOpen();
  85.                                                 }
  86.                                             }}
  87.  
  88.                                             isIconOnly
  89.                                             radius="full"
  90.                                             className=" bg-transparent  hover:bg-[#452fde]/30 "
  91.                                         >
  92.                                             {item.check ? (
  93.                                                 <Image src={circleCheck} width={20} />
  94.                                             ) : (
  95.                                                 <PlusCircle size={20} color={"white"} />
  96.                                             )}
  97.                                         </Button>
  98.                                     </div>
  99.                                 </div>
  100.                             ) : (
  101.                                 <></>
  102.                             )}
  103.                         </div>
  104.                     ))}
  105.                     <div className="flex justify-center items-center">
  106.                         <Button
  107.                             color="primary"
  108.                             variant="shadow"
  109.                             onClick={() =>
  110.                                 navigate(
  111.                                     `/filter?keyword=${search.split(" ").join("+")}&sort=popularity&type=multi`
  112.                                 )
  113.                             }
  114.                             radius="full"
  115.                             className="w-[95%]"
  116.                             endContent={<Plus size={20} color={"white"} />}
  117.                         >
  118.                             {defaultLanguage === "bg-BG"
  119.                                 ? "Виж Всички Резултати"
  120.                                 : "View All Results"}
  121.                         </Button>
  122.                     </div>
  123.                 </div>
  124.             ) : (
  125.                 <>
  126.                     {isLoading ? (
  127.                         <>loading...</>
  128.                     ) : (
  129.                         <div>{selected && search.length > 3 && `no data`}</div>
  130.                     )}
  131.                 </>
  132.             )}
  133.         </div>
  134.     );
  135. };
  136.  
  137. export default SearchSuggestions;
  138.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement