Merge pull request #1084 from apaatsio/handle-window-resize-properly
Handle window resize in React way
Этот коммит содержится в:
@@ -32,6 +32,7 @@ export default class CreateComment extends React.Component {
|
|||||||
this.removePreview = this.removePreview.bind(this);
|
this.removePreview = this.removePreview.bind(this);
|
||||||
this.handleSubmit = this.handleSubmit.bind(this);
|
this.handleSubmit = this.handleSubmit.bind(this);
|
||||||
this.getFileCount = this.getFileCount.bind(this);
|
this.getFileCount = this.getFileCount.bind(this);
|
||||||
|
this.handleResize = this.handleResize.bind(this);
|
||||||
|
|
||||||
PostStore.clearCommentDraftUploads();
|
PostStore.clearCommentDraftUploads();
|
||||||
|
|
||||||
@@ -40,13 +41,23 @@ export default class CreateComment extends React.Component {
|
|||||||
messageText: draft.message,
|
messageText: draft.message,
|
||||||
uploadsInProgress: draft.uploadsInProgress,
|
uploadsInProgress: draft.uploadsInProgress,
|
||||||
previews: draft.previews,
|
previews: draft.previews,
|
||||||
submitting: false
|
submitting: false,
|
||||||
|
windowWidth: Utils.windowWidth()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
componentDidMount() {
|
||||||
|
window.addEventListener('resize', this.handleResize);
|
||||||
|
}
|
||||||
|
componentWillUnmount() {
|
||||||
|
window.removeEventListener('resize', this.handleResize);
|
||||||
|
}
|
||||||
|
handleResize() {
|
||||||
|
this.setState({windowWidth: Utils.windowWidth()});
|
||||||
|
}
|
||||||
componentDidUpdate(prevProps, prevState) {
|
componentDidUpdate(prevProps, prevState) {
|
||||||
if (prevState.uploadsInProgress < this.state.uploadsInProgress) {
|
if (prevState.uploadsInProgress < this.state.uploadsInProgress) {
|
||||||
$('.post-right__scroll').scrollTop($('.post-right__scroll')[0].scrollHeight);
|
$('.post-right__scroll').scrollTop($('.post-right__scroll')[0].scrollHeight);
|
||||||
if ($(window).width() > 768) {
|
if (this.state.windowWidth > 768) {
|
||||||
$('.post-right__scroll').perfectScrollbar('update');
|
$('.post-right__scroll').perfectScrollbar('update');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ export default class CreatePost extends React.Component {
|
|||||||
this.onChange = this.onChange.bind(this);
|
this.onChange = this.onChange.bind(this);
|
||||||
this.getFileCount = this.getFileCount.bind(this);
|
this.getFileCount = this.getFileCount.bind(this);
|
||||||
this.handleArrowUp = this.handleArrowUp.bind(this);
|
this.handleArrowUp = this.handleArrowUp.bind(this);
|
||||||
|
this.handleResize = this.handleResize.bind(this);
|
||||||
|
|
||||||
PostStore.clearDraftUploads();
|
PostStore.clearDraftUploads();
|
||||||
|
|
||||||
@@ -48,9 +49,17 @@ export default class CreatePost extends React.Component {
|
|||||||
uploadsInProgress: draft.uploadsInProgress,
|
uploadsInProgress: draft.uploadsInProgress,
|
||||||
previews: draft.previews,
|
previews: draft.previews,
|
||||||
submitting: false,
|
submitting: false,
|
||||||
initialText: draft.messageText
|
initialText: draft.messageText,
|
||||||
|
windowWidth: Utils.windowWidth(),
|
||||||
|
windowHeigth: Utils.windowHeight()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
handleResize() {
|
||||||
|
this.setState({
|
||||||
|
windowWidth: Utils.windowWidth(),
|
||||||
|
windowHeight: Utils.windowHeight()
|
||||||
|
});
|
||||||
|
}
|
||||||
componentDidUpdate(prevProps, prevState) {
|
componentDidUpdate(prevProps, prevState) {
|
||||||
if (prevState.previews.length !== this.state.previews.length) {
|
if (prevState.previews.length !== this.state.previews.length) {
|
||||||
this.resizePostHolder();
|
this.resizePostHolder();
|
||||||
@@ -61,6 +70,11 @@ export default class CreatePost extends React.Component {
|
|||||||
this.resizePostHolder();
|
this.resizePostHolder();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (prevState.windowWidth !== this.state.windowWidth || prevState.windowHeight !== this.state.windowHeigth) {
|
||||||
|
this.resizePostHolder();
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
getCurrentDraft() {
|
getCurrentDraft() {
|
||||||
const draft = PostStore.getCurrentDraft();
|
const draft = PostStore.getCurrentDraft();
|
||||||
@@ -194,10 +208,9 @@ export default class CreatePost extends React.Component {
|
|||||||
PostStore.storeCurrentDraft(draft);
|
PostStore.storeCurrentDraft(draft);
|
||||||
}
|
}
|
||||||
resizePostHolder() {
|
resizePostHolder() {
|
||||||
const height = $(window).height() - $(ReactDOM.findDOMNode(this.refs.topDiv)).height() - 50;
|
const height = this.state.windowHeigth - $(ReactDOM.findDOMNode(this.refs.topDiv)).height() - 50;
|
||||||
$('.post-list-holder-by-time').css('height', `${height}px`);
|
$('.post-list-holder-by-time').css('height', `${height}px`);
|
||||||
$(window).trigger('resize');
|
if (this.state.windowWidth > 960) {
|
||||||
if ($(window).width() > 960) {
|
|
||||||
$('#post_textbox').focus();
|
$('#post_textbox').focus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -274,9 +287,11 @@ export default class CreatePost extends React.Component {
|
|||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
ChannelStore.addChangeListener(this.onChange);
|
ChannelStore.addChangeListener(this.onChange);
|
||||||
this.resizePostHolder();
|
this.resizePostHolder();
|
||||||
|
window.addEventListener('resize', this.handleResize);
|
||||||
}
|
}
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
ChannelStore.removeChangeListener(this.onChange);
|
ChannelStore.removeChangeListener(this.onChange);
|
||||||
|
window.removeEventListener('resize', this.handleResize);
|
||||||
}
|
}
|
||||||
onChange() {
|
onChange() {
|
||||||
const channelId = ChannelStore.getCurrentId();
|
const channelId = ChannelStore.getCurrentId();
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
var PostStore = require('../stores/post_store.jsx');
|
var PostStore = require('../stores/post_store.jsx');
|
||||||
var UserStore = require('../stores/user_store.jsx');
|
var UserStore = require('../stores/user_store.jsx');
|
||||||
var PreferenceStore = require('../stores/preference_store.jsx');
|
var PreferenceStore = require('../stores/preference_store.jsx');
|
||||||
var utils = require('../utils/utils.jsx');
|
var Utils = require('../utils/utils.jsx');
|
||||||
var SearchBox = require('./search_bar.jsx');
|
var SearchBox = require('./search_bar.jsx');
|
||||||
var CreateComment = require('./create_comment.jsx');
|
var CreateComment = require('./create_comment.jsx');
|
||||||
var RhsHeaderPost = require('./rhs_header_post.jsx');
|
var RhsHeaderPost = require('./rhs_header_post.jsx');
|
||||||
@@ -20,8 +20,12 @@ export default class RhsThread extends React.Component {
|
|||||||
this.onChange = this.onChange.bind(this);
|
this.onChange = this.onChange.bind(this);
|
||||||
this.onChangeAll = this.onChangeAll.bind(this);
|
this.onChangeAll = this.onChangeAll.bind(this);
|
||||||
this.forceUpdateInfo = this.forceUpdateInfo.bind(this);
|
this.forceUpdateInfo = this.forceUpdateInfo.bind(this);
|
||||||
|
this.handleResize = this.handleResize.bind(this);
|
||||||
|
|
||||||
this.state = this.getStateFromStores();
|
const state = this.getStateFromStores();
|
||||||
|
state.windowWidth = Utils.windowWidth();
|
||||||
|
state.windowHeight = Utils.windowHeight();
|
||||||
|
this.state = state;
|
||||||
}
|
}
|
||||||
getStateFromStores() {
|
getStateFromStores() {
|
||||||
var postList = PostStore.getSelectedPost();
|
var postList = PostStore.getSelectedPost();
|
||||||
@@ -47,9 +51,7 @@ export default class RhsThread extends React.Component {
|
|||||||
PostStore.addChangeListener(this.onChangeAll);
|
PostStore.addChangeListener(this.onChangeAll);
|
||||||
PreferenceStore.addChangeListener(this.forceUpdateInfo);
|
PreferenceStore.addChangeListener(this.forceUpdateInfo);
|
||||||
this.resize();
|
this.resize();
|
||||||
$(window).resize(function resize() {
|
window.addEventListener('resize', this.handleResize);
|
||||||
this.resize();
|
|
||||||
}.bind(this));
|
|
||||||
}
|
}
|
||||||
componentDidUpdate() {
|
componentDidUpdate() {
|
||||||
if ($('.post-right__scroll')[0]) {
|
if ($('.post-right__scroll')[0]) {
|
||||||
@@ -61,6 +63,7 @@ export default class RhsThread extends React.Component {
|
|||||||
PostStore.removeSelectedPostChangeListener(this.onChange);
|
PostStore.removeSelectedPostChangeListener(this.onChange);
|
||||||
PostStore.removeChangeListener(this.onChangeAll);
|
PostStore.removeChangeListener(this.onChangeAll);
|
||||||
PreferenceStore.removeChangeListener(this.forceUpdateInfo);
|
PreferenceStore.removeChangeListener(this.forceUpdateInfo);
|
||||||
|
window.removeEventListener('resize', this.handleResize);
|
||||||
}
|
}
|
||||||
forceUpdateInfo() {
|
forceUpdateInfo() {
|
||||||
if (this.state.postList) {
|
if (this.state.postList) {
|
||||||
@@ -71,9 +74,15 @@ export default class RhsThread extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
handleResize() {
|
||||||
|
this.setState({
|
||||||
|
windowWidth: Utils.windowWidth(),
|
||||||
|
windowHeight: Utils.windowHeight()
|
||||||
|
});
|
||||||
|
}
|
||||||
onChange() {
|
onChange() {
|
||||||
var newState = this.getStateFromStores();
|
var newState = this.getStateFromStores();
|
||||||
if (!utils.areStatesEqual(newState, this.state)) {
|
if (!Utils.areStatesEqual(newState, this.state)) {
|
||||||
this.setState(newState);
|
this.setState(newState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -103,15 +112,15 @@ export default class RhsThread extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var newState = this.getStateFromStores();
|
var newState = this.getStateFromStores();
|
||||||
if (!utils.areStatesEqual(newState, this.state)) {
|
if (!Utils.areStatesEqual(newState, this.state)) {
|
||||||
this.setState(newState);
|
this.setState(newState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
resize() {
|
resize() {
|
||||||
var height = $(window).height() - $('#error_bar').outerHeight() - 100;
|
var height = this.state.windowHeight - $('#error_bar').outerHeight() - 100;
|
||||||
$('.post-right__scroll').css('height', height + 'px');
|
$('.post-right__scroll').css('height', height + 'px');
|
||||||
$('.post-right__scroll').scrollTop(100000);
|
$('.post-right__scroll').scrollTop(100000);
|
||||||
if ($(window).width() > 768) {
|
if (this.state.windowWidth > 768) {
|
||||||
$('.post-right__scroll').perfectScrollbar();
|
$('.post-right__scroll').perfectScrollbar();
|
||||||
$('.post-right__scroll').perfectScrollbar('update');
|
$('.post-right__scroll').perfectScrollbar('update');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
var PostStore = require('../stores/post_store.jsx');
|
var PostStore = require('../stores/post_store.jsx');
|
||||||
var UserStore = require('../stores/user_store.jsx');
|
var UserStore = require('../stores/user_store.jsx');
|
||||||
var SearchBox = require('./search_bar.jsx');
|
var SearchBox = require('./search_bar.jsx');
|
||||||
var utils = require('../utils/utils.jsx');
|
var Utils = require('../utils/utils.jsx');
|
||||||
var SearchResultsHeader = require('./search_results_header.jsx');
|
var SearchResultsHeader = require('./search_results_header.jsx');
|
||||||
var SearchResultsItem = require('./search_results_item.jsx');
|
var SearchResultsItem = require('./search_results_item.jsx');
|
||||||
|
|
||||||
@@ -20,18 +20,19 @@ export default class SearchResults extends React.Component {
|
|||||||
|
|
||||||
this.onChange = this.onChange.bind(this);
|
this.onChange = this.onChange.bind(this);
|
||||||
this.resize = this.resize.bind(this);
|
this.resize = this.resize.bind(this);
|
||||||
|
this.handleResize = this.handleResize.bind(this);
|
||||||
|
|
||||||
this.state = getStateFromStores();
|
const state = getStateFromStores();
|
||||||
|
state.windowWidth = Utils.windowWidth();
|
||||||
|
state.windowHeight = Utils.windowHeight();
|
||||||
|
this.state = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
this.mounted = true;
|
this.mounted = true;
|
||||||
PostStore.addSearchChangeListener(this.onChange);
|
PostStore.addSearchChangeListener(this.onChange);
|
||||||
this.resize();
|
this.resize();
|
||||||
var self = this;
|
window.addEventListener('resize', this.handleResize);
|
||||||
$(window).resize(function resize() {
|
|
||||||
self.resize();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidUpdate() {
|
componentDidUpdate() {
|
||||||
@@ -41,22 +42,30 @@ export default class SearchResults extends React.Component {
|
|||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
PostStore.removeSearchChangeListener(this.onChange);
|
PostStore.removeSearchChangeListener(this.onChange);
|
||||||
this.mounted = false;
|
this.mounted = false;
|
||||||
|
window.removeEventListener('resize', this.handleResize);
|
||||||
|
}
|
||||||
|
|
||||||
|
handleResize() {
|
||||||
|
this.setState({
|
||||||
|
windowWidth: Utils.windowWidth(),
|
||||||
|
windowHeight: Utils.windowHeight()
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
onChange() {
|
onChange() {
|
||||||
if (this.mounted) {
|
if (this.mounted) {
|
||||||
var newState = getStateFromStores();
|
var newState = getStateFromStores();
|
||||||
if (!utils.areStatesEqual(newState, this.state)) {
|
if (!Utils.areStatesEqual(newState, this.state)) {
|
||||||
this.setState(newState);
|
this.setState(newState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
resize() {
|
resize() {
|
||||||
var height = $(window).height() - $('#error_bar').outerHeight() - 100;
|
var height = this.state.windowHeight - $('#error_bar').outerHeight() - 100;
|
||||||
$('#search-items-container').css('height', height + 'px');
|
$('#search-items-container').css('height', height + 'px');
|
||||||
$('#search-items-container').scrollTop(0);
|
$('#search-items-container').scrollTop(0);
|
||||||
if ($(window).width() > 768) {
|
if (this.state.windowWidth > 768) {
|
||||||
$('#search-items-container').perfectScrollbar();
|
$('#search-items-container').perfectScrollbar();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,9 +29,10 @@ export default class Sidebar extends React.Component {
|
|||||||
|
|
||||||
this.onChange = this.onChange.bind(this);
|
this.onChange = this.onChange.bind(this);
|
||||||
this.onScroll = this.onScroll.bind(this);
|
this.onScroll = this.onScroll.bind(this);
|
||||||
this.onResize = this.onResize.bind(this);
|
|
||||||
this.updateUnreadIndicators = this.updateUnreadIndicators.bind(this);
|
this.updateUnreadIndicators = this.updateUnreadIndicators.bind(this);
|
||||||
this.handleLeaveDirectChannel = this.handleLeaveDirectChannel.bind(this);
|
this.handleLeaveDirectChannel = this.handleLeaveDirectChannel.bind(this);
|
||||||
|
this.updateScrollbar = this.updateScrollbar.bind(this);
|
||||||
|
this.handleResize = this.handleResize.bind(this);
|
||||||
|
|
||||||
this.showNewChannelModal = this.showNewChannelModal.bind(this);
|
this.showNewChannelModal = this.showNewChannelModal.bind(this);
|
||||||
this.hideNewChannelModal = this.hideNewChannelModal.bind(this);
|
this.hideNewChannelModal = this.hideNewChannelModal.bind(this);
|
||||||
@@ -46,6 +47,7 @@ export default class Sidebar extends React.Component {
|
|||||||
state.newChannelModalType = '';
|
state.newChannelModalType = '';
|
||||||
state.showDirectChannelsModal = false;
|
state.showDirectChannelsModal = false;
|
||||||
state.loadingDMChannel = -1;
|
state.loadingDMChannel = -1;
|
||||||
|
state.windowWidth = Utils.windowWidth();
|
||||||
|
|
||||||
this.state = state;
|
this.state = state;
|
||||||
}
|
}
|
||||||
@@ -129,14 +131,11 @@ export default class Sidebar extends React.Component {
|
|||||||
TeamStore.addChangeListener(this.onChange);
|
TeamStore.addChangeListener(this.onChange);
|
||||||
PreferenceStore.addChangeListener(this.onChange);
|
PreferenceStore.addChangeListener(this.onChange);
|
||||||
|
|
||||||
if ($(window).width() > 768) {
|
|
||||||
$('.nav-pills__container').perfectScrollbar();
|
|
||||||
}
|
|
||||||
|
|
||||||
this.updateTitle();
|
this.updateTitle();
|
||||||
this.updateUnreadIndicators();
|
this.updateUnreadIndicators();
|
||||||
|
this.updateScrollbar();
|
||||||
|
|
||||||
$(window).on('resize', this.onResize);
|
window.addEventListener('resize', this.handleResize);
|
||||||
}
|
}
|
||||||
shouldComponentUpdate(nextProps, nextState) {
|
shouldComponentUpdate(nextProps, nextState) {
|
||||||
if (!Utils.areStatesEqual(nextProps, this.props)) {
|
if (!Utils.areStatesEqual(nextProps, this.props)) {
|
||||||
@@ -151,9 +150,10 @@ export default class Sidebar extends React.Component {
|
|||||||
componentDidUpdate() {
|
componentDidUpdate() {
|
||||||
this.updateTitle();
|
this.updateTitle();
|
||||||
this.updateUnreadIndicators();
|
this.updateUnreadIndicators();
|
||||||
|
this.updateScrollbar();
|
||||||
}
|
}
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
$(window).off('resize', this.onResize);
|
window.removeEventListener('resize', this.handleResize);
|
||||||
|
|
||||||
ChannelStore.removeChangeListener(this.onChange);
|
ChannelStore.removeChangeListener(this.onChange);
|
||||||
UserStore.removeChangeListener(this.onChange);
|
UserStore.removeChangeListener(this.onChange);
|
||||||
@@ -161,6 +161,18 @@ export default class Sidebar extends React.Component {
|
|||||||
TeamStore.removeChangeListener(this.onChange);
|
TeamStore.removeChangeListener(this.onChange);
|
||||||
PreferenceStore.removeChangeListener(this.onChange);
|
PreferenceStore.removeChangeListener(this.onChange);
|
||||||
}
|
}
|
||||||
|
handleResize() {
|
||||||
|
this.setState({
|
||||||
|
windowWidth: Utils.windowWidth(),
|
||||||
|
windowHeight: Utils.windowHeight()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
updateScrollbar() {
|
||||||
|
if (this.state.windowWidth > 768) {
|
||||||
|
$('.nav-pills__container').perfectScrollbar();
|
||||||
|
$('.nav-pills__container').perfectScrollbar('update');
|
||||||
|
}
|
||||||
|
}
|
||||||
onChange() {
|
onChange() {
|
||||||
var newState = this.getStateFromStores();
|
var newState = this.getStateFromStores();
|
||||||
if (!Utils.areStatesEqual(newState, this.state)) {
|
if (!Utils.areStatesEqual(newState, this.state)) {
|
||||||
@@ -186,9 +198,6 @@ export default class Sidebar extends React.Component {
|
|||||||
onScroll() {
|
onScroll() {
|
||||||
this.updateUnreadIndicators();
|
this.updateUnreadIndicators();
|
||||||
}
|
}
|
||||||
onResize() {
|
|
||||||
this.updateUnreadIndicators();
|
|
||||||
}
|
|
||||||
updateUnreadIndicators() {
|
updateUnreadIndicators() {
|
||||||
const container = $(ReactDOM.findDOMNode(this.refs.container));
|
const container = $(ReactDOM.findDOMNode(this.refs.container));
|
||||||
|
|
||||||
|
|||||||
@@ -968,3 +968,11 @@ export function getShortenedTeamURL() {
|
|||||||
}
|
}
|
||||||
return teamURL + '/';
|
return teamURL + '/';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function windowWidth() {
|
||||||
|
return $(window).width();
|
||||||
|
}
|
||||||
|
|
||||||
|
export function windowHeight() {
|
||||||
|
return $(window).height();
|
||||||
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user