Skip to content

Commit

Permalink
ctrl-f search
Browse files Browse the repository at this point in the history
fixes #55
  • Loading branch information
jmlee337 committed Jul 16, 2024
1 parent 4ae7125 commit a57af75
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 11 deletions.
27 changes: 19 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
"iconv-lite": "^0.6.3",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-hotkeys": "^2.0.0",
"react-router-dom": "^6.16.0",
"sanitize-filename": "^1.6.3",
"slp-enforcer": "^0.4.1",
Expand Down
1 change: 1 addition & 0 deletions src/main/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ const electronHandler = {
ipcRenderer.removeAllListeners('usbstorage');
ipcRenderer.on('usbstorage', callback);
},
isMac: process.platform === 'darwin',
};

contextBridge.exposeInMainWorld('electron', electronHandler);
Expand Down
40 changes: 37 additions & 3 deletions src/renderer/StartggView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import {
KeyboardArrowUp,
Refresh,
} from '@mui/icons-material';
import { useState } from 'react';
import { useRef, useState } from 'react';
import { GlobalHotKeys } from 'react-hotkeys';
import {
Event,
NameWithHighlight,
Expand Down Expand Up @@ -542,24 +543,42 @@ export default function StartggView({
eventSlug: string,
) => void;
}) {
const searchInputRef = useRef<HTMLInputElement>(null);
const [searchSubstr, setSearchSubstr] = useState('');
const [showSearch, setShowSearch] = useState(false);
const clearSearch = () => {
setSearchSubstr('');
setShowSearch(false);
};

return (
<Box>
{vlerkMode && (
{(showSearch || vlerkMode) && (
<Box style={{ padding: '8px 0' }}>
<TextField
autoFocus
fullWidth
label="Search"
onChange={(event) => {
setSearchSubstr(event.target.value);
}}
onKeyDown={(event) => {
if (event.key === 'Escape') {
clearSearch();
}
}}
inputRef={searchInputRef}
size="small"
value={searchSubstr}
InputProps={{
endAdornment: (
<InputAdornment position="end">
<Tooltip title="Clear search">
<IconButton onClick={() => setSearchSubstr('')}>
<IconButton
onClick={() => {
clearSearch();
}}
>
<Clear />
</IconButton>
</Tooltip>
Expand All @@ -582,6 +601,21 @@ export default function StartggView({
selectSet={selectSet}
/>
))}
<GlobalHotKeys
keyMap={{
ESC: 'escape',
FIND: window.electron.isMac ? 'command+f' : 'ctrl+f',
}}
handlers={{
ESC: () => {
clearSearch();
},
FIND: () => {
setShowSearch(true);
searchInputRef.current?.focus();
},
}}
/>
</Box>
);
}

0 comments on commit a57af75

Please sign in to comment.