Migrate components to typescript
This commit is contained in:
20
src/components/yourCircles/IYourCirclesComponentProps.ts
Normal file
20
src/components/yourCircles/IYourCirclesComponentProps.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { Circle } from 'core/domain/circles'
|
||||
|
||||
export interface IYourCirclesComponentProps {
|
||||
|
||||
/**
|
||||
* Circles
|
||||
*
|
||||
* @type {{[circleId: string]: Circle}}
|
||||
* @memberof IYourCirclesComponentProps
|
||||
*/
|
||||
circles?: {[circleId: string]: Circle}
|
||||
|
||||
/**
|
||||
* User identifier
|
||||
*
|
||||
* @type {string}
|
||||
* @memberof IYourCirclesComponentProps
|
||||
*/
|
||||
uid?: string
|
||||
}
|
||||
4
src/components/yourCircles/IYourCirclesComponentState.ts
Normal file
4
src/components/yourCircles/IYourCirclesComponentState.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
|
||||
export interface IYourCirclesComponentState {
|
||||
|
||||
}
|
||||
109
src/components/yourCircles/YourCirclesComponent.tsx
Normal file
109
src/components/yourCircles/YourCirclesComponent.tsx
Normal file
@@ -0,0 +1,109 @@
|
||||
// - Import react components
|
||||
import React, { Component } from 'react'
|
||||
import { connect } from 'react-redux'
|
||||
import PropTypes from 'prop-types'
|
||||
import { List } from 'material-ui/List'
|
||||
|
||||
// - Import app components
|
||||
import CircleComponent from 'components/circle'
|
||||
import { IYourCirclesComponentProps } from './IYourCirclesComponentProps'
|
||||
import { IYourCirclesComponentState } from './IYourCirclesComponentState'
|
||||
|
||||
// - Import API
|
||||
|
||||
// - Import actions
|
||||
|
||||
/**
|
||||
* Create component class
|
||||
*/
|
||||
export class YourCirclesComponent extends Component<IYourCirclesComponentProps,IYourCirclesComponentState> {
|
||||
|
||||
static propTypes = {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Component constructor
|
||||
* @param {object} props is an object properties of component
|
||||
*/
|
||||
constructor (props: IYourCirclesComponentProps) {
|
||||
super(props)
|
||||
|
||||
// Defaul state
|
||||
this.state = {
|
||||
|
||||
}
|
||||
|
||||
// Binding functions to `this`
|
||||
|
||||
}
|
||||
|
||||
circleList = () => {
|
||||
let { circles,uid } = this.props
|
||||
let parsedCircles: any[] = []
|
||||
|
||||
if (circles) {
|
||||
Object.keys(circles).map((key, index) => {
|
||||
if (key.trim() !== '-Followers') {
|
||||
parsedCircles.push(<CircleComponent key={key} circle={circles![key]} id={key} uid={uid!} />)
|
||||
}
|
||||
})
|
||||
}
|
||||
return parsedCircles
|
||||
}
|
||||
|
||||
/**
|
||||
* Reneder component DOM
|
||||
* @return {react element} return the DOM which rendered by component
|
||||
*/
|
||||
render () {
|
||||
let circleItems = this.circleList()
|
||||
return (
|
||||
|
||||
<div style={{
|
||||
maxWidth: '800px',
|
||||
margin: '40px auto'
|
||||
}}>
|
||||
{(circleItems && circleItems.length !== 0 ) ? (<div>
|
||||
<div className='profile__title'>
|
||||
Your circles
|
||||
</div>
|
||||
<List>
|
||||
{circleItems}
|
||||
</List>
|
||||
<div style={{ height: '24px' }}></div>
|
||||
</div>) : ''}
|
||||
</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: IYourCirclesComponentProps) => {
|
||||
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: IYourCirclesComponentProps) => {
|
||||
const { uid } = state.authorize
|
||||
return {
|
||||
uid,
|
||||
circles: state.circle ? state.circle.userCircles[uid] : {}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// - Connect component to redux store
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(YourCirclesComponent as any)
|
||||
2
src/components/yourCircles/index.ts
Normal file
2
src/components/yourCircles/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
import YourCirclesComponent from './YourCirclesComponent'
|
||||
export default YourCirclesComponent
|
||||
Reference in New Issue
Block a user