FEATURE: improve blank page syndrome (#187)

FEATURE: improve blank page syndrome (#187)

diff --git a/assets/javascripts/discourse-assign/controllers/user-activity-assigned.js.es6 b/assets/javascripts/discourse-assign/controllers/user-activity-assigned.js.es6
index ad09c5c..d32fc27 100644
--- a/assets/javascripts/discourse-assign/controllers/user-activity-assigned.js.es6
+++ b/assets/javascripts/discourse-assign/controllers/user-activity-assigned.js.es6
@@ -5,6 +5,9 @@ import { INPUT_DELAY } from "discourse-common/config/environment";
 import { inject as controller } from "@ember/controller";
 import { inject as service } from "@ember/service";
 import { action } from "@ember/object";
+import getURL from "discourse-common/lib/get-url";
+import { iconHTML } from "discourse-common/lib/icon-library";
+import I18n from "I18n";
 
 export default UserTopicsList.extend({
   user: controller(),
@@ -19,6 +22,19 @@ export default UserTopicsList.extend({
     return search;
   },
 
+  @discourseComputed("model.topics.length", "search")
+  doesntHaveAssignments(topicsLength, search) {
+    return !search && !topicsLength;
+  },
+
+  @discourseComputed
+  emptyStateBody() {
+    return I18n.t("user.no_assignments_body", {
+      preferencesUrl: getURL("/my/preferences/notifications"),
+      icon: iconHTML("user-plus"),
+    }).htmlSafe();
+  },
+
   _setSearchTerm(searchTerm) {
     this.set("search", searchTerm);
     this.refreshModel();
diff --git a/assets/javascripts/discourse/templates/user-assigned-topics.hbs b/assets/javascripts/discourse/templates/user-assigned-topics.hbs
index 98d6e3d..aef4428 100644
--- a/assets/javascripts/discourse/templates/user-assigned-topics.hbs
+++ b/assets/javascripts/discourse/templates/user-assigned-topics.hbs
@@ -1,32 +1,42 @@
-<div class="topic-search-div">
-  <div class="form-horizontal bookmark-search-form">
-    {{input
-      class="no-blur"
-      value=searchTerm
-      placeholder=(i18n "discourse_assign.topic_search_placeholder")
-      input=(action "onChangeFilter" value="target.value")
-      autocomplete="discourse"
-    }}
+{{#if doesntHaveAssignments}}
+  <div class="empty-state">
+    <span class="empty-state-title">{{i18n "user.no_assignments_title"}}</span>
+    <div class="empty-state-body">
+      <p>{{emptyStateBody}}</p>
+    </div>
+  </div>
+{{else}}
+  <div class="topic-search-div">
+    <div class="form-horizontal bookmark-search-form">
+      {{input
+        class="no-blur"
+        value=searchTerm
+        placeholder=(i18n "discourse_assign.topic_search_placeholder")
+        input=(action "onChangeFilter" value="target.value")
+        autocomplete="discourse"
+      }}
+    </div>
   </div>
-</div>
 
-{{#load-more class="paginated-topics-list" selector=".paginated-topics-list .topic-list tr" action=(action "loadMore")}}
-  {{basic-assigned-topic-list
-    topicList=model
-    hideCategory=hideCategory
-    showPosters=showPosters
-    bulkSelectEnabled=bulkSelectEnabled
-    selected=selected
-    hasIncoming=hasIncoming
-    incomingCount=incomingCount
-    showInserted=(action "showInserted")
-    tagsForUser=tagsForUser
-    changeSort=(action "changeSort")
-    unassign=(action "unassign")
-    reassign=(action "reassign")
-    onScroll=saveScrollPosition
-    scrollOnLoad=true
-  }}
+  {{#load-more class="paginated-topics-list" selector=".paginated-topics-list .topic-list tr" action=(action "loadMore")}}
+    {{basic-assigned-topic-list
+      topicList=model
+      hideCategory=hideCategory
+      showPosters=showPosters
+      bulkSelectEnabled=bulkSelectEnabled
+      selected=selected
+      hasIncoming=hasIncoming
+      incomingCount=incomingCount
+      showInserted=(action "showInserted")
+      tagsForUser=tagsForUser
+      changeSort=(action "changeSort")
+      unassign=(action "unassign")
+      reassign=(action "reassign")
+      onScroll=saveScrollPosition
+      scrollOnLoad=true
+    }}
+
+    {{conditional-loading-spinner condition=model.loadingMore}}
+  {{/load-more}}
+{{/if}}
 
-  {{conditional-loading-spinner condition=model.loadingMore}}
-{{/load-more}}
diff --git a/test/javascripts/acceptance/assign-disabled-test.js.es6 b/test/javascripts/acceptance/assign-disabled-test.js.es6
index 368d5f1..57bb585 100644
--- a/test/javascripts/acceptance/assign-disabled-test.js.es6
+++ b/test/javascripts/acceptance/assign-disabled-test.js.es6
@@ -7,7 +7,7 @@ import { visit } from "@ember/test-helpers";
 import { clearTopicFooterButtons } from "discourse/lib/register-topic-footer-button";
 import { test } from "qunit";
 
-acceptance("Assign disabled mobile", function (needs) {
+acceptance("Discourse Assign | Assign disabled mobile", function (needs) {
   needs.user();
   needs.mobileView();
   needs.settings({ assign_enabled: false });
diff --git a/test/javascripts/acceptance/un-assign-from-list-test.js.es6 b/test/javascripts/acceptance/un-assign-from-list-test.js.es6
deleted file mode 100644
index fc8ba34..0000000
--- a/test/javascripts/acceptance/un-assign-from-list-test.js.es6
+++ /dev/null
@@ -1,25 +0,0 @@
-import selectKit from "discourse/tests/helpers/select-kit-helper";
-import { acceptance, count } from "discourse/tests/helpers/qunit-helpers";
-import { visit } from "@ember/test-helpers";
-import AssignedTopics from "../fixtures/assigned-topics-fixtures";
-import { test } from "qunit";
-
-acceptance("Discourse Assign | UnAssign/Re-assign from the topics list", function (needs) {
-  needs.user();
-  needs.settings({ assign_enabled: true, assigns_user_url_path: "/" });
-  needs.pretender((server, helper) => {
-    const messagesPath = "/topics/messages-assigned/eviltrout.json";
-    const assigns = AssignedTopics[messagesPath];
-    server.get(messagesPath, () => helper.response(assigns));
-  });
-
-  test("Unassign/Re-assign options are visible", async (assert) => {
-    const options = selectKit(".assign-actions-dropdown");
-
-    await visit("/u/eviltrout/activity/assigned");
-    await options.expand();
-
-    assert.equal(count("li[data-value='unassign']"), 1);
-    assert.equal(count("li[data-value='reassign']"), 1);
-  });
-});
diff --git a/test/javascripts/acceptance/user-assignments-list.js.es6 b/test/javascripts/acceptance/user-assignments-list.js.es6
new file mode 100644
index 0000000..6d4f58d
--- /dev/null
+++ b/test/javascripts/acceptance/user-assignments-list.js.es6
@@ -0,0 +1,47 @@
+import selectKit from "discourse/tests/helpers/select-kit-helper";
+import {acceptance, count, exists} from "discourse/tests/helpers/qunit-helpers";
+import {visit} from "@ember/test-helpers";
+import AssignedTopics from "../fixtures/assigned-topics-fixtures";
+import {test} from "qunit";
+
+acceptance("Discourse Assign | UnAssign/Re-assign from the topics list", function (needs) {
+  needs.user();
+  needs.settings({ assign_enabled: true, assigns_user_url_path: "/" });
+  needs.pretender((server, helper) => {
+    const messagesPath = "/topics/messages-assigned/eviltrout.json";
+    const assigns = AssignedTopics[messagesPath];
+    server.get(messagesPath, () => helper.response(assigns));
+  });
+
+  test("Unassign/Re-assign options are visible", async (assert) => {
+    const options = selectKit(".assign-actions-dropdown");
+
+    await visit("/u/eviltrout/activity/assigned");
+    await options.expand();
+
+    assert.equal(count("li[data-value='unassign']"), 1);
+    assert.equal(count("li[data-value='reassign']"), 1);
+  });
+});
+
+acceptance("Discourse Assign | A user doesn't have assignments", function (needs) {
+  needs.user();
+  needs.settings({ assign_enabled: true, assigns_user_url_path: "/" });
+  needs.pretender((server, helper) => {
+    const assignments = AssignedTopics["/topics/messages-assigned/eviltrout.json"];
+    assignments.topic_list.topics = [];
+    server.get(
+      "/topics/messages-assigned/eviltrout.json",
+      () => helper.response(assignments));
+  });
+
+  test("It renders the empty state panel", async function (assert) {
+    await visit("/u/eviltrout/activity/assigned");
+    assert.ok(exists("div.empty-state"));
+  });
+

[... diff too long, it was truncated ...]

GitHub sha: 29d4b8fd5cfb311fcb33d1cc743ab0cc1cd92cdf

This commit appears in #187 which was approved by eviltrout. It was merged by AndrewPrigorshnev.