Live preview of post editing/replying thanks to TextFormatter 👏

This commit is contained in:
Toby Zerner
2015-07-22 16:05:00 +09:30
parent a0fe68272c
commit 017c258e46
14 changed files with 130 additions and 26 deletions

View File

@ -19,6 +19,29 @@ export default class EditPostComposer extends ComposerBody {
props.confirmExit = props.confirmExit || app.trans('core.confirm_discard_edit');
props.originalContent = props.originalContent || props.post.content();
props.user = props.user || props.post.user();
props.post.editedContent = props.originalContent;
}
config(isInitialized, context) {
super.config(isInitialized, context);
if (isInitialized) return;
// Every 50ms, if the content has changed, then update the post's
// editedContent property and redraw. This will cause the preview in the
// post's component to update.
const updateInterval = setInterval(() => {
const post = this.props.post;
const content = this.content();
if (content === post.editedContent) return;
post.editedContent = content;
m.redraw();
}, 50);
context.onunload = () => clearInterval(updateInterval);
}
headerItems() {