Browse Source

fix: double opening

feat/mainnet-updates
kyranjamie 4 years ago
committed by Thomas Osmonson
parent
commit
004188f1c6
  1. 3
      src/components/search-button.tsx
  2. 9
      src/components/search.tsx
  3. 22
      yarn.lock

3
src/components/search-button.tsx

@ -6,7 +6,7 @@ import { useAppState } from '../common/hooks/use-app-state';
import { MagnifyingGlass } from './icons/magnifying-glass';
export const SearchButton = forwardRef((props: LinkProps, ref: Ref<HTMLDivElement>) => {
const { setState } = useAppState();
const { setState, searchModal } = useAppState();
return (
<IconButton
@ -16,6 +16,7 @@ export const SearchButton = forwardRef((props: LinkProps, ref: Ref<HTMLDivElemen
{...props}
ref={ref}
>
{searchModal}
<MagnifyingGlass size={18} color={color('text-title')} />
</IconButton>
);

9
src/components/search.tsx

@ -1,4 +1,4 @@
import React, { useEffect, useState } from 'react';
import React, { useEffect, useRef, useState } from 'react';
import {
Box,
Flex,
@ -33,7 +33,7 @@ const getLocalUrl = href => {
function Hit({ hit, children }: any) {
const url = getLocalUrl(hit.url);
return (
<Link href={url} as={url} passHref scroll={!url.includes('#')}>
<Link href={url} as={url} passHref scroll={false}>
<a>{children}</a>
</Link>
);
@ -80,7 +80,6 @@ let DocSearchModal: any = null;
export const SearchBox: React.FC<BoxProps> = React.memo(props => {
const { setState, searchModal } = useAppState();
const isOpen = searchModal === 'open' && DocSearchModal;
const importDocSearchModalIfNeeded = React.useCallback(function importDocSearchModalIfNeeded() {
if (DocSearchModal) {
@ -95,10 +94,11 @@ export const SearchBox: React.FC<BoxProps> = React.memo(props => {
const onOpen = React.useCallback(
function onOpen() {
void importDocSearchModalIfNeeded().then(() => {
console.log('reopening');
setState(state => ({ ...state, searchModal: 'open' }));
});
},
[importDocSearchModalIfNeeded, searchModal]
[importDocSearchModalIfNeeded]
);
const onClose = React.useCallback(
@ -113,6 +113,7 @@ export const SearchBox: React.FC<BoxProps> = React.memo(props => {
}, [searchModal]);
const searchButtonRef = React.useRef(null);
const isOpen = Boolean(searchModal === 'open' && DocSearchModal);
useDocSearchKeyboardEvents({ isOpen, onOpen, onClose, searchButtonRef });

22
yarn.lock

@ -2795,27 +2795,6 @@ algoliasearch@^3.24.5:
semver "^5.1.0"
tunnel-agent "^0.6.0"
<<<<<<< HEAD
algoliasearch@^4.0.0, algoliasearch@^4.5.1:
version "4.8.2"
resolved "https://registry.yarnpkg.com/algoliasearch/-/algoliasearch-4.8.2.tgz#499d187afe2169bc66c921cf7d5271c3fe0b3598"
integrity sha512-wQg1UpiXO6iXMXXyrmhKopjd3K4GGq5N/0qEjPB5OYzdvj4ju9rDIW8bYL9ghv9jD5IDrcyFsqCzlSKqn/RVXw==
dependencies:
"@algolia/cache-browser-local-storage" "4.8.2"
"@algolia/cache-common" "4.8.2"
"@algolia/cache-in-memory" "4.8.2"
"@algolia/client-account" "4.8.2"
"@algolia/client-analytics" "4.8.2"
"@algolia/client-common" "4.8.2"
"@algolia/client-recommendation" "4.8.2"
"@algolia/client-search" "4.8.2"
"@algolia/logger-common" "4.8.2"
"@algolia/logger-console" "4.8.2"
"@algolia/requester-browser-xhr" "4.8.2"
"@algolia/requester-common" "4.8.2"
"@algolia/requester-node-http" "4.8.2"
"@algolia/transporter" "4.8.2"
=======
algoliasearch@^4.0.0:
version "4.4.0"
resolved "https://registry.yarnpkg.com/algoliasearch/-/algoliasearch-4.4.0.tgz#25c356d8bdcf7e3f941633f61e1ac111ddcba404"
@ -2855,7 +2834,6 @@ algoliasearch@^4.5.1:
"@algolia/requester-common" "4.6.0"
"@algolia/requester-node-http" "4.6.0"
"@algolia/transporter" "4.6.0"
>>>>>>> feat: add mobile search
ally.js@1.4.1:
version "1.4.1"

Loading…
Cancel
Save