mirror of
https://github.com/flarum/core.git
synced 2025-08-06 08:27:42 +02:00
Reuse ComposerPostPreview in ReplyPlaceholder
This commit is contained in:
@@ -4,7 +4,7 @@ import Component from '../../common/Component';
|
|||||||
import avatar from '../../common/helpers/avatar';
|
import avatar from '../../common/helpers/avatar';
|
||||||
import username from '../../common/helpers/username';
|
import username from '../../common/helpers/username';
|
||||||
import DiscussionControls from '../utils/DiscussionControls';
|
import DiscussionControls from '../utils/DiscussionControls';
|
||||||
import ReplyPlaceholderPreview from './ReplyPlaceholderPreview';
|
import ComposerPostPreview from './ComposerPostPreview';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The `ReplyPlaceholder` component displays a placeholder for a reply, which,
|
* The `ReplyPlaceholder` component displays a placeholder for a reply, which,
|
||||||
@@ -27,7 +27,7 @@ export default class ReplyPlaceholder extends Component {
|
|||||||
</h3>
|
</h3>
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
<ReplyPlaceholderPreview />
|
<ComposerPostPreview className="Post-body" composer={app.composer} surround={this.anchorPreview.bind(this)} />
|
||||||
</article>
|
</article>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -44,4 +44,14 @@ export default class ReplyPlaceholder extends Component {
|
|||||||
</article>
|
</article>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
anchorPreview(preview) {
|
||||||
|
const anchorToBottom = $(window).scrollTop() + $(window).height() >= $(document).height();
|
||||||
|
|
||||||
|
preview();
|
||||||
|
|
||||||
|
if (anchorToBottom) {
|
||||||
|
$(window).scrollTop($(document).height());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,40 +0,0 @@
|
|||||||
/*global s9e*/
|
|
||||||
|
|
||||||
import Component from '../../common/Component';
|
|
||||||
|
|
||||||
export default class ReplyPlaceholderPreview extends Component {
|
|
||||||
view() {
|
|
||||||
return <div className="Post-body" />;
|
|
||||||
}
|
|
||||||
|
|
||||||
oncreate(vnode) {
|
|
||||||
super.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() {
|
|
||||||
clearInterval(this.updateInterval);
|
|
||||||
}
|
|
||||||
}
|
|
Reference in New Issue
Block a user