de-emberobjectify stream

This commit is contained in:
Nat 2025-07-02 10:46:54 +08:00
parent 8397f62d3b
commit 220016c90f
No known key found for this signature in database
GPG Key ID: 4938B35D927EC773

View File

@ -6,17 +6,16 @@ import { ajax } from "discourse/lib/ajax";
import DiscourseRoute from "discourse/routes/discourse"; import DiscourseRoute from "discourse/routes/discourse";
import { i18n } from "discourse-i18n"; import { i18n } from "discourse-i18n";
class SolvedPostsStream extends EmberObject { class SolvedPostsStream {
@tracked content = []; @tracked content = [];
@tracked loading = false; @tracked loading = false;
@tracked loaded = false; @tracked loaded = false;
@tracked itemsLoaded = 0; @tracked itemsLoaded = 0;
@tracked canLoadMore = true; @tracked canLoadMore = true;
constructor(args) { constructor({ username, siteCategories }) {
super(args); this.username = username;
this.username = args.username; this.siteCategories = siteCategories;
this.siteCategories = args.siteCategories;
} }
get noContent() { get noContent() {
@ -28,7 +27,7 @@ class SolvedPostsStream extends EmberObject {
return Promise.resolve(); return Promise.resolve();
} }
this.set("loading", true); this.loading = true;
const limit = 20; const limit = 20;
return ajax( return ajax(
@ -38,7 +37,7 @@ class SolvedPostsStream extends EmberObject {
const userSolvedPosts = result.user_solved_posts || []; const userSolvedPosts = result.user_solved_posts || [];
if (userSolvedPosts.length === 0) { if (userSolvedPosts.length === 0) {
this.set("canLoadMore", false); this.canLoadMore = false;
return; return;
} }
@ -56,24 +55,16 @@ class SolvedPostsStream extends EmberObject {
return post; return post;
}); });
// Add to existing content this.content = [...this.content, ...posts];
if (this.content.pushObjects) { this.itemsLoaded = this.itemsLoaded + userSolvedPosts.length;
this.content.pushObjects(posts);
} else {
this.content = this.content.concat(posts);
}
this.set("itemsLoaded", this.itemsLoaded + userSolvedPosts.length);
if (userSolvedPosts.length < limit) { if (userSolvedPosts.length < limit) {
this.set("canLoadMore", false); this.canLoadMore = false;
} }
}) })
.finally(() => { .finally(() => {
this.setProperties({ this.loaded = true;
loaded: true, this.loading = false;
loading: false,
});
}); });
} }
} }