DEV: Use `transformedPost` as args to the Post widget (#202)

The post widgets expect to receive a transformed post as argument and use the spread operator to pass attributes to the inner widget, however the Docs plugin was providing a post model instance as argument instead.

This used to work fine, but as we introduce tracked properties in the post model, the spread operator doesn't copy their values, which causes issues.

This PR changes the `DocsTopic` Component to provide a `transformedPost` as argument to the post widget instead.

The change is necessary due to upcoming changes in the post model for the Glimmer post stream.
This commit is contained in:
Sérgio Saquetim 2025-03-18 14:37:56 -03:00 committed by GitHub
parent 9a7169a6df
commit 9fcfac6d76
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 13 additions and 5 deletions

View File

@ -1,21 +1,29 @@
import Component from "@ember/component"; import Component from "@ember/component";
import { reads } from "@ember/object/computed"; import { reads } from "@ember/object/computed";
import { service } from "@ember/service";
import { classNames } from "@ember-decorators/component"; import { classNames } from "@ember-decorators/component";
import discourseDebounce from "discourse/lib/debounce"; import discourseDebounce from "discourse/lib/debounce";
import computed, { bind } from "discourse/lib/decorators"; import computed, { bind } from "discourse/lib/decorators";
import transformPost from "discourse/lib/transform-post";
@classNames("docs-topic") @classNames("docs-topic")
export default class DocsTopic extends Component { export default class DocsTopic extends Component {
@service currentUser;
@service site;
@reads("post.cooked") originalPostContent; @reads("post.cooked") originalPostContent;
@computed("topic.post_stream") @computed("currentUser", "model")
post(stream) { post() {
return this.store.createRecord("post", stream?.posts.firstObject); return transformPost(this.currentUser, this.site, this.model);
} }
@computed("post", "topic") @computed("topic", "topic.post_stream")
model() { model() {
const post = this.post; const post = this.store.createRecord(
"post",
this.topic.post_stream?.posts.firstObject
);
if (!post.topic) { if (!post.topic) {
post.set("topic", this.topic); post.set("topic", this.topic);