DEV: Asyncify loadTopicView (#18585)

See https://github.com/discourse/discourse/pull/14838#issuecomment-1271935405 for details about `controllerReady` logic.

Co-authored-by: David Taylor <david@taylorhq.com>
This commit is contained in:
Jarek Radosz
2022-10-14 12:44:31 +02:00
committed by GitHub
parent 7718ef97cc
commit 2c5e8f1763
4 changed files with 9 additions and 7 deletions

View File

@@ -24,7 +24,7 @@ import DiscourseURL, { userPath } from "discourse/lib/url";
import deprecated from "discourse-common/lib/deprecated"; import deprecated from "discourse-common/lib/deprecated";
import { applyModelTransformations } from "discourse/lib/model-transformers"; import { applyModelTransformations } from "discourse/lib/model-transformers";
export function loadTopicView(topic, args) { export async function loadTopicView(topic, args) {
const data = deepMerge({}, args); const data = deepMerge({}, args);
const url = `${getURL("/t/")}${topic.id}`; const url = `${getURL("/t/")}${topic.id}`;
const jsonUrl = (data.nearPost ? `${url}/${data.nearPost}` : url) + ".json"; const jsonUrl = (data.nearPost ? `${url}/${data.nearPost}` : url) + ".json";
@@ -33,12 +33,12 @@ export function loadTopicView(topic, args) {
delete data.__type; delete data.__type;
delete data.store; delete data.store;
return PreloadStore.getAndRemove(`topic_${topic.id}`, () => const json = await PreloadStore.getAndRemove(`topic_${topic.id}`, () =>
ajax(jsonUrl, { data }) ajax(jsonUrl, { data })
).then((json) => { );
topic.updateFromJson(json);
return json; topic.updateFromJson(json);
}); return json;
} }
export const ID_CONSTRAINT = /^\d+$/; export const ID_CONSTRAINT = /^\d+$/;

View File

@@ -80,6 +80,7 @@ export default DiscourseRoute.extend({
enteredAt: Date.now().toString(), enteredAt: Date.now().toString(),
userLastReadPostNumber: topic.last_read_post_number, userLastReadPostNumber: topic.last_read_post_number,
highestPostNumber: topic.highest_post_number, highestPostNumber: topic.highest_post_number,
controllerReady: true,
}); });
this.appEvents.trigger("page:topic-loaded", topic); this.appEvents.trigger("page:topic-loaded", topic);

View File

@@ -23,6 +23,7 @@ const TopicRoute = DiscourseRoute.extend({
isTransitioning: false, isTransitioning: false,
scheduledReplace: null, scheduledReplace: null,
lastScrollPos: null, lastScrollPos: null,
controllerReady: true,
}); });
}, },

View File

@@ -13,7 +13,7 @@
<PluginOutlet @name="topic-above-post-stream" @tagName="span" @connectorTagName="div" @args={{hash model=this.model editFirstPost=(action "editFirstPost")}} /> <PluginOutlet @name="topic-above-post-stream" @tagName="span" @connectorTagName="div" @args={{hash model=this.model editFirstPost=(action "editFirstPost")}} />
{{#if this.model.postStream.loaded}} {{#if (and this.controllerReady this.model.postStream.loaded)}}
{{#if this.model.postStream.firstPostPresent}} {{#if this.model.postStream.firstPostPresent}}
<TopicTitle @cancelled={{action "cancelEditingTopic"}} @save={{action "finishedEditingTopic"}} @model={{this.model}}> <TopicTitle @cancelled={{action "cancelEditingTopic"}} @save={{action "finishedEditingTopic"}} @model={{this.model}}>
{{#if this.editingTopic}} {{#if this.editingTopic}}