FIX: Correctly shows no bookmark message (#9548)
This commit is contained in:
+62
-62
@@ -2,6 +2,7 @@ import Controller from "@ember/controller";
|
||||
import showModal from "discourse/lib/show-modal";
|
||||
import { Promise } from "rsvp";
|
||||
import { inject } from "@ember/controller";
|
||||
import { action } from "@ember/object";
|
||||
import discourseComputed from "discourse-common/utils/decorators";
|
||||
import Bookmark from "discourse/models/bookmark";
|
||||
|
||||
@@ -22,12 +23,8 @@ export default Controller.extend({
|
||||
|
||||
return this.model
|
||||
.loadItems()
|
||||
.then(response => {
|
||||
this.processLoadResponse(response);
|
||||
})
|
||||
.catch(() => {
|
||||
this.set("noResultsHelp", I18n.t("bookmarks.list_permission_denied"));
|
||||
})
|
||||
.then(response => this._processLoadResponse(response))
|
||||
.catch(() => this._bookmarksListDenied())
|
||||
.finally(() =>
|
||||
this.setProperties({
|
||||
loaded: true,
|
||||
@@ -38,69 +35,72 @@ export default Controller.extend({
|
||||
|
||||
@discourseComputed("loaded", "content.length", "noResultsHelp")
|
||||
noContent(loaded, contentLength, noResultsHelp) {
|
||||
return loaded && contentLength === 0 && noResultsHelp !== null;
|
||||
return loaded && contentLength === 0 && noResultsHelp;
|
||||
},
|
||||
|
||||
processLoadResponse(response) {
|
||||
response = response.user_bookmark_list;
|
||||
@action
|
||||
removeBookmark(bookmark) {
|
||||
bootbox.confirm(I18n.t("bookmarks.confirm_delete"), result => {
|
||||
if (result) {
|
||||
return bookmark.destroy().then(() => this.loadItems());
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
if (response && response.no_results_help) {
|
||||
this.set("noResultsHelp", response.no_results_help);
|
||||
@action
|
||||
editBookmark(bookmark) {
|
||||
let controller = showModal("bookmark", {
|
||||
model: {
|
||||
postId: bookmark.post_id,
|
||||
id: bookmark.id,
|
||||
reminderAt: bookmark.reminder_at,
|
||||
name: bookmark.name
|
||||
},
|
||||
title: "post.bookmarks.edit",
|
||||
modalClass: "bookmark-with-reminder"
|
||||
});
|
||||
controller.setProperties({
|
||||
afterSave: () => this.loadItems()
|
||||
});
|
||||
},
|
||||
|
||||
@action
|
||||
loadMore() {
|
||||
if (this.loadingMore) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
this.set("loadingMore", true);
|
||||
|
||||
return this.model
|
||||
.loadMore()
|
||||
.then(response => this._processLoadResponse(response))
|
||||
.catch(() => this._bookmarksListDenied())
|
||||
.finally(() => this.set("loadingMore", false));
|
||||
},
|
||||
|
||||
_bookmarksListDenied() {
|
||||
this.set("noResultsHelp", I18n.t("bookmarks.list_permission_denied"));
|
||||
},
|
||||
|
||||
_processLoadResponse(response) {
|
||||
if (!response) {
|
||||
this._bookmarksListDenied();
|
||||
return;
|
||||
}
|
||||
|
||||
if (response.no_results_help) {
|
||||
this.set("noResultsHelp", response.no_results_help);
|
||||
return;
|
||||
}
|
||||
|
||||
response = response.user_bookmark_list;
|
||||
this.model.more_bookmarks_url = response.more_bookmarks_url;
|
||||
|
||||
if (response && response.bookmarks) {
|
||||
let bookmarks = [];
|
||||
response.bookmarks.forEach(bookmark => {
|
||||
bookmarks.push(Bookmark.create(bookmark));
|
||||
});
|
||||
this.content.pushObjects(bookmarks);
|
||||
}
|
||||
},
|
||||
|
||||
actions: {
|
||||
removeBookmark(bookmark) {
|
||||
bootbox.confirm(I18n.t("bookmarks.confirm_delete"), result => {
|
||||
if (result) {
|
||||
return bookmark.destroy().then(() => this.loadItems());
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
editBookmark(bookmark) {
|
||||
let controller = showModal("bookmark", {
|
||||
model: {
|
||||
postId: bookmark.post_id,
|
||||
id: bookmark.id,
|
||||
reminderAt: bookmark.reminder_at,
|
||||
name: bookmark.name
|
||||
},
|
||||
title: "post.bookmarks.edit",
|
||||
modalClass: "bookmark-with-reminder"
|
||||
});
|
||||
controller.setProperties({
|
||||
afterSave: () => this.loadItems()
|
||||
});
|
||||
},
|
||||
|
||||
loadMore() {
|
||||
if (this.loadingMore) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
this.set("loadingMore", true);
|
||||
|
||||
return this.model
|
||||
.loadMore()
|
||||
.then(response => this.processLoadResponse(response))
|
||||
.catch(() => {
|
||||
this.set("noResultsHelp", I18n.t("bookmarks.list_permission_denied"));
|
||||
})
|
||||
.finally(() =>
|
||||
this.setProperties({
|
||||
loadingMore: false
|
||||
})
|
||||
);
|
||||
if (response.bookmarks) {
|
||||
this.content.pushObjects(
|
||||
response.bookmarks.map(bookmark => Bookmark.create(bookmark))
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user