From ef74c4114576e5e96109be7c7c90d950e92f8a45 Mon Sep 17 00:00:00 2001 From: shams mosowi Date: Sat, 5 Oct 2019 09:36:34 +1000 Subject: [PATCH] type narrowing/cleanup --- src/components/Fields/File.tsx | 2 +- src/components/Fields/Rating.tsx | 2 +- src/components/SearchBox.tsx | 5 ++--- src/hooks/useFiretable/useTableConfig.ts | 9 +++++---- src/hooks/useKeyCode.ts | 22 ---------------------- 5 files changed, 9 insertions(+), 31 deletions(-) delete mode 100644 src/hooks/useKeyCode.ts diff --git a/src/components/Fields/File.tsx b/src/components/Fields/File.tsx index 34ad3415..d187ad51 100644 --- a/src/components/Fields/File.tsx +++ b/src/components/Fields/File.tsx @@ -12,7 +12,7 @@ import CircularProgress from "@material-ui/core/CircularProgress"; // TODO: multi support interface Props { - value: any; + value: { name: string; downloadURL: string }[]; row: { ref: firebase.firestore.DocumentReference; id: string }; onSubmit: Function; fieldType: FieldType; diff --git a/src/components/Fields/Rating.tsx b/src/components/Fields/Rating.tsx index ca1824c4..738cefe4 100644 --- a/src/components/Fields/Rating.tsx +++ b/src/components/Fields/Rating.tsx @@ -5,7 +5,7 @@ import MuiRating from "@material-ui/lab/Rating"; interface Props { value: number; - row: any; + row: { id: string }; onSubmit: Function; isScrolling: boolean; } diff --git a/src/components/SearchBox.tsx b/src/components/SearchBox.tsx index d8eba919..63bf50aa 100644 --- a/src/components/SearchBox.tsx +++ b/src/components/SearchBox.tsx @@ -3,7 +3,7 @@ import { createStyles, makeStyles } from "@material-ui/core/styles"; import List from "@material-ui/core/List"; import ListItem from "@material-ui/core/ListItem"; import ListItemText from "@material-ui/core/ListItemText"; -import ClickAwayListener from "@material-ui/core/ClickAwayListener"; + import algoliasearch from "algoliasearch/lite"; import Paper from "@material-ui/core/Paper"; @@ -94,7 +94,6 @@ const SearchBox = (props: Props) => { const open = Boolean(collection); const id = open ? "no-transition-popper" : undefined; - const onClickAway = (event: any) => {}; const Hit = (hit: any) => ( { aria-describedby="transition-modal-description" className={classes.modal} open={open} - onClose={(event: any, reason: any) => { + onClose={() => { clear(); }} closeAfterTransition diff --git a/src/hooks/useFiretable/useTableConfig.ts b/src/hooks/useFiretable/useTableConfig.ts index b05c40ee..5460a355 100644 --- a/src/hooks/useFiretable/useTableConfig.ts +++ b/src/hooks/useFiretable/useTableConfig.ts @@ -24,7 +24,7 @@ const useTableConfig = (tablePath: string) => { loading: true, }); }; - const add = (name: string, type: FieldType, data?: any) => { + const add = (name: string, type: FieldType, data?: unknown) => { //TODO: validation const { columns } = tableConfigState; const key = _camelCase(name); @@ -38,9 +38,10 @@ const useTableConfig = (tablePath: string) => { columns[index].width = width; documentDispatch({ action: DocActions.update, data: { columns } }); }; - const updateColumn = (index: number, updatables: any) => { + type updatable = { field: string; value: unknown }; + const updateColumn = (index: number, updatables: updatable[]) => { const { columns } = tableConfigState; - updatables.forEach((updatable: any) => { + updatables.forEach((updatable: updatable) => { columns[index][updatable.field] = updatable.value; }); documentDispatch({ action: DocActions.update, data: { columns } }); @@ -62,7 +63,7 @@ const useTableConfig = (tablePath: string) => { data: { columns: reorderedColumns }, }); }; - const updateConfig = (key: string, value: any) => { + const updateConfig = (key: string, value: unknown) => { documentDispatch({ action: DocActions.update, data: { [key]: value }, diff --git a/src/hooks/useKeyCode.ts b/src/hooks/useKeyCode.ts deleted file mode 100644 index 49bc48e3..00000000 --- a/src/hooks/useKeyCode.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { useEffect, useState } from "react"; -function useKeyCode(keyCode: number) { - const [isPressed, setKeyPressed] = useState(false); - // Only allow fetching each keypress event once to prevent infinite loops - const clear = () => { - if (isPressed) { - setKeyPressed(false); - } - }; - useEffect(() => { - function downHandler(event: any) { - if (event.keyCode === keyCode) { - setKeyPressed(true); - } - } - window.addEventListener("keydown", downHandler); - return () => window.removeEventListener("keydown", downHandler); - }, [keyCode]); - - return { isPressed, clear }; -} -export default useKeyCode;