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.
37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
4 years ago
|
import 'jquery.easing';
|
||
|
|
||
2 years ago
|
import $ from 'jquery';
|
||
|
|
||
4 years ago
|
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');
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
2 years ago
|
export default function reducer(state = null, action: any = {}) {
|
||
4 years ago
|
switch (action.type) {
|
||
3 years ago
|
case 'DIALOGUES_SWITCH_TO': {
|
||
|
scrollToViewport();
|
||
|
return action.payload;
|
||
|
}
|
||
|
case 'DIALOGUES_POST_SEND_FULFILLED': {
|
||
|
return action.meta.dialogueId;
|
||
|
}
|
||
|
default:
|
||
|
return state;
|
||
4 years ago
|
}
|
||
|
}
|