removed redundant code

Massimo Melina committed Mar 6, 2022 at 20:01 UTC 95046af7d0f1224a44f2fda15333af8010326670
2 files changed +5 -7
admin/src/FileCard.ts
+3 -3
@@ -3,7 +3,7 @@
3 import { state, useSnapState } from './state'
4 import { createElement as h, useEffect, useMemo, useState } from 'react'
5 import { Card, CardContent, List, ListItem, ListItemText } from '@mui/material'
6 -import { BoolField, DisplayField, FieldComponent, FieldProps, Form, MultiSelectField, SelectField } from './Form'
6 +import { BoolField, DisplayField, Field, FieldProps, Form, MultiSelectField, SelectField } from './Form'
7 import { apiCall, useApi } from './api'
8 import { formatBytes, isEqualLax, onlyTruthy } from './misc'
9 import { reloadVfs, Who } from './VfsPage'
@@ -121,7 +121,7 @@ function WhoField({ value, onChange, parent, inherit, accounts, ...rest }: WhoFi
121
122 const arrayMode = Array.isArray(value)
123 return h('div', {},
124 - h(SelectField as FieldComponent<Who>, {
124 + h(SelectField as Field<Who>, {
125 ...rest,
126 value: arrayMode ? [] : value,
127 onChange(v, { was, event }) {
@@ -129,7 +129,7 @@ function WhoField({ value, onChange, parent, inherit, accounts, ...rest }: WhoFi
129 },
130 options
131 }),
132 - arrayMode && h(MultiSelectField as FieldComponent<string[]>, {
132 + arrayMode && h(MultiSelectField as Field<string[]>, {
133 label: "Choose accounts for " + rest.label,
134 value,
135 onChange,
admin/src/Form.ts
+2 -4
@@ -1,6 +1,6 @@
1 // This file is part of HFS - Copyright 2020-2021, Massimo Melina <a@rejetto.com> - License https://www.gnu.org/licenses/gpl-3.0.txt
2
3 -import { createElement as h, Fragment, isValidElement, ReactElement, useEffect, useState } from 'react'
3 +import { createElement as h, FC, Fragment, isValidElement, ReactElement, useEffect, useState } from 'react'
4 import {
5 Box,
6 Button,
@@ -20,7 +20,7 @@ import _ from 'lodash'
20 interface FieldDescriptor { k:string, comp?: any, label?: string | ReactElement, [extraProp:string]:any }
21
22 // it seems necessary to cast (Multi)SelectField sometimes
23 -export type FieldComponent<T> = (props:FieldProps<T>) => ReactElement
23 +export type Field<T> = FC<FieldProps<T>>
24
25 interface FormProps {
26 fields: (FieldDescriptor | ReactElement | null | undefined | false)[]
@@ -95,8 +95,6 @@ export interface FieldProps<T> {
95 [rest: string]: any
96 }
97
98 -export type Field<T> = (props:FieldProps<T>) => ReactElement
99 -
98 export function StringField({ value, onChange, fromField=_.identity, toField=_.identity, ...props }: FieldProps<string>) {
99 if (fromField === JSON.parse)
100 fromField = v => v ? JSON.parse(v) : undefined