Vitalik
2 years ago
7 changed files with 199 additions and 455 deletions
@ -1,26 +0,0 @@
@@ -1,26 +0,0 @@
|
||||
import { PureComponent } from 'react'; |
||||
import { withRouter } from 'react-router-dom'; |
||||
import PropTypes from 'prop-types'; |
||||
|
||||
class ScrollToTop extends PureComponent<any> { |
||||
static propTypes = { |
||||
location: PropTypes.shape({ |
||||
pathname: PropTypes.string, |
||||
}).isRequired, |
||||
children: PropTypes.element.isRequired, |
||||
}; |
||||
|
||||
componentDidUpdate(prevProps) { |
||||
const { location } = this.props; |
||||
if (location.pathname !== prevProps.location.pathname) { |
||||
window.scrollTo(0, 0); |
||||
} |
||||
} |
||||
|
||||
render() { |
||||
const { children } = this.props; |
||||
return children; |
||||
} |
||||
} |
||||
|
||||
export default withRouter(ScrollToTop); |
@ -1,249 +0,0 @@
@@ -1,249 +0,0 @@
|
||||
import React, { Component } from 'react'; |
||||
import { connect } from 'react-redux'; |
||||
import { getUsersNotification } from '../Layout/topbar/TopbarNotification/actions'; |
||||
import { |
||||
getTasks, getUsers as getUserTask, getUsersPermissions, getFactories, getTypes, |
||||
} from '../Task/actions'; |
||||
import { getUsers } from '../User/actions'; |
||||
import { logout, me } from './actions'; |
||||
import { |
||||
gotMessage, gotMessageDelete, gotMessageEdit, gotMessagePin, gotMessageUnPin, loadChatMessages, |
||||
} from '../Messenger/redux/chat/chat.actions'; |
||||
import { gotChatCreated, gotChatDeleted, updateChat } from '../Messenger/redux/chatList/chatlist.actions'; |
||||
import taskSockets from './sockets'; |
||||
|
||||
|
||||
class SocketComponent extends Component<any> { |
||||
constructor(props) { |
||||
super(props); |
||||
this.state = { |
||||
is_init_socket: false, |
||||
}; |
||||
|
||||
this.header = {}; |
||||
|
||||
this.clientSocket = null; |
||||
} |
||||
|
||||
componentWillMount() { |
||||
|
||||
} |
||||
|
||||
componentDidMount() { |
||||
this.header = { |
||||
Authorization: `Bearer ${localStorage.getItem('tmp_token')}`, |
||||
}; |
||||
taskSockets.headers = this.header; |
||||
taskSockets.initSockets(); |
||||
} |
||||
|
||||
componentWillReceiveProps(nextProps) { |
||||
// if (!this.state.is_init_socket && nextProps.is_logined && nextProps.is_load) { |
||||
// this.header = { |
||||
// Authorization: `Bearer ${localStorage.getItem('tmp_token')}`, |
||||
// }; |
||||
// taskSockets.headers = this.header; |
||||
// taskSockets.initSockets(); |
||||
// this.state.is_init_socket = true; |
||||
// this.clientSocket = sailsIOClient(socketIOClient); |
||||
|
||||
|
||||
// this.clientSocket.sails.url = config.apiUrl; |
||||
// this.clientSocket.sails.initialConnectionHeaders = this.header; |
||||
|
||||
// this.clientSocket.sails.autoConnect = true; |
||||
|
||||
// this.clientSocket.sails.reconnection = true; |
||||
|
||||
// this.clientSocket.socket.on('connect', () => { |
||||
// this.state.is_connect = true; |
||||
// console.log('on connect'); |
||||
// // io.socket.get('/api/admin/socket_init', {headers: headers}, function (body, response) { |
||||
// this.clientSocket.socket.request({ |
||||
// method: 'get', |
||||
// url: '/api/auth/socket_init', |
||||
// headers: this.header |
||||
// }, (body, response) => { |
||||
// console.log('socket init req') |
||||
// console.log("TCL: SocketComponent -> componentWillReceiveProps -> response", response) |
||||
// console.log("TCL: SocketComponent -> componentWillReceiveProps -> body", body) |
||||
// }); |
||||
// }); |
||||
|
||||
|
||||
// this.clientSocket.socket.on('message',message => { |
||||
// console.log('message',message) |
||||
// // if(message.userId !== me.id){ |
||||
// // store.dispatch(gotMessage(message)) |
||||
// // } |
||||
// this.props.gotMessage(message) |
||||
|
||||
// }) |
||||
// this.clientSocket.socket.on('messageUnPinned',()=>{ |
||||
// console.log('gotMessageUnPIn') |
||||
// this.props.gotMessageUnPin() |
||||
// }) |
||||
// this.clientSocket.socket.on('messagePin',(msg)=>{ |
||||
// console.log('gotMessagePin',msg) |
||||
// this.props.gotMessagePin(msg) |
||||
// }) |
||||
// this.clientSocket.socket.on('messageDelete',(messageId)=>{ |
||||
// console.log('gotMessageToDelete',messageId) |
||||
// this.props.gotMessageDelete(messageId) |
||||
// }) |
||||
// this.clientSocket.socket.on('messageEdit',(message)=>{ |
||||
// console.log('gotMessageToEdit',message) |
||||
// this.props.gotMessageEdit(message) |
||||
// }) |
||||
// this.clientSocket.socket.on('notificationMessage', async message => { |
||||
// console.log('messageFromNotifications',message) |
||||
// // await Notifications.scheduleLocalNotificationAsync({title:message.chatName, |
||||
// // body:message.message |
||||
// // }) |
||||
// }) |
||||
// this.clientSocket.socket.on('chatCreated',(chat)=>{ |
||||
// console.log('chatCreateeeed',chat) |
||||
// this.props.gotChatCreated(chat) |
||||
// }) |
||||
// this.clientSocket.socket.on('chatUpdated',(chat)=>{ |
||||
// console.log('chatUpdateddd',chat) |
||||
// this.props.updateChat(chat) |
||||
// }) |
||||
// this.clientSocket.socket.on('chatDeleted',(chatId)=>{ |
||||
// console.log('chatDeleted',chatId) |
||||
// this.props.gotChatDeleted(chatId) |
||||
// }) |
||||
// this.clientSocket.socket.on('getLatest',()=>{ |
||||
// this.props.loadChatMessages() |
||||
// }) |
||||
|
||||
// this.clientSocket.socket.on('update_me', () => { |
||||
// this.props.me() |
||||
// }); |
||||
|
||||
// this.clientSocket.socket.on('update_notification', () => { |
||||
// this.props.getUsersNotification(); |
||||
// }); |
||||
|
||||
// this.clientSocket.socket.on('user_logout', (data) => { |
||||
// if(data.token_type){ |
||||
// if(data.token_type == 'desktop'){ |
||||
// this.props.logout(); |
||||
// } |
||||
// } else { |
||||
// this.props.logout(); |
||||
// } |
||||
|
||||
// }); |
||||
|
||||
// this.clientSocket.socket.on('update_users', () => { |
||||
|
||||
// this.props.getUsers(this.props.filter_user); |
||||
// this.props.getUserTask(); |
||||
// this.props.getUsersPermissions(); |
||||
// }); |
||||
|
||||
// this.clientSocket.socket.on('update_tasks', () => { |
||||
// this.props.getUserTask(); |
||||
// this.props.getFactories(); |
||||
// this.props.getTypes(); |
||||
// this.props.getUsersPermissions(); |
||||
// this.props.getTasks(this.props.filter_task, false); |
||||
// }); |
||||
|
||||
// this.clientSocket.socket.on('reconnect', () => { |
||||
// }); |
||||
|
||||
// this.clientSocket.socket.on('disconnect', () => { |
||||
// }); |
||||
|
||||
// this.clientSocket.socket.on('notification', (notification) => { |
||||
// this.props.getUsersNotification(); |
||||
// if(notification.type == 'task') |
||||
// this.props.getTasks(this.props.filter_task); |
||||
// }); |
||||
// } |
||||
|
||||
|
||||
// if(this.state.is_init_socket && !this.props.is_logined && nextProps.is_logined && nextProps.is_load){ |
||||
// if(this.clientSocket && this.clientSocket.socket.isConnected()){ |
||||
// this.header = { |
||||
// 'Authorization': 'Bearer ' + localStorage.getItem('tmp_token'), |
||||
// }; |
||||
// this.clientSocket.sails.initialConnectionHeaders = this.header; |
||||
// console.log('reconnect') |
||||
// this.clientSocket.socket.request({ |
||||
// method: 'get', |
||||
// url: '/api/auth/socket_init', |
||||
// headers: this.header |
||||
// }, (body, response) => { |
||||
// console.log("TCL: SocketComponent -> componentWillReceiveProps -> body", body) |
||||
|
||||
// }); |
||||
// } |
||||
// } |
||||
|
||||
// if(this.props.token != nextProps.token && nextProps.token){ |
||||
// if(this.clientSocket && this.clientSocket.socket.isConnected()){ |
||||
// this.header = { |
||||
// 'Authorization': 'Bearer ' + nextProps.token, |
||||
// }; |
||||
// this.clientSocket.sails.initialConnectionHeaders = this.header; |
||||
// console.log('reconnect') |
||||
// this.clientSocket.socket.request({ |
||||
// method: 'get', |
||||
// url: '/api/auth/socket_init', |
||||
// headers: this.header |
||||
// }, (body, response) => { |
||||
// console.log("TCL: SocketComponent -> componentWillReceiveProps22 -> body", body) |
||||
|
||||
// }); |
||||
// } |
||||
// } |
||||
} |
||||
|
||||
componentWillUnmount() { |
||||
|
||||
} |
||||
|
||||
render() { |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
SocketComponent.propTypes = { |
||||
|
||||
}; |
||||
|
||||
|
||||
const mapStateToProps = (state, ownProps) => ({ |
||||
is_logined: state.auth.is_logined, |
||||
is_load: state.auth.is_load, |
||||
token: state.auth.token, |
||||
filter_task: state.task.filter, |
||||
filter_user: state.user.filter, |
||||
}); |
||||
|
||||
const mapDispatchToProps = { |
||||
getUsersNotification, |
||||
getTasks, |
||||
getUsers, |
||||
getUserTask, |
||||
getUsersPermissions, |
||||
logout, |
||||
getFactories, |
||||
getTypes, |
||||
me, |
||||
gotMessage, |
||||
gotMessageDelete, |
||||
gotMessageEdit, |
||||
gotMessagePin, |
||||
gotMessageUnPin, |
||||
gotChatCreated, |
||||
gotChatDeleted, |
||||
updateChat, |
||||
loadChatMessages, |
||||
|
||||
}; |
||||
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(SocketComponent); |
Loading…
Reference in new issue