| 1 | import { EyeIcon } from "@heroicons/react/24/outline"; |
| 2 | import { useContext } from "react"; |
| 3 | import { useDispatch } from "react-redux"; |
| 4 | import { IdeMessengerContext } from "../../../../context/IdeMessenger"; |
| 5 | import { |
| 6 | setDialogMessage, |
| 7 | setShowDialog, |
| 8 | } from "../../../../redux/slices/uiSlice"; |
| 9 | import { fontSize } from "../../../../util"; |
| 10 | import DocsDetailsDialog from "./DocsDetailsDialog"; |
| 11 | |
| 12 | interface IndexedPagesTooltipProps { |
| 13 | pages: string[]; |
| 14 | siteTitle: string; |
| 15 | baseUrl: string; |
| 16 | } |
| 17 | |
| 18 | function removePrefix(str: string, prefix: string): string { |
| 19 | return str.startsWith(prefix) ? str.slice(prefix.length) : str; |
| 20 | } |
| 21 | |
| 22 | export const IndexedPagesTooltip = ({ |
| 23 | pages, |
| 24 | siteTitle, |
| 25 | baseUrl, |
| 26 | }: IndexedPagesTooltipProps) => { |
| 27 | const ideMessenger = useContext(IdeMessengerContext); |
| 28 | const dispatch = useDispatch(); |
| 29 | |
| 30 | const handleEyeIconClick = (e: React.MouseEvent) => { |
| 31 | e.stopPropagation(); |
| 32 | |
| 33 | // Open the DocsDetailsDialog component as a modal |
| 34 | dispatch(setShowDialog(true)); |
| 35 | dispatch(setDialogMessage(<DocsDetailsDialog startUrl={baseUrl} />)); |
| 36 | }; |
| 37 | |
| 38 | return ( |
| 39 | <div> |
| 40 | <div |
| 41 | className="mx-1 my-2 flex items-center justify-between font-semibold" |
| 42 | style={{ fontSize: fontSize(-3) }} |
| 43 | > |
| 44 | <span> |
| 45 | {siteTitle} - {pages.length} Pages Indexed |
| 46 | </span> |
| 47 | <EyeIcon |
| 48 | className="ml-2 h-4 w-4 cursor-pointer text-red-500 transition-colors hover:text-red-400" |
| 49 | onClick={handleEyeIconClick} |
| 50 | title="View detailed docs information" |
| 51 | /> |
| 52 | </div> |
| 53 | <div className="max-h-48 overflow-y-auto px-1"> |
| 54 | <ul className="list-none pl-0"> |
| 55 | {pages.map((page, index) => ( |
| 56 | <li |
| 57 | key={index} |
| 58 | className="my-1 cursor-pointer truncate text-left text-gray-400 hover:underline" |
| 59 | style={{ fontSize: fontSize(-4) }} |
| 60 | onClick={() => { |
| 61 | ideMessenger.post("openUrl", page); |
| 62 | }} |
| 63 | > |
| 64 | {removePrefix(page, baseUrl)} |
| 65 | </li> |
| 66 | ))} |
| 67 | </ul> |
| 68 | </div> |
| 69 | </div> |
| 70 | ); |
| 71 | }; |