Skip to content

Commit

Permalink
fix: remove close on click
Browse files Browse the repository at this point in the history
  • Loading branch information
gagdiez committed Jul 25, 2024
1 parent e86c4f1 commit b52c731
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 28 deletions.
16 changes: 7 additions & 9 deletions src/components/sidebar-navigation/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,11 @@ export const Search = ({ inputRef }: { inputRef: any }) => {

switch (type) {
case 'Docs':
return rawResp.hits.map((item: any, index: number) => (
<DocsResults key={index} item={item} setOpen={setOpen} />
));
return rawResp.hits.map((item: any, index: number) => <DocsResults key={index} item={item} />);
case 'Apps':
return Object.values(rawResp).map((item: any, index: number) => (
<AppsResults key={index} item={item} setOpen={setOpen} />
));
return Object.values(rawResp).map((item: any, index: number) => <AppsResults key={index} item={item} />);
case 'Components':
return rawResp.hits.map((item: any, index: number) => (
<ComponentsResults key={index} item={item} setOpen={setOpen} />
));
return rawResp.hits.map((item: any, index: number) => <ComponentsResults key={index} item={item} />);
}
},
[debouncedSearchTerm],
Expand Down Expand Up @@ -94,6 +88,10 @@ export const Search = ({ inputRef }: { inputRef: any }) => {
setActiveTab(tabId);
};

useEffect(() => {
searchTerm && setOpen(true);
}, [searchTerm]);

useEffect(() => {
const handleClickOutside = (event: MouseEvent) => {
if (componentRef.current && !componentRef.current.contains(event.target as Node)) {
Expand Down
9 changes: 2 additions & 7 deletions src/components/sidebar-navigation/Search/AppsResults.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { set } from 'lodash';
import { useRouter } from 'next/router';
import styled from 'styled-components';

Expand Down Expand Up @@ -79,15 +78,11 @@ interface Item {

interface AppsResultsProps {
item: Item;
setOpen?: (open: boolean) => void;
}

export const AppsResults: React.FC<AppsResultsProps> = ({ item, setOpen }) => {
export const AppsResults: React.FC<AppsResultsProps> = ({ item }) => {
const router = useRouter();
const redirect = (url: string) => {
router.push(url);
setOpen && setOpen(false);
};
const redirect = (url: string) => router.push(url);

return (
<Card>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,11 @@ interface HighlightResult {

interface ComponentsResultsProps {
item: Item;
setOpen?: (open: boolean) => void;
}

export const ComponentsResults: React.FC<ComponentsResultsProps> = ({ item, setOpen }) => {
export const ComponentsResults: React.FC<ComponentsResultsProps> = ({ item }) => {
const router = useRouter();
const redirect = (url: string) => {
router.push(url);
setOpen && setOpen(false);
};
const redirect = (url: string) => router.push(url);
const defaultImage = 'bafkreifc4burlk35hxom3klq4mysmslfirj7slueenbj7ddwg7pc6ixomu';
const [imageSrc, setImageSrc] = useState(item?.image?.ipfs_cid || defaultImage);

Expand Down
8 changes: 2 additions & 6 deletions src/components/sidebar-navigation/Search/DocsResults.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,11 @@ interface HighlightResultItem {

interface DocsResultsProps {
item: Item;
setOpen?: (open: boolean) => void;
}

export const DocsResults: React.FC<DocsResultsProps> = ({ item, setOpen }) => {
export const DocsResults: React.FC<DocsResultsProps> = ({ item }) => {
const router = useRouter();
const redirect = (url: string) => {
router.push(url);
setOpen && setOpen(false);
};
const redirect = (url: string) => router.push(url);
const convertUrl = (url: string) => url.replace(/^https:\/\/docs\.near\.org\/(.+)$/, '/documentation/$1');

return (
Expand Down

0 comments on commit b52c731

Please sign in to comment.