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

View File

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