diff --git a/src/Search/TypeAheadDropdown.jsx b/src/Search/TypeAheadDropdown.jsx index 89089e09..52b36f13 100644 --- a/src/Search/TypeAheadDropdown.jsx +++ b/src/Search/TypeAheadDropdown.jsx @@ -5,9 +5,6 @@ const API_URL = props.apiUrl ?? `https://${APPLICATION_ID}-dsn.algolia.net/1/ind const INITIAL_PAGE = props.initialPage ?? 0; const facets = props.facets ?? ["All", "People", "Apps", "Components", "Posts"]; const tab = props.tab ?? "All"; -const showHeader = props.showHeader ?? true; -const showSearchBar = props.showSearchBar ?? true; -const showPagination = props.showPagination ?? true; const userId = props.accountId ?? context.accountId; const searchPageUrl = "/${REPL_ACCOUNT}/widget/Search.IndexPage"; const topmostCount = props.topmostCount ?? 3; @@ -16,14 +13,6 @@ State.init({ currentPage: 0, selectedTab: tab, facet: tab, - isFiltersPanelVisible: false, - numColumns: 3, - selectedTags: [], - searchResults: [], // Assuming search results are stored here - allTags: [], - activeTags: [], - showFollowed: false, - showNotFollowed: false, }); // Styling Specifications @@ -231,6 +220,15 @@ const ScrollableContent = styled.div` const Item = styled.div``; +const _parceDataByFacet = (facet, arr) => { + if (!arr || arr.length === 0) return []; + return arr.slice(0, topmostCount).map((item) => ({ + ...item, + variant: item.variant ?? facet, + relevance: item.searchPosition, + })); +}; + const DisplayResultsByFacet = ({ title, count, items }) => ( @@ -249,6 +247,98 @@ const DisplayResultsByFacet = ({ title, count, items }) => ( ); +const DisplayAllResults = () => { + const profiles = _parceDataByFacet("profile", state.profiles.hits); + const apps = _parceDataByFacet("apps", state.apps.hits); + const components = _parceDataByFacet("components", state.components.hits); + const postsAndComments = _parceDataByFacet("postsAndComments", state.postsAndComments.hits); + const allResults = [...apps, ...profiles, ...components, ...postsAndComments]; + const sortedResults = allResults?.sort((a, b) => a.relevance - b.relevance); + return ( + ( + + ))} + /> + ); +}; + +const ResultByFacet = (record) => { + switch (record.variant) { + case "profile": + return ( + + + onSearchResultClick({ + queryID: record.queryID, + searchPosition: record.searchPosition, + objectID: `${record.accountId}/profile`, + eventName: "Clicked Profile After Search", + }), + }} + /> + + ); + case "apps": + case "components": + case "nearcatalog": + const isNearCatalogItem = record.variant === "nearcatalog"; + const componentSrc = isNearCatalogItem + ? `${record.accountId}/widget/${record.widgetName}?id=${record.slug}` + : `${record.accountId}/widget/${record.widgetName}`; + const componentProps = isNearCatalogItem + ? { image: record.image, name: record.name, variant: record.variant } + : {}; + return ( + + + onSearchResultClick({ + queryID: record.queryID, + searchPosition: record.searchPosition, + objectID: `${record.accountId}/widget/${record.widgetName}`, + eventName: "Clicked App After Search", + }), + }} + /> + + ); + case "postsAndComments": + return ( + + + onSearchResultClick({ + queryID: record.queryID, + searchPosition: record.searchPosition, + objectID: `${record.accountId}/${record.postType}/${record.blockHeight}`, + eventName: "Clicked Post After Search", + }), + }} + /> + + ); + } +}; + const TextMessage = ({ message, ...props }) => (

{ }); }; -const topmostNEARCatalogComponents = () => { - let output = state.nearcatalog.hits.slice(0, 5); - - const queryID = state.nearcatalog.queryID; - const eventName = "Component"; - return output.map((component, i) => ( - - - onSearchResultClick({ - queryID, - searchPosition: component.searchPosition, - objectID: `${component.accountId}/widget/${component.widgetName}?id=${component.slug}`, - eventName: `Clicked ${eventName} After Search`, - }), - }} - /> - - )); -}; - const topmostPosts = () => { let output = []; @@ -781,30 +841,7 @@ const displayResultsByFacet = (selectedTab) => { ); case "All": - return ( - <> - {state.profiles.hits?.length > 0 && ( - - )} - {state.apps.hits?.length > 0 && ( - - )} - {state.components.hits?.length > 0 && ( - - )} - {state.postsAndComments.hits?.length > 0 && ( - - )} - - ); + return ; } };