import React, { useState, useMemo } from "react"; import { Input } from "./ui/input"; import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger, } from "./ui/dialog"; import { Button } from "./ui/button"; import { fetchAllAuthorsData } from "../utils/authors"; import { generateCalendarData } from "../utils/calendar"; import Heatmap from "./Heatmap"; import { ModelData } from "../types/heatmap"; import { fetchAuthorData, fetchUserData } from "@/utils/authors"; const UserSearchDialog = () => { const [isOpen, setIsOpen] = useState(false); const [isLoading, setIsLoading] = useState(false); const [searchInput, setSearchInput] = useState(""); const [searchedData, setSearchedData] = useState(null); const [isCopied, setIsCopied] = useState(false); const [currentSearchTerm, setCurrentSearchTerm] = useState(""); const [userInfo, setUserInfo] = useState<{ fullName: string; avatarUrl: string | null } | null>(null); const handleSearch = async () => { if (searchInput.trim()) { setIsLoading(true); try { const authorData = await fetchAllAuthorsData([searchInput.trim()]); const authorInfo = await fetchUserData([searchInput.trim()]); setSearchedData(authorData); setUserInfo(authorInfo); setCurrentSearchTerm(searchInput.trim()); } catch (error) { console.error("Error fetching data for searched user:", error); setSearchedData(null); setUserInfo(null); setCurrentSearchTerm(""); } setIsLoading(false); } else { setSearchedData(null); setUserInfo(null); setCurrentSearchTerm(""); } }; const handleKeyPress = (e: React.KeyboardEvent) => { if (e.key === 'Enter') { handleSearch(); } }; const handleInputChange = (e: React.ChangeEvent) => { setSearchInput(e.target.value); }; const getIframeCode = (username: string) => { return ``; }; const handleCopyCode = () => { const iframeCode = getIframeCode(searchInput); navigator.clipboard.writeText(iframeCode).then(() => { setIsCopied(true); setTimeout(() => setIsCopied(false), 2000); }); }; const searchedHeatmapData = useMemo(() => { if (searchedData && searchedData.length > 0 && userInfo) { return generateCalendarData(searchedData, [{ authors: [currentSearchTerm], color: "#0088cc", fullName: userInfo.fullName, avatarUrl: userInfo.avatarUrl }])[currentSearchTerm]; } return null; }, [searchedData, currentSearchTerm, userInfo]); const handleDialogOpenChange = (open: boolean) => { setIsOpen(open); if (!open) { setSearchInput(""); setSearchedData(null); setCurrentSearchTerm(""); setIsLoading(false); setIsCopied(false); setUserInfo(null); } }; return ( Get your Hugging Face Heatmap
{isLoading ? (

Loading...

) : searchedHeatmapData && userInfo ? (

Embed in iFrame

                      {getIframeCode(searchInput)}
                    
) : searchedData !== null && searchedData.length === 0 ? (

User or Organization not found

) : null}
); }; export default UserSearchDialog;