Skip to content

Commit

Permalink
wip - add alt-s functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
RoyEJohnson committed Mar 27, 2024
1 parent f16aac6 commit 21fa234
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/app/content/components/Topbar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ import {
clearSearch,
openMobileToolbar,
openSearchResultsMobile,
requestSearch
requestSearch,
} from '../../search/actions';
import * as selectSearch from '../../search/selectors';
import * as selectContent from '../../selectors';
import { mobileNudgeStudyToolsTargetId } from '../NudgeStudyTools/constants';
import { NudgeElementTarget } from '../NudgeStudyTools/styles';
import * as Styled from './styled';
import { TextResizer } from './TextResizer';
import { useKeyCombination, useMatchMobileQuery } from '../../../reactUtils';
import { searchKeyCombination } from '../../highlights/constants';

interface Props {
search: typeof requestSearch;
Expand All @@ -35,6 +37,7 @@ interface Props {
bookTheme: string;
textSize: TextResizerValue | null;
setTextSize: (size: TextResizerValue) => void;
selectedResult: any;
}

type CommonSearchInputParams = Pick<
Expand Down Expand Up @@ -263,6 +266,27 @@ function Topbar(props: Props) {
[props]
);

const isMobile = useMatchMobileQuery();
const cycleSearchRegions = React.useCallback(
// Only in desktop layout
() => {
if (isMobile) {
console.info('Mobile: ignore');
return;
}
// Identify which regions are available
const hasResults = props.hasSearchResults;
const ssr = props.selectedResult;
// Determine which region we are in (if any)
// Navigate to the next region in sequence
console.info('Next region!', {isMobile, hasResults, query, ssr});

},
[isMobile, props.hasSearchResults, props.selectedResult, query]
);

useKeyCombination(searchKeyCombination, cycleSearchRegions);

return (
<Styled.TopBarWrapper data-testid='topbar'>
<Styled.SearchPrintWrapper>
Expand Down Expand Up @@ -325,6 +349,7 @@ export default connect(
searchInSidebar: selectSearch.searchInSidebar(state),
searchSidebarOpen: selectSearch.searchResultsOpen(state),
textSize: selectContent.textSize(state),
selectedResult: selectSearch.selectedResult(state),
}),
(dispatch: Dispatch) => ({
clearSearch: flow(clearSearch, dispatch),
Expand Down
5 changes: 5 additions & 0 deletions src/app/content/highlights/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@ export const highlightKeyCombination: KeyCombinationOptions = {
code: 'KeyH', // key isn't always h when alt is pressed
altKey: true,
};

export const searchKeyCombination: KeyCombinationOptions = {
code: 'KeyS',
altKey: true,
};
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ const OneSearchResultHit = ({
return (
<Styled.SectionContentPreview
selectedResult={isSelected}
aria-current={isSelected}
data-testid={testId}
key={index}
book={book}
Expand Down

0 comments on commit 21fa234

Please sign in to comment.