1
0
mirror of https://github.com/oceanprotocol/commons.git synced 2023-03-15 18:03:00 +01:00

better types

This commit is contained in:
Matthias Kretschmann 2019-03-29 19:44:58 +01:00
parent dd9ccd92f0
commit 1a9c875c48
Signed by: m
GPG Key ID: 606EEEF3C479A91F
7 changed files with 71 additions and 26 deletions

View File

@ -1,5 +1,5 @@
import cx from 'classnames' import cx from 'classnames'
import React, { PureComponent } from 'react' import React, { PureComponent, FormEvent, ChangeEvent } from 'react'
import slugify from 'slugify' import slugify from 'slugify'
import DatePicker from 'react-datepicker' import DatePicker from 'react-datepicker'
import { ReactComponent as SearchIcon } from '../../../img/search.svg' import { ReactComponent as SearchIcon } from '../../../img/search.svg'
@ -21,7 +21,13 @@ interface InputProps {
options?: string[] options?: string[]
additionalComponent?: any additionalComponent?: any
value?: string value?: string
onChange?: any onChange?(
event:
| FormEvent<HTMLInputElement>
| ChangeEvent<HTMLInputElement>
| ChangeEvent<HTMLSelectElement>
| ChangeEvent<HTMLTextAreaElement>
): void
rows?: number rows?: number
group?: any group?: any
multiple?: boolean multiple?: boolean
@ -29,11 +35,14 @@ interface InputProps {
interface InputState { interface InputState {
isFocused: boolean isFocused: boolean
startDate?: any startDate?: Date
} }
export default class Input extends PureComponent<InputProps, InputState> { export default class Input extends PureComponent<InputProps, InputState> {
public state: InputState = { isFocused: false, startDate: new Date() } public state: InputState = {
isFocused: false,
startDate: new Date()
}
public inputWrapClasses() { public inputWrapClasses() {
if (this.props.type === 'search') { if (this.props.type === 'search') {
@ -51,7 +60,7 @@ export default class Input extends PureComponent<InputProps, InputState> {
this.setState({ isFocused: !this.state.isFocused }) this.setState({ isFocused: !this.state.isFocused })
} }
public handleDateChange = (date: any) => { public handleDateChange = (date: Date) => {
this.setState({ this.setState({
startDate: date startDate: date
}) })

View File

@ -26,7 +26,7 @@
"fields": { "fields": {
"description": { "description": {
"label": "Description", "label": "Description",
"description": "Add a thorough description with as much detail as possible.", "help": "Add a thorough description with as much detail as possible.",
"placeholder": "i.e. Almond sales data ", "placeholder": "i.e. Almond sales data ",
"type": "textarea", "type": "textarea",
"required": true, "required": true,
@ -34,7 +34,7 @@
}, },
"categories": { "categories": {
"label": "Categories", "label": "Categories",
"description": "Pick a category which best fits your data set.", "help": "Pick a category which best fits your data set.",
"type": "select", "type": "select",
"required": true, "required": true,
"options": [ "options": [
@ -73,7 +73,7 @@
}, },
"dateCreated": { "dateCreated": {
"label": "Creation Date", "label": "Creation Date",
"description": "Select the date the asset was created, or was updated for the last time.", "help": "Select the date the asset was created, or was updated for the last time.",
"type": "date", "type": "date",
"required": true "required": true
} }

View File

@ -2,7 +2,13 @@ import React from 'react'
import styles from './Item.module.scss' import styles from './Item.module.scss'
import filesize from 'filesize' import filesize from 'filesize'
const Item = ({ item, removeItem }: { item: any; removeItem: any }) => ( const Item = ({
item,
removeItem
}: {
item: { url: string; found: boolean; type: string; size: number }
removeItem(): void
}) => (
<li> <li>
<a href={item.url}>{item.url}</a> <a href={item.url}>{item.url}</a>
<div className={styles.details}> <div className={styles.details}>

View File

@ -5,7 +5,7 @@ import Button from '../../../components/atoms/Button'
import styles from './ItemForm.module.scss' import styles from './ItemForm.module.scss'
interface ItemFormProps { interface ItemFormProps {
addItem: any addItem(url: string): void
placeholder: string placeholder: string
} }

View File

@ -1,4 +1,4 @@
import React, { PureComponent } from 'react' import React, { FormEvent, PureComponent, ChangeEvent } from 'react'
import { CSSTransition, TransitionGroup } from 'react-transition-group' import { CSSTransition, TransitionGroup } from 'react-transition-group'
import Button from '../../../components/atoms/Button' import Button from '../../../components/atoms/Button'
import Help from '../../../components/atoms/Form/Help' import Help from '../../../components/atoms/Form/Help'
@ -8,12 +8,25 @@ import styles from './index.module.scss'
import { serviceHost, servicePort, serviceScheme } from '../../../config' import { serviceHost, servicePort, serviceScheme } from '../../../config'
interface File {
url: string
found: boolean
size: number
type: string
}
interface FilesProps { interface FilesProps {
files: any[] files: [File]
placeholder: string placeholder: string
help?: string help?: string
name: string name: string
onChange: any onChange(
event:
| ChangeEvent<HTMLInputElement>
| FormEvent<HTMLInputElement>
| ChangeEvent<HTMLSelectElement>
| ChangeEvent<HTMLTextAreaElement>
): void
} }
interface FilesStates { interface FilesStates {
@ -33,7 +46,8 @@ export default class Files extends PureComponent<FilesProps, FilesStates> {
public addItem = async (value: string) => { public addItem = async (value: string) => {
let res: any let res: any
let file: any = { url: value, found: false } let file: File = { url: value, found: false, size: 0, type: '' }
try { try {
const response = await fetch( const response = await fetch(
`${serviceScheme}://${serviceHost}:${servicePort}/api/v1/urlcheck`, `${serviceScheme}://${serviceHost}:${servicePort}/api/v1/urlcheck`,

View File

@ -1,4 +1,4 @@
import React, { PureComponent } from 'react' import React, { PureComponent, FormEvent, ChangeEvent } from 'react'
import Input from '../../components/atoms/Form/Input' import Input from '../../components/atoms/Form/Input'
import Label from '../../components/atoms/Form/Label' import Label from '../../components/atoms/Form/Label'
import Row from '../../components/atoms/Form/Row' import Row from '../../components/atoms/Form/Row'
@ -8,20 +8,38 @@ import Files from './Files/'
import StepRegisterContent from './StepRegisterContent' import StepRegisterContent from './StepRegisterContent'
import styles from './Step.module.scss' import styles from './Step.module.scss'
interface Fields {
label: string
placeholder?: string
help?: string
type: string
required?: boolean
options?: string
rows?: number
}
interface StepProps { interface StepProps {
currentStep: number currentStep: number
index: number index: number
inputChange: any inputChange(
inputToArrayChange: any event:
fields?: any[] | FormEvent<HTMLInputElement>
| ChangeEvent<HTMLInputElement>
| ChangeEvent<HTMLSelectElement>
| ChangeEvent<HTMLTextAreaElement>
): void
inputToArrayChange(
event: ChangeEvent<HTMLSelectElement> | ChangeEvent<HTMLInputElement>
): void
fields?: Fields
state: any state: any
title: string title: string
description: string description: string
next: any next(): void
prev: any prev(): void
totalSteps: number totalSteps: number
tryAgain: any tryAgain(): void
toStart: any toStart(): void
publishedDid?: string publishedDid?: string
content?: string content?: string
} }
@ -66,7 +84,6 @@ export default class Step extends PureComponent<StepProps, {}> {
description, description,
fields, fields,
inputChange, inputChange,
inputToArrayChange,
state, state,
totalSteps, totalSteps,
tryAgain, tryAgain,
@ -89,7 +106,6 @@ export default class Step extends PureComponent<StepProps, {}> {
{fields && {fields &&
Object.entries(fields).map(([key, value]) => { Object.entries(fields).map(([key, value]) => {
if (key === 'files') { if (key === 'files') {
return ( return (
<Row key={key}> <Row key={key}>

View File

@ -4,8 +4,8 @@ import Spinner from '../../components/atoms/Spinner'
import styles from './StepRegisterContent.module.scss' import styles from './StepRegisterContent.module.scss'
interface StepRegisterContentProps { interface StepRegisterContentProps {
tryAgain: any tryAgain(): void
toStart: any toStart(): void
state: any state: any
content?: string content?: string
} }