FIX: Correctly shows no bookmark message (#9548)
This commit is contained in:
parent
2c6d6dfd05
commit
ad978b93ab
|
@ -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,28 +35,10 @@ 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;
|
||||
|
||||
if (response && response.no_results_help) {
|
||||
this.set("noResultsHelp", response.no_results_help);
|
||||
}
|
||||
|
||||
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: {
|
||||
@action
|
||||
removeBookmark(bookmark) {
|
||||
bootbox.confirm(I18n.t("bookmarks.confirm_delete"), result => {
|
||||
if (result) {
|
||||
|
@ -68,6 +47,7 @@ export default Controller.extend({
|
|||
});
|
||||
},
|
||||
|
||||
@action
|
||||
editBookmark(bookmark) {
|
||||
let controller = showModal("bookmark", {
|
||||
model: {
|
||||
|
@ -84,22 +64,42 @@ export default Controller.extend({
|
|||
});
|
||||
},
|
||||
|
||||
@action
|
||||
loadMore() {
|
||||
if (this.loadingMore) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
this.set("loadingMore", true);
|
||||
|
||||
return this.model
|
||||
.loadMore()
|
||||
.then(response => this.processLoadResponse(response))
|
||||
.catch(() => {
|
||||
.then(response => this._processLoadResponse(response))
|
||||
.catch(() => this._bookmarksListDenied())
|
||||
.finally(() => this.set("loadingMore", false));
|
||||
},
|
||||
|
||||
_bookmarksListDenied() {
|
||||
this.set("noResultsHelp", I18n.t("bookmarks.list_permission_denied"));
|
||||
})
|
||||
.finally(() =>
|
||||
this.setProperties({
|
||||
loadingMore: false
|
||||
})
|
||||
},
|
||||
|
||||
_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.bookmarks) {
|
||||
this.content.pushObjects(
|
||||
response.bookmarks.map(bookmark => Bookmark.create(bookmark))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
import { acceptance } from "helpers/qunit-helpers";
|
||||
import selectKit from "helpers/select-kit-helper";
|
||||
import pretender from "helpers/create-pretender";
|
||||
|
||||
acceptance("User's bookmarks", {
|
||||
loggedIn: true,
|
||||
|
||||
beforeEach() {
|
||||
pretender.delete("/bookmarks/576", () => [
|
||||
200,
|
||||
{ "Content-Type": "application/json" },
|
||||
{}
|
||||
]);
|
||||
}
|
||||
});
|
||||
|
||||
test("listing user bookmarks", async assert => {
|
||||
await visit("/u/eviltrout/activity/bookmarks-with-reminders");
|
||||
|
||||
assert.ok(find(".bookmark-list-item").length);
|
||||
});
|
||||
|
||||
test("removing a bookmark", async assert => {
|
||||
await visit("/u/eviltrout/activity/bookmarks-with-reminders");
|
||||
|
||||
const dropdown = selectKit(".bookmark-actions-dropdown");
|
||||
await dropdown.expand();
|
||||
await dropdown.selectRowByValue("remove");
|
||||
|
||||
assert.ok(exists(".bootbox.modal"));
|
||||
|
||||
await click(".bootbox.modal .btn-primary");
|
||||
});
|
||||
|
||||
test("listing users bookmarks - no bookmarks", async assert => {
|
||||
pretender.get("/u/eviltrout/bookmarks.json", () => [
|
||||
200,
|
||||
{
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
{
|
||||
bookmarks: [],
|
||||
no_results_help: "no bookmarks"
|
||||
}
|
||||
]);
|
||||
|
||||
await visit("/u/eviltrout/activity/bookmarks-with-reminders");
|
||||
|
||||
assert.equal(find(".alert.alert-info").text(), "no bookmarks");
|
||||
});
|
Loading…
Reference in New Issue