Migrate Master component to typescript
This commit is contained in:
101
app/components/Master/IMasterProps.ts
Normal file
101
app/components/Master/IMasterProps.ts
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
export interface IMasterProps{
|
||||||
|
/**
|
||||||
|
* Close gloal message
|
||||||
|
*
|
||||||
|
* @type {Function}
|
||||||
|
* @memberof IMasterProps
|
||||||
|
*/
|
||||||
|
closeMessage: Function,
|
||||||
|
/**
|
||||||
|
* Show progress bar information
|
||||||
|
*
|
||||||
|
* @type {*}
|
||||||
|
* @memberof IMasterProps
|
||||||
|
*/
|
||||||
|
progress:any,
|
||||||
|
/**
|
||||||
|
* Login a user
|
||||||
|
*
|
||||||
|
* @type {Function}
|
||||||
|
* @memberof IMasterProps
|
||||||
|
*/
|
||||||
|
login: Function,
|
||||||
|
/**
|
||||||
|
* Global state
|
||||||
|
*
|
||||||
|
* @type {*}
|
||||||
|
* @memberof IMasterProps
|
||||||
|
*/
|
||||||
|
global:any,
|
||||||
|
/**
|
||||||
|
* Set flag {false} which user data has not loaded
|
||||||
|
*
|
||||||
|
* @type {Function}
|
||||||
|
* @memberof IMasterProps
|
||||||
|
*/
|
||||||
|
defaultDataDisable: Function,
|
||||||
|
/**
|
||||||
|
* Logout current user
|
||||||
|
*
|
||||||
|
* @type {Function}
|
||||||
|
* @memberof IMasterProps
|
||||||
|
*/
|
||||||
|
logout: Function,
|
||||||
|
/**
|
||||||
|
* Clear user date from store
|
||||||
|
*
|
||||||
|
* @type {Function}
|
||||||
|
* @memberof IMasterProps
|
||||||
|
*/
|
||||||
|
clearData: Function,
|
||||||
|
/**
|
||||||
|
* Prepare default data for a guest user
|
||||||
|
*
|
||||||
|
* @type {Function}
|
||||||
|
* @memberof IMasterProps
|
||||||
|
*/
|
||||||
|
loadDataGuest: Function,
|
||||||
|
/**
|
||||||
|
* Set flag {true} which all user data has loaded
|
||||||
|
*
|
||||||
|
* @type {Function}
|
||||||
|
* @memberof IMasterProps
|
||||||
|
*/
|
||||||
|
defaultDataEnable: Function,
|
||||||
|
/**
|
||||||
|
* Load user data into store
|
||||||
|
*
|
||||||
|
* @type {Function}
|
||||||
|
* @memberof IMasterProps
|
||||||
|
*/
|
||||||
|
loadData: Function,
|
||||||
|
/**
|
||||||
|
* If all data from all entities are loaded {true} if not {false}
|
||||||
|
*
|
||||||
|
* @type {Boolean}
|
||||||
|
* @memberof IMasterProps
|
||||||
|
*/
|
||||||
|
loaded:Boolean,
|
||||||
|
/**
|
||||||
|
* If current user is guest {true} if no
|
||||||
|
*
|
||||||
|
* @type {Boolean}
|
||||||
|
* @memberof IMasterProps
|
||||||
|
*/
|
||||||
|
guest:Boolean,
|
||||||
|
/**
|
||||||
|
* If current user is authed {true} if not {false}
|
||||||
|
*
|
||||||
|
* @type {Boolean}
|
||||||
|
* @memberof IMasterProps
|
||||||
|
*/
|
||||||
|
authed: Boolean,
|
||||||
|
/**
|
||||||
|
* Authed user identifier
|
||||||
|
*
|
||||||
|
* @type {string}
|
||||||
|
* @memberof IMasterProps
|
||||||
|
*/
|
||||||
|
uid: string
|
||||||
|
}
|
||||||
|
|
||||||
24
app/components/Master/IMasterState.ts
Normal file
24
app/components/Master/IMasterState.ts
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
|
||||||
|
export interface IMasterState {
|
||||||
|
/**
|
||||||
|
* Loding will be appeared if it's true
|
||||||
|
*
|
||||||
|
* @type {Boolean}
|
||||||
|
* @memberof IMasterState
|
||||||
|
*/
|
||||||
|
loading: Boolean,
|
||||||
|
/**
|
||||||
|
* It's true if user is authorized
|
||||||
|
*
|
||||||
|
* @type {Boolean}
|
||||||
|
* @memberof IMasterState
|
||||||
|
*/
|
||||||
|
authed:Boolean;
|
||||||
|
/**
|
||||||
|
* It's true if all default data loaded from database
|
||||||
|
*
|
||||||
|
* @type {Boolean}
|
||||||
|
* @memberof IMasterState
|
||||||
|
*/
|
||||||
|
dataLoaded:Boolean;
|
||||||
|
}
|
||||||
@@ -2,46 +2,49 @@
|
|||||||
import React, { Component } from 'react'
|
import React, { Component } from 'react'
|
||||||
import { connect } from 'react-redux'
|
import { connect } from 'react-redux'
|
||||||
import { Route, Switch, NavLink, withRouter, Redirect } from 'react-router-dom'
|
import { Route, Switch, NavLink, withRouter, Redirect } from 'react-router-dom'
|
||||||
import { firebaseAuth, firebaseRef } from 'app/firebase/'
|
import { firebaseAuth, firebaseRef } from 'app/firebase'
|
||||||
import { push } from 'react-router-redux'
|
import { push } from 'react-router-redux'
|
||||||
import Snackbar from 'material-ui/Snackbar';
|
import Snackbar from 'material-ui/Snackbar';
|
||||||
import LinearProgress from 'material-ui/LinearProgress'
|
import LinearProgress from 'material-ui/LinearProgress'
|
||||||
|
|
||||||
|
|
||||||
// - Import components
|
// - Import components
|
||||||
import Home from 'Home'
|
import Home from 'components/Home'
|
||||||
import Signup from 'Signup'
|
import Signup from 'components/Signup'
|
||||||
import Login from 'Login'
|
import Login from 'components/Login'
|
||||||
import Settings from 'Settings'
|
import Settings from 'components/Settings'
|
||||||
|
import MasterLoading from 'components/MasterLoading'
|
||||||
import MasterLoading from 'MasterLoading'
|
import { IMasterProps } from "./IMasterProps";
|
||||||
|
import { IMasterState } from "./IMasterState";
|
||||||
|
|
||||||
|
|
||||||
// - Import API
|
// - Import API
|
||||||
import { PrivateRoute, PublicRoute } from 'AuthRouterAPI'
|
import { PrivateRoute, PublicRoute } from 'api/AuthRouterAPI'
|
||||||
|
|
||||||
|
|
||||||
// - Import actions
|
// - Import actions
|
||||||
import * as authorizeActions from 'authorizeActions'
|
import * as authorizeActions from 'actions/authorizeActions'
|
||||||
import * as imageGalleryActions from 'imageGalleryActions'
|
import * as imageGalleryActions from 'actions/imageGalleryActions'
|
||||||
import * as postActions from 'postActions'
|
import * as postActions from 'actions/postActions'
|
||||||
import * as commentActions from 'commentActions'
|
import * as commentActions from 'actions/commentActions'
|
||||||
import * as voteActions from 'voteActions'
|
import * as voteActions from 'actions/voteActions'
|
||||||
import * as userActions from 'userActions'
|
import * as userActions from 'actions/userActions'
|
||||||
import * as globalActions from 'globalActions'
|
import * as globalActions from 'actions/globalActions'
|
||||||
import * as circleActions from 'circleActions'
|
import * as circleActions from 'actions/circleActions'
|
||||||
import * as notifyActions from 'notifyActions'
|
import * as notifyActions from 'actions/notifyActions'
|
||||||
|
|
||||||
|
|
||||||
/* ------------------------------------ */
|
/* ------------------------------------ */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// - Create Master component class
|
// - Create Master component class
|
||||||
export class Master extends Component {
|
export class Master extends Component<IMasterProps,IMasterState>{
|
||||||
|
|
||||||
static isPrivate = true
|
static isPrivate = true
|
||||||
// Constructor
|
// Constructor
|
||||||
constructor(props) {
|
constructor(props : IMasterProps) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
loading: true,
|
loading: true,
|
||||||
@@ -57,21 +60,21 @@ export class Master extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Handle click on message
|
// Handle click on message
|
||||||
handleMessage = (evt) => {
|
handleMessage = (evt: any) => {
|
||||||
this.props.closeMessage()
|
this.props.closeMessage()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle loading
|
// Handle loading
|
||||||
handleLoading = (status) => {
|
handleLoading = (status: boolean) => {
|
||||||
this.setState({
|
this.setState({
|
||||||
loading: status,
|
loading: status,
|
||||||
authed: false
|
authed: false
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillMount = () => {
|
componentWillMount (){
|
||||||
|
|
||||||
firebaseAuth().onAuthStateChanged((user) => {
|
firebaseAuth().onAuthStateChanged((user:any) => {
|
||||||
|
|
||||||
if (user) {
|
if (user) {
|
||||||
this.props.login(user)
|
this.props.login(user)
|
||||||
@@ -108,7 +111,7 @@ export class Master extends Component {
|
|||||||
*
|
*
|
||||||
* @memberof Master
|
* @memberof Master
|
||||||
*/
|
*/
|
||||||
render() {
|
public render() {
|
||||||
|
|
||||||
const {progress, global} = this.props
|
const {progress, global} = this.props
|
||||||
|
|
||||||
@@ -154,7 +157,7 @@ export class Master extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// - Map dispatch to props
|
// - Map dispatch to props
|
||||||
const mapDispatchToProps = (dispatch, ownProps) => {
|
const mapDispatchToProps = (dispatch : any, ownProps : any) => {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
loadData: () => {
|
loadData: () => {
|
||||||
@@ -177,7 +180,7 @@ const mapDispatchToProps = (dispatch, ownProps) => {
|
|||||||
dispatch(circleActions.clearAllCircles())
|
dispatch(circleActions.clearAllCircles())
|
||||||
|
|
||||||
},
|
},
|
||||||
login: (user) => {
|
login: (user : any) => {
|
||||||
dispatch(authorizeActions.login(user.uid))
|
dispatch(authorizeActions.login(user.uid))
|
||||||
},
|
},
|
||||||
logout: () => {
|
logout: () => {
|
||||||
@@ -203,8 +206,8 @@ const mapDispatchToProps = (dispatch, ownProps) => {
|
|||||||
* Map state to props
|
* Map state to props
|
||||||
* @param {object} state
|
* @param {object} state
|
||||||
*/
|
*/
|
||||||
const mapStateToProps = ({authorize, global, user, post, comment, imageGallery , vote, notify,circle }) => {
|
const mapStateToProps = (state : any) => {
|
||||||
|
const {authorize, global, user, post, comment, imageGallery , vote, notify,circle } = state;
|
||||||
return {
|
return {
|
||||||
guest: authorize.guest,
|
guest: authorize.guest,
|
||||||
uid: authorize.uid,
|
uid: authorize.uid,
|
||||||
@@ -216,4 +219,4 @@ const mapStateToProps = ({authorize, global, user, post, comment, imageGallery ,
|
|||||||
|
|
||||||
}
|
}
|
||||||
// - Connect commponent to redux store
|
// - Connect commponent to redux store
|
||||||
export default withRouter(connect(mapStateToProps, mapDispatchToProps)(Master))
|
export default withRouter(connect(mapStateToProps, mapDispatchToProps)(Master as any))
|
||||||
2
app/components/Master/index.ts
Normal file
2
app/components/Master/index.ts
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
import Master from './Master';
|
||||||
|
export default Master;
|
||||||
@@ -8,6 +8,8 @@ import Dialog from 'material-ui/Dialog'
|
|||||||
// - Create MasterLoading component class
|
// - Create MasterLoading component class
|
||||||
export default class MasterLoading extends Component {
|
export default class MasterLoading extends Component {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
|
|||||||
@@ -4,10 +4,9 @@
|
|||||||
"module": "es6", // use ES2015 modules
|
"module": "es6", // use ES2015 modules
|
||||||
"target": "es6", // compile to ES2015 (Babel will do the rest)
|
"target": "es6", // compile to ES2015 (Babel will do the rest)
|
||||||
"allowSyntheticDefaultImports": true, // see below
|
"allowSyntheticDefaultImports": true, // see below
|
||||||
"baseUrl": "./app", // enables you to import relative to this folder
|
"baseUrl": "./app/", // enables you to import relative to this folder
|
||||||
"paths": {
|
"paths": {
|
||||||
"angular2/*": ["../path/to/angular2/*"],
|
"app/*" : ["*"]
|
||||||
"local/*": ["../path/to/local/modules/*"]
|
|
||||||
},
|
},
|
||||||
"sourceMap": true, // make TypeScript generate sourcemaps
|
"sourceMap": true, // make TypeScript generate sourcemaps
|
||||||
"outDir": "public", // output directory to build to (irrelevant because we use Webpack most of the time)
|
"outDir": "public", // output directory to build to (irrelevant because we use Webpack most of the time)
|
||||||
|
|||||||
@@ -83,6 +83,7 @@ module.exports = {
|
|||||||
components: 'app/components',
|
components: 'app/components',
|
||||||
reducers: 'app/reducers',
|
reducers: 'app/reducers',
|
||||||
constants: 'app/constants',
|
constants: 'app/constants',
|
||||||
|
api: 'app/api',
|
||||||
db: 'app/db',
|
db: 'app/db',
|
||||||
store: 'app/store',
|
store: 'app/store',
|
||||||
applicationStyles: 'app/styles/app.scss',
|
applicationStyles: 'app/styles/app.scss',
|
||||||
|
|||||||
Reference in New Issue
Block a user