Browse Source

Change search to use controlled btn before input

master
jeffvli 3 years ago
committed by Jeff
parent
commit
ac061f8beb
  1. 2
      src/components/layout/GenericPage.tsx
  2. 43
      src/components/layout/GenericPageHeader.tsx

2
src/components/layout/GenericPage.tsx

@ -1,6 +1,5 @@
import React, { useEffect, useState } from 'react'; import React, { useEffect, useState } from 'react';
import { Divider } from 'rsuite'; import { Divider } from 'rsuite';
import { useHotkeys } from 'react-hotkeys-hook';
import { useAppSelector } from '../../redux/hooks'; import { useAppSelector } from '../../redux/hooks';
import { PageContainer, PageHeader, PageContent } from './styled'; import { PageContainer, PageHeader, PageContent } from './styled';
import { isCached } from '../../shared/utils'; import { isCached } from '../../shared/utils';
@ -9,7 +8,6 @@ const GenericPage = ({ header, children, hideDivider, ...rest }: any) => {
const playQueue = useAppSelector((state) => state.playQueue); const playQueue = useAppSelector((state) => state.playQueue);
const misc = useAppSelector((state) => state.misc); const misc = useAppSelector((state) => state.misc);
const [backgroundImage, setBackgroundImage] = useState(''); const [backgroundImage, setBackgroundImage] = useState('');
useHotkeys('ctrl+f', () => document.getElementById('local-search-input')?.focus());
useEffect(() => { useEffect(() => {
if (misc.dynamicBackground) { if (misc.dynamicBackground) {

43
src/components/layout/GenericPageHeader.tsx

@ -1,9 +1,10 @@
import React from 'react'; import React, { useState } from 'react';
import { LazyLoadImage } from 'react-lazy-load-image-component'; import { LazyLoadImage } from 'react-lazy-load-image-component';
import { useHistory } from 'react-router-dom'; import { useHistory } from 'react-router-dom';
import { useHotkeys } from 'react-hotkeys-hook';
import { Icon, Input, InputGroup } from 'rsuite'; import { Icon, Input, InputGroup } from 'rsuite';
import ViewTypeButtons from '../viewtypes/ViewTypeButtons'; import ViewTypeButtons from '../viewtypes/ViewTypeButtons';
import { StyledInputGroup } from '../shared/styled'; import { StyledIconButton, StyledInputGroup } from '../shared/styled';
import { CoverArtWrapper, PageHeaderTitle } from './styled'; import { CoverArtWrapper, PageHeaderTitle } from './styled';
import cacheImage from '../shared/cacheImage'; import cacheImage from '../shared/cacheImage';
import CustomTooltip from '../shared/CustomTooltip'; import CustomTooltip from '../shared/CustomTooltip';
@ -27,6 +28,12 @@ const GenericPageHeader = ({
showTitleTooltip, showTitleTooltip,
}: any) => { }: any) => {
const history = useHistory(); const history = useHistory();
const [openSearch, setOpenSearch] = useState(false);
useHotkeys('ctrl+f', () => {
setOpenSearch(true);
document.getElementById('local-search-input')?.focus();
});
return ( return (
<> <>
@ -86,12 +93,14 @@ const GenericPageHeader = ({
{sidetitle && <span style={{ display: 'inline-block' }}>{sidetitle}</span>} {sidetitle && <span style={{ display: 'inline-block' }}>{sidetitle}</span>}
{showSearchBar && ( {showSearchBar && (
<span style={{ display: 'inline-block' }}> <span style={{ display: 'inline-block' }}>
<StyledInputGroup inside> {searchQuery !== '' || openSearch ? (
<StyledInputGroup inside onClick={() => console.log('click')}>
<InputGroup.Addon>
<Icon icon="search" />
</InputGroup.Addon>
<Input <Input
id="local-search-input" id="local-search-input"
size="md"
value={searchQuery} value={searchQuery}
placeholder="Search..."
onChange={handleSearch} onChange={handleSearch}
onPressEnter={() => { onPressEnter={() => {
if (searchQuery.trim()) { if (searchQuery.trim()) {
@ -101,15 +110,33 @@ const GenericPageHeader = ({
onKeyDown={(e: KeyboardEvent) => { onKeyDown={(e: KeyboardEvent) => {
if (e.key === 'Escape') { if (e.key === 'Escape') {
clearSearchQuery(); clearSearchQuery();
setOpenSearch(false);
} }
}} }}
style={{ width: '180px' }}
/> />
{searchQuery !== '' && ( <InputGroup.Button
<InputGroup.Button appearance="subtle" onClick={clearSearchQuery}> appearance="subtle"
onClick={() => {
clearSearchQuery();
setOpenSearch(false);
}}
>
<Icon icon="close" /> <Icon icon="close" />
</InputGroup.Button> </InputGroup.Button>
)}
</StyledInputGroup> </StyledInputGroup>
) : (
<StyledIconButton
onClick={() => {
setOpenSearch(true);
setTimeout(() => {
document.getElementById('local-search-input')?.focus();
}, 50);
}}
appearance="subtle"
icon={<Icon icon="search" />}
/>
)}
</span> </span>
)} )}
</span> </span>

Loading…
Cancel
Save