import React, { useState, useEffect, useContext } from 'react'; import ReactGA from 'react-ga4'; import {getTheme} from '../theme.jsx'; import {Link} from 'react-router-dom'; import { Search as SearchIcon, CloudQueue as CloudQueueIcon, Code as CodeIcon } from '@mui/icons-material'; import { toast } from 'react-toastify'; import { Context } from '../context/ContextApi.jsx'; //import algoliasearch from 'algoliasearch/lite'; import algoliasearch from 'algoliasearch'; import { InstantSearch, connectSearchBox, connectHits } from 'react-instantsearch-dom'; import { Grid, Paper, TextField, ButtonBase, InputAdornment, Typography, Button, Tooltip } from '@mui/material'; import aa from 'search-insights' 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, inputHeight, apps, } = props const { themeMode } = useContext(Context) const theme = getTheme(themeMode) const isCloud = window.location.host === "localhost:3002" || window.location.host === "shuffler.io"; const rowHandler = maxRows === undefined || maxRows === null ? 50 : maxRows const xs = parsedXs === undefined || parsedXs === null ? 12 : parsedXs const [formMail, setFormMail] = React.useState(""); const [message, setMessage] = React.useState(""); const [formMessage, setFormMessage] = React.useState(""); const [selectedApp, setSelectedApp] = React.useState({}); const buttonStyle = {borderRadius: 30, height: 50, width: 220, margin: isMobile ? "15px auto 15px auto" : 20, fontSize: 18,} const innerColor = "rgba(255,255,255,0.65)" const borderRadius = 3 window.title = "Shuffle | Apps | Find and integration any app" const parsedInputHeight = inputHeight === undefined || inputHeight === null ? 295 : inputHeight // value={currentRefinement} const SearchBox = ({currentRefinement, refine, isSearchStalled} ) => { useEffect(() => { //console.log("FIRST LOAD ONLY? RUN REFINEMENT: !", currentRefinement) if (defaultSearch !== undefined && defaultSearch !== null) { refine(defaultSearch) } }, []) return (
), }} autoComplete='on' type="search" color="primary" defaultValue={defaultSearch} // placeholder={`Find ${defaultSearch} Apps...`} placeholder= {defaultSearch ? `${defaultSearch}` : "Search Apps "} id="shuffle_workflow_search_field" onChange={(event) => { refine(event.currentTarget.value) }} limit={5} /> {/*isSearchStalled ? 'My search is stalled' : ''*/} ) //value={currentRefinement} } const Hits = ({ hits }) => { const [mouseHoverIndex, setMouseHoverIndex] = useState(-1) var counted = 0 if (hits?.length < 20 && apps !== undefined && apps !== null && apps?.length > 0) { // Find the textbox html const findId = "shuffle_workflow_search_field" const searchField = document.getElementById(findId) const searchValue = searchField === null || searchField === undefined ? "" : searchField?.value if (searchValue?.length > 0) { const parsedsearch = searchValue.toLowerCase().replaceAll(" ", "") for (var appkey in apps) { const app = apps[appkey] const parsedAppname = app?.name?.toLowerCase().replaceAll(" ", "") if (parsedAppname.includes(parsedsearch)) { hits.push({ objectID: app.id, id: app.id, name: app.name, image_url: app.large_image, }) } } } else { console.log("No value in textfield: ", searchValue) } } return ( {hits.map((data, index) => { const paperStyle = { backgroundColor: index === mouseHoverIndex ? theme.palette.hoverColor : theme.palette.textFieldStyle.backgroundColor, 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: "100%", 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(isCreatorPage === true){ if (setNewSelectedApp !== undefined && setUserSpecialzedApp !== undefined) { setUserSpecialzedApp(userdata.id, data) } } if (setNewSelectedApp !== undefined) { setNewSelectedApp(data) } if (isCloud) { ReactGA.event({ category: "app_search", action: `app_${parsedname}_${data.id}_personalize_click`, label: "", }) } const queryID = "" if (queryID !== undefined && queryID !== null) { try { aa('init', { appId: searchClient.appId, apiKey: searchClient.transporter.headers["x-algolia-api-key"] }) const timestamp = new Date().getTime() aa('sendEvents', [ { eventType: 'conversion', eventName: 'App Framework Activation', index: 'appsearch', objectIDs: [data.objectID], timestamp: timestamp, queryID: queryID, userToken: userdata === undefined || userdata === null || userdata.id === undefined ? "unauthenticated" : userdata.id, } ]) } catch (e) { console.log("Failed algolia search update: ", e) } } }}>
{data.name} {parsedname}
) })}
) } const InputHits = ConfiguredHits === undefined ? Hits : ConfiguredHits const CustomSearchBox = connectSearchBox(SearchBox) const CustomHits = connectHits(InputHits) return (
) } export default Appsearch;