Skip to content

Commit

Permalink
Merge pull request #107 from seantiz/main
Browse files Browse the repository at this point in the history
Define explicit types for handler functions and events in App.tsx
  • Loading branch information
shivay-at-pieces authored May 24, 2024
2 parents bd0f9df + 714c01b commit 6ceef2e
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ type LocalAsset = {
classification: Pieces.ClassificationSpecificEnum,
}

type SnippetSelector = ( arg: number ) => void;
type SnippetDeselector = () => void;
type KeyboardInputHandler = ( arg: React.KeyboardEvent ) => void;
type FormHandler = (event: React.BaseSyntheticEvent) => void;

//=============================[GLOBALS]================================//
let full_context: JSON;
export var applicationData: Application;
Expand Down Expand Up @@ -50,16 +55,16 @@ export function App(): React.JSX.Element {
setArray([])
}

const handleSelect = (index) => {
const handleSelect: SnippetSelector = (index) => {
setSelectedIndex(index!=selectedIndex?index:-1);
};

const handleDeSelect = () => {
const handleDeSelect: SnippetDeselector = () => {
setSelectedIndex(-1)
};

// Keyboard event handler
const handleKeyPress = (event) => {
const handleKeyPress: KeyboardInputHandler = (event) => {
// Check if 'Cmd' on MacOS or 'Ctrl' on Windows is pressed along with '\'
if ((event.metaKey || event.ctrlKey) && event.key === '\\') {
handleDeSelect();
Expand Down Expand Up @@ -116,7 +121,7 @@ export function App(): React.JSX.Element {

const [searchTerm, setSearchTerm] = useState('')
const [searchResult, setSearchResult] = useState('')
const handleSearch = async (event) => {
const handleSearch: FormHandler = async (event) => {
event.preventDefault()
const searchTerm = event.target.elements['search-term'].value
if (!searchTerm) {
Expand Down

0 comments on commit 6ceef2e

Please sign in to comment.