From d8e6a5fb2ecc6d46912e27ec83c4f364dc60becb Mon Sep 17 00:00:00 2001 From: fmtabbara Date: Tue, 31 Aug 2021 12:55:13 +0100 Subject: [PATCH] make typescript happy --- .../src/routes/internal-docs/ApiList.tsx | 34 ++--- .../src/routes/internal-docs/DocEntry.tsx | 127 +++++++++--------- 2 files changed, 80 insertions(+), 81 deletions(-) diff --git a/tauri-wallet/src/routes/internal-docs/ApiList.tsx b/tauri-wallet/src/routes/internal-docs/ApiList.tsx index 9737493870..10ca59f35e 100644 --- a/tauri-wallet/src/routes/internal-docs/ApiList.tsx +++ b/tauri-wallet/src/routes/internal-docs/ApiList.tsx @@ -1,28 +1,22 @@ -import React, { useState } from 'react' -import { - Button, - Checkbox, - FormControlLabel, - Grid, - InputAdornment, - List, - ListItem, - TextField, - Theme, -} from '@material-ui/core' -import { useTheme } from '@material-ui/styles' +import React from 'react' +import { List, ListItem } from '@material-ui/core' + import { DocEntry } from './DocEntry' export const ApiList = () => { - const [advancedShown, setAdvancedShown] = React.useState(false) - - const theme: Theme = useTheme() - return ( - - + + + + + + - ) } diff --git a/tauri-wallet/src/routes/internal-docs/DocEntry.tsx b/tauri-wallet/src/routes/internal-docs/DocEntry.tsx index beb612e32c..cb6eab5f27 100644 --- a/tauri-wallet/src/routes/internal-docs/DocEntry.tsx +++ b/tauri-wallet/src/routes/internal-docs/DocEntry.tsx @@ -1,85 +1,90 @@ import React, { useState } from 'react' -import { - Box, - Button, - Card, - Checkbox, - Divider, - FormControlLabel, - Grid, - InputAdornment, - TextField, - Theme, -} from '@material-ui/core' -import { useTheme } from '@material-ui/styles' +import { Button, Card, TextField } from '@material-ui/core' import { invoke } from '@tauri-apps/api' -import CardContent from '@material-ui/core/CardContent'; +import CardContent from '@material-ui/core/CardContent' interface DocEntryProps { - function: FunctionDef; + function: FunctionDef } interface FunctionDef { - name: string, - args: ArgDef[] + name: string + args: ArgDef[] } interface ArgDef { - name: string, - type: string + name: string + type: string } const argKey = (functionName: string, arg: string) => `${functionName}_${arg}` function collectArgs(functionName: string, args: ArgDef[]) { - let invokeArgs = {} - for (let arg of args) { - invokeArgs[arg.name] = document.getElementById(argKey(functionName, arg.name)).value - } - return invokeArgs + let invokeArgs: { [key: string]: string } = {} + args.forEach((arg) => { + const elem: HTMLElement | null = document.getElementById( + argKey(functionName, arg.name) + ) + if (elem) invokeArgs[arg.name] = (elem as HTMLInputElement).value || '' + }) + + return invokeArgs } export const DocEntry = (props: DocEntryProps) => { - const [card, setCard] = React.useState() - const theme: Theme = useTheme() + const [card, setCard] = React.useState() - const onClick = () => { - invoke(props.function.name, collectArgs(props.function.name, props.function.args)).then( - (result) => { - setCard({JSON.stringify(result, null, 4)}) - } - ).catch( - (e) => setCard({e}) + const onClick = () => { + invoke( + props.function.name, + collectArgs(props.function.name, props.function.args) + ) + .then((result) => { + setCard( + + {JSON.stringify(result, null, 4)} + ) - } + }) + .catch((e) => + setCard( + + {e} + + ) + ) + } - let fields = [] - for (let arg of props.function.args) { - fields.push( + + +
+ {props.function.args.map((arg) => ( + - ) - } - return ( -
- - -
{fields}
-
- {card} -
- - ) + key={argKey(props.function.name, arg.name)} + /> + ))} +
+
+ {card} + + ) }