import React, { useState, useEffect, useRef } from 'react'; import theme from '../theme.jsx'; import { Link, useNavigate } from 'react-router-dom'; import { Search as SearchIcon, CloudQueue as CloudQueueIcon, Code as CodeIcon } from '@mui/icons-material'; //import algoliasearch from 'algoliasearch/lite'; import algoliasearch from 'algoliasearch'; import { InstantSearch, connectSearchBox, connectHits } from 'react-instantsearch-dom'; import { Grid, Paper, TextField, InputAdornment, Typography, } from '@mui/material'; const searchClient = algoliasearch("JNSS5CFDZZ", "33e4e3564f4f060e96e0531957bed552") const Appsearch = props => { const { maxRows, showName, showSuggestion, isMobile, globalUrl, parsedXs, newSelectedApp, setNewSelectedApp, defaultSearch, showSearch, ConfiguredHits, userdata, cy, isCreatorPage, actionImageList, setActionImageList, setUserSpecialzedApp, placeholder, } = props let navigate = useNavigate(); const rowHandler = maxRows === undefined || maxRows === null ? 50 : maxRows const xs = parsedXs === undefined || parsedXs === null ? 12 : parsedXs const [open, setOpen] = React.useState(false); const [value, setValue] = useState(""); window.title = "Shuffle | Apps | Find and integration any app" const useCloseOnBlur = (setOpen) => { useEffect(() => { // Add event listener to detect clicks outside of the search box const handleClickOutside = (event) => { // Check if the click is outside the search box if (!event.target.closest('.search-box')) { setOpen(false); } }; document.addEventListener('mousedown', handleClickOutside); // Clean up event listener return () => { document.removeEventListener('mousedown', handleClickOutside); }; }, [setOpen]); // Ensure that this effect runs whenever setOpen changes }; useCloseOnBlur(setOpen); const SearchBox = ({ currentRefinement, refine, isSearchStalled }) => { useEffect(() => { //console.log("FIRST LOAD ONLY? RUN REFINEMENT: !", currentRefinement) if (defaultSearch !== undefined && defaultSearch !== null) { refine(defaultSearch) } }, []) return (
{ navigate("/search?q=" + currentRefinement, { state: value, replace: true }) //navigate("/search?q="+currentRefinement, { state: value, replace: true }) //window.open("/apps"+currentRefinement, "_blank") }} style={{ cursor: 'pointer', width: isMobile ? 20 : "", marginright: 5, marginTop: isMobile ? 6 : 7 }} />
), }} autoComplete="off" type="search" color="primary" placeholder={placeholder !== undefined ? placeholder : "Search more than 2500 Apps"} id="shuffle_search_field" onChange={(event) => { // Remove "q" from URL // removeQuery("q") refine(event.currentTarget.value) }} onKeyDown={(event) => { if (event.keyCode === 13) { navigate("/search?q=" + currentRefinement, { state: value, replace: true }); } }} onClick={(event) => { setOpen(true); }} /> {/*isSearchStalled ? 'My search is stalled' : ''*/}
) } const Hits = ({ hits, currentRefinement }) => { const [mouseHoverIndex, setMouseHoverIndex] = useState(-1) var counted = 0 return ( {hits.map((data, index) => { const paperStyle = { backgroundColor: index === mouseHoverIndex ? "rgba(255,255,255,1)" : "#38383A", color: index === mouseHoverIndex ? theme.palette.inputColor : "rgba(255,255,255,0.8)", // border: newSelectedApp.objectID !== data.objectID ? `1px solid rgba(255,255,255,0.2)` : "2px solid #f86a3e", textAlign: "left", padding: 10, cursor: "pointer", position: "relative", overflow: "hidden", width: 402, minHeight: 37, maxHeight: 52, } if (counted === 12 / xs * rowHandler) { return null } counted += 1 var parsedname = data.name.valueOf() parsedname = (parsedname.charAt(0).toUpperCase() + parsedname.substring(1)).replaceAll("_", " ") return ( { setMouseHoverIndex(index) }} onMouseOut={() => { setMouseHoverIndex(-1) }} onClick={() => { if (setNewSelectedApp !== undefined) { setNewSelectedApp(data.name) } else { //need to add perfect url which redirect direct to app page const newname = data.name.toLowerCase().replaceAll(" ", "_") window.open("/apps/" + newname, "_blank") } }}>
{data.name} {parsedname}
) })}
) } const InputHits = ConfiguredHits === undefined ? Hits : ConfiguredHits const CustomSearchBox = connectSearchBox(SearchBox) const CustomHits = connectHits(InputHits) return (
{open ? : null}
) } export default Appsearch;