2017-06-21 06:40:28 +00:00
|
|
|
import { getCharWidth } from 'state/app';
|
|
|
|
import { updateMessageHeight } from 'state/messages';
|
2018-04-05 19:13:32 +00:00
|
|
|
import { when } from 'utils/observe';
|
|
|
|
import { measureScrollBarWidth } from 'utils';
|
2018-10-26 05:00:37 +00:00
|
|
|
import { addResizeListener } from 'utils/size';
|
2017-05-26 06:20:00 +00:00
|
|
|
|
|
|
|
const menuWidth = 200;
|
|
|
|
const messagePadding = 30;
|
|
|
|
const smallScreen = 600;
|
|
|
|
|
|
|
|
export default function widthUpdates({ store }) {
|
|
|
|
when(store, getCharWidth, charWidth => {
|
|
|
|
const scrollBarWidth = measureScrollBarWidth();
|
|
|
|
let prevWrapWidth;
|
|
|
|
|
2018-10-26 05:00:37 +00:00
|
|
|
function updateWidth(windowWidth) {
|
2017-05-26 06:20:00 +00:00
|
|
|
let wrapWidth = windowWidth - scrollBarWidth - messagePadding;
|
|
|
|
if (windowWidth > smallScreen) {
|
|
|
|
wrapWidth -= menuWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wrapWidth !== prevWrapWidth) {
|
|
|
|
prevWrapWidth = wrapWidth;
|
|
|
|
store.dispatch(updateMessageHeight(wrapWidth, charWidth, windowWidth));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-26 05:00:37 +00:00
|
|
|
addResizeListener(updateWidth, true);
|
2017-05-26 06:20:00 +00:00
|
|
|
});
|
|
|
|
}
|