1
0
mirror of https://github.com/flarum/core.git synced 2025-08-07 17:07:19 +02:00

add: Extract ReplyPlaceholderPreview from ReplyPlaceholder

This commit is contained in:
Alexander Skvortsov
2020-08-09 22:31:54 -04:00
committed by Franz Liedke
parent 27bacd779b
commit 1ce06611ce

View File

@@ -0,0 +1,36 @@
/*global s9e*/
export default class ReplyPlaceholderPreview {
view() {
return <div className="Post-body" />;
}
oncreate(vnode) {
// Every 50ms, if the composer content has changed, then update the post's
// body with a preview.
let preview;
this.updateInterval = setInterval(() => {
// Since we're polling, the composer may have been closed in the meantime,
// so we bail in that case.
if (!app.composer.isVisible()) return;
const content = app.composer.fields.content();
if (preview === content) return;
preview = content;
const anchorToBottom = $(window).scrollTop() + $(window).height() >= $(document).height();
s9e.TextFormatter.preview(preview || '', vnode.dom);
if (anchorToBottom) {
$(window).scrollTop($(document).height());
}
}, 50);
}
onremove(vnode) {
clearInterval(this.updateInterval);
}
}