Skip to content

Commit

Permalink
Merge pull request polkassembly#1014 from polkassembly/fix/searchBarI…
Browse files Browse the repository at this point in the history
…ssue

fix/searchbar issue
  • Loading branch information
rajdeep7Singh authored Dec 4, 2023
2 parents 24be83d + b556aa3 commit b1595ce
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
4 changes: 2 additions & 2 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { useRouter } from 'next/router';
import NextNProgress from 'nextjs-progressbar';
import { useEffect, useState } from 'react';
import AppLayout from 'src/components/AppLayout';
import CMDK from 'src/components/CMDK';
// import CMDK from 'src/components/CMDK';
import { antdTheme } from 'styles/antdTheme';

import { ApiContextProvider } from '~src/context/ApiContext';
Expand Down Expand Up @@ -93,7 +93,7 @@ function App({ Component, pageProps }: AppProps) {
{showSplashScreen && <SplashLoader />}
<main className={`${poppins.variable} ${poppins.className} ${robotoMono.className} ${workSans.className} ${showSplashScreen ? 'hidden' : ''}`}>
<NextNProgress color='#E5007A' />
<CMDK />
{/* <CMDK /> */}
<AppLayout
Component={Component}
pageProps={pageProps}
Expand Down
12 changes: 10 additions & 2 deletions src/components/Search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
// of the Apache-2.0 license. See the LICENSE file for details.

/* eslint-disable sort-keys */
import React, { useCallback, useEffect, useMemo, useState } from 'react';
import { Checkbox, Input, List, Modal, Popover, Radio, RadioChangeEvent, Collapse } from 'antd';
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { Checkbox, Input, List, Modal, Popover, Radio, RadioChangeEvent, Collapse, InputRef } from 'antd';
import _ from 'lodash';
import { CheckboxValueType } from 'antd/es/checkbox/Group';
import { networkTrackInfo } from '~src/global/post_trackInfo';
Expand Down Expand Up @@ -115,6 +115,13 @@ const NewSearch = ({ className, openModal, setOpenModal, isSuperSearch, setIsSup
const [isFilter, setIsFilter] = useState<boolean>(false);
const [justStart, setJustStart] = useState<boolean>(true);
const currentUser = useUserDetailsSelector();
const inputRef = useRef<InputRef>(null);

useEffect(() => {
if (openModal) {
setTimeout(() => inputRef.current?.focus(), 0);
}
}, [openModal]);

Object.keys(post_topic).map((topic) => topicOptions.push(topicToOptionText(topic)));

Expand Down Expand Up @@ -491,6 +498,7 @@ const NewSearch = ({ className, openModal, setOpenModal, isSuperSearch, setIsSup
>
<div className={`${className} ${isSuperSearch && !loading && 'pb-2'}`}>
<Input
ref={inputRef}
className='placeholderColor mt-2 h-[40px] rounded-[4px] border-pink_primary text-bodyBlue dark:border-separatorDark dark:bg-section-dark-overlay dark:text-blue-dark-high dark:focus:border-[#91054F]'
type='search'
value={searchInput}
Expand Down
14 changes: 13 additions & 1 deletion src/ui-components/SearchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// of the Apache-2.0 license. See the LICENSE file for details.

import { SearchOutlined } from '@ant-design/icons';
import React, { FC, useState } from 'react';
import React, { FC, useEffect, useState } from 'react';
import styled from 'styled-components';
import ClientOnly, { Search } from './ClientOnly';
import NewSearch from 'src/components/Search';
Expand All @@ -26,6 +26,18 @@ const SearchBar: FC<ISearchBarProps> = (props) => {
const [isSuperSearch, setIsSuperSearch] = useState<boolean>(false);
const { resolvedTheme: theme } = useTheme();

useEffect(() => {
const handleKeyDown = (event: KeyboardEvent) => {
if ((event.metaKey || event.ctrlKey) && event.key === 'k') {
setOpen((prev) => !prev);
}
};
document.addEventListener('keydown', handleKeyDown);
return () => {
document.removeEventListener('keydown', handleKeyDown);
};
}, [open]);

return allowedNetwork.includes(network?.toUpperCase()) ? (
<div className={className}>
{isSmallScreen ? (
Expand Down

0 comments on commit b1595ce

Please sign in to comment.