Colocate reducers, actions and selectors
This commit is contained in:
parent
1e7d4c3fe4
commit
889e3b88b7
53 changed files with 1031 additions and 914 deletions
|
@ -1,64 +1,6 @@
|
|||
import FontFaceObserver from 'fontfaceobserver';
|
||||
import { stringWidth, measureScrollBarWidth } from './index';
|
||||
import { updateMessageHeight } from '../actions/message';
|
||||
|
||||
const lineHeight = 24;
|
||||
const menuWidth = 200;
|
||||
const userListWidth = 200;
|
||||
const messagePadding = 30;
|
||||
const smallScreen = 600;
|
||||
let windowWidth;
|
||||
|
||||
function init(store, charWidth, done) {
|
||||
window.messageIndent = 6 * charWidth;
|
||||
const scrollBarWidth = measureScrollBarWidth();
|
||||
let prevWrapWidth;
|
||||
|
||||
function updateWidth() {
|
||||
windowWidth = window.innerWidth;
|
||||
let wrapWidth = windowWidth - scrollBarWidth - messagePadding;
|
||||
if (windowWidth > smallScreen) {
|
||||
wrapWidth -= menuWidth;
|
||||
}
|
||||
|
||||
if (wrapWidth !== prevWrapWidth) {
|
||||
prevWrapWidth = wrapWidth;
|
||||
store.dispatch(updateMessageHeight(wrapWidth, charWidth));
|
||||
}
|
||||
}
|
||||
|
||||
let resizeRAF;
|
||||
|
||||
function resize() {
|
||||
if (resizeRAF) {
|
||||
window.cancelAnimationFrame(resizeRAF);
|
||||
}
|
||||
resizeRAF = window.requestAnimationFrame(updateWidth);
|
||||
}
|
||||
|
||||
updateWidth();
|
||||
done();
|
||||
window.addEventListener('resize', resize);
|
||||
}
|
||||
|
||||
export function initWidthUpdates(store, done) {
|
||||
let charWidth = localStorage.charWidth;
|
||||
if (charWidth) {
|
||||
init(store, parseFloat(charWidth), done);
|
||||
}
|
||||
|
||||
new FontFaceObserver('Roboto Mono').load().then(() => {
|
||||
if (!charWidth) {
|
||||
charWidth = stringWidth(' ', '16px Roboto Mono');
|
||||
init(store, charWidth, done);
|
||||
localStorage.charWidth = charWidth;
|
||||
}
|
||||
});
|
||||
|
||||
new FontFaceObserver('Montserrat').load();
|
||||
new FontFaceObserver('Montserrat', { weight: 700 }).load();
|
||||
new FontFaceObserver('Roboto Mono', { weight: 700 }).load();
|
||||
}
|
||||
|
||||
export function findBreakpoints(text) {
|
||||
const breakpoints = [];
|
||||
|
@ -76,15 +18,15 @@ export function findBreakpoints(text) {
|
|||
return breakpoints;
|
||||
}
|
||||
|
||||
export function messageHeight(message, width, charWidth, indent = 0) {
|
||||
export function messageHeight(message, wrapWidth, charWidth, indent = 0, windowWidth) {
|
||||
let pad = (6 + (message.from ? message.from.length + 1 : 0)) * charWidth;
|
||||
let height = lineHeight + 8;
|
||||
|
||||
if (message.channel && windowWidth > smallScreen) {
|
||||
width -= userListWidth;
|
||||
wrapWidth -= userListWidth;
|
||||
}
|
||||
|
||||
if (pad + (message.length * charWidth) < width) {
|
||||
if (pad + (message.length * charWidth) < wrapWidth) {
|
||||
return height;
|
||||
}
|
||||
|
||||
|
@ -93,7 +35,7 @@ export function messageHeight(message, width, charWidth, indent = 0) {
|
|||
let prevPos = 0;
|
||||
|
||||
for (let i = 0; i < breaks.length; i++) {
|
||||
if (pad + ((breaks[i].end - prevBreak) * charWidth) >= width) {
|
||||
if (pad + ((breaks[i].end - prevBreak) * charWidth) >= wrapWidth) {
|
||||
prevBreak = prevPos;
|
||||
pad = indent;
|
||||
height += lineHeight;
|
||||
|
@ -102,7 +44,7 @@ export function messageHeight(message, width, charWidth, indent = 0) {
|
|||
prevPos = breaks[i].next;
|
||||
}
|
||||
|
||||
if (pad + ((message.length - prevBreak) * charWidth) >= width) {
|
||||
if (pad + ((message.length - prevBreak) * charWidth) >= wrapWidth) {
|
||||
height += lineHeight;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue