You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Hydro/packages/ui-default/components/messagepad/reducers/activeId.js

37 lines
1.1 KiB
JavaScript

import 'jquery.easing';
import $ from 'jquery';
function scrollToViewport() {
const BOUND_TOP = 60;
const BOUND_BOTTOM = 20;
const node = $('.messagepad')[0];
if (node.offsetHeight + BOUND_TOP + BOUND_BOTTOM < window.innerHeight) {
const rect = node.getBoundingClientRect();
const rectBody = document.body.getBoundingClientRect();
let targetScrollTop = null;
if (rect.top < BOUND_TOP) {
targetScrollTop = rect.top - rectBody.top - BOUND_TOP;
} else if (rect.top + node.offsetHeight > window.innerHeight) {
targetScrollTop = rect.top - rectBody.top + node.offsetHeight + BOUND_BOTTOM - window.innerHeight;
}
if (targetScrollTop !== null) {
$('html, body').stop().animate({ scrollTop: targetScrollTop }, 200, 'easeOutCubic');
}
}
}
export default function reducer(state = null, action: any = {}) {
switch (action.type) {
case 'DIALOGUES_SWITCH_TO': {
scrollToViewport();
return action.payload;
}
case 'DIALOGUES_POST_SEND_FULFILLED': {
return action.meta.dialogueId;
}
default:
return state;
}
}