DEV: Add outlet + scroll event to support DiscoTOC (#75)

This commit is contained in:
Penar Musaraj 2022-01-19 12:43:00 -05:00 committed by GitHub
parent f8ac536160
commit 39f956fa13
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 7 deletions

View File

@ -1,18 +1,16 @@
import Component from "@ember/component";
import { reads } from "@ember/object/computed";
import computed from "discourse-common/utils/decorators";
import computed, { bind } from "discourse-common/utils/decorators";
import discourseDebounce from "discourse-common/lib/debounce";
export default Component.extend({
classNames: "docs-topic",
originalPostContent: reads("post.cooked"),
@computed("topic")
post() {
return this.store.createRecord(
"post",
this.topic.post_stream.posts.firstObject
);
@computed("topic.post_stream")
post(stream) {
return this.store.createRecord("post", stream?.posts.firstObject);
},
@computed("post", "topic")
@ -26,15 +24,27 @@ export default Component.extend({
return post;
},
@bind
_emitScrollEvent() {
this.appEvents.trigger("docs-topic:current-post-scrolled");
},
@bind
debounceScrollEvent() {
discourseDebounce(this, this._emitScrollEvent, 200);
},
didInsertElement() {
this._super(...arguments);
document.querySelector("body").classList.add("archetype-docs-topic");
document.addEventListener("scroll", this.debounceScrollEvent);
},
willDestroyElement() {
this._super(...arguments);
document.querySelector("body").classList.remove("archetype-docs-topic");
document.removeEventListener("scroll", this.debounceScrollEvent);
},
});

View File

@ -88,6 +88,7 @@
{{#if selectedTopic}}
{{#conditional-loading-spinner condition=isTopicLoading}}
{{docs-topic topic=topic return=(action "returnToList")}}
{{plugin-outlet name="below-docs-topic" tagName="" connectorTagName="div"}}
{{/conditional-loading-spinner}}
{{else}}
<div class="docs-results">