Migrate components to typescript

This commit is contained in:
Qolzam
2017-10-30 20:48:18 +07:00
parent 97c2e0f157
commit 7bbb1679ad
346 changed files with 6045 additions and 3946 deletions

View File

@@ -0,0 +1,105 @@
// - Import react components
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { connect } from 'react-redux'
import Avatar from 'material-ui/Avatar'
// - Import app components
// - Import API
// - Import actions
import * as imageGalleryActions from 'actions/imageGalleryActions'
import { IUserAvatarComponentProps } from './IUserAvatarComponentProps'
import { IUserAvatarComponentState } from './IUserAvatarComponentState'
/**
* Create component class
*/
export class UserAvatarComponent extends Component<IUserAvatarComponentProps,IUserAvatarComponentState> {
static propTypes = {
/**
* Use for getting url address from server
*/
fileName: PropTypes.string.isRequired,
/**
* User full name
*/
fullName: PropTypes.string.isRequired,
/**
* Avatar style
*/
style: PropTypes.object,
/**
* Avatar size
*/
size: PropTypes.number,
/**
* Trigger on touch tap
*/
onTouchTap: PropTypes.func
}
/**
* Component constructor
* @param {object} props is an object properties of component
*/
constructor (props: IUserAvatarComponentProps) {
super(props)
// Defaul state
this.state = {
}
// Binding functions to `this`
}
/**
* Reneder component DOM
* @return {react element} return the DOM which rendered by component
*/
render () {
let { fileName, fullName, style, size, onTouchTap } = this.props
return (
<div style={{display: 'inherit'}}>
{(fileName && fileName !== '' && fileName !== 'noImage' )
? ( <Avatar backgroundColor='#ffffff' src={fileName} size={size || 36} style={style} onTouchTap={onTouchTap} />)
: (<Avatar backgroundColor='#00bcd4' size={size || 36} style={style} onTouchTap={onTouchTap}>{fullName.slice(0, 1)}</Avatar>) }
</div>
)
}
}
/**
* Map dispatch to props
* @param {func} dispatch is the function to dispatch action to reducers
* @param {object} ownProps is the props belong to component
* @return {object} props of component
*/
const mapDispatchToProps = (dispatch: Function, ownProps: IUserAvatarComponentProps) => {
return {
}
}
/**
* Map state to props
* @param {object} state is the obeject from redux store
* @param {object} ownProps is the props belong to component
* @return {object} props of component
*/
const mapStateToProps = (state: any, ownProps: IUserAvatarComponentProps) => {
return {
avatarURL: state.imageGallery.imageURLList,
imageRequests: state.imageGallery.imageRequests
}
}
// - Connect component to redux store
export default connect(mapStateToProps, mapDispatchToProps)(UserAvatarComponent as any)