type narrowing/cleanup

This commit is contained in:
shams mosowi
2019-10-05 09:36:34 +10:00
parent 2dd11f253c
commit ef74c41145
5 changed files with 9 additions and 31 deletions

View File

@@ -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;

View File

@@ -5,7 +5,7 @@ import MuiRating from "@material-ui/lab/Rating";
interface Props {
value: number;
row: any;
row: { id: string };
onSubmit: Function;
isScrolling: boolean;
}

View File

@@ -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) => (
<ListItem
button
@@ -128,7 +127,7 @@ const SearchBox = (props: Props) => {
aria-describedby="transition-modal-description"
className={classes.modal}
open={open}
onClose={(event: any, reason: any) => {
onClose={() => {
clear();
}}
closeAfterTransition

View File

@@ -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 },

View File

@@ -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;