From bc839fb541e15b1405eb24499062898a47e8a9f0 Mon Sep 17 00:00:00 2001 From: Ben Gotow Date: Wed, 2 Dec 2015 11:43:37 -0800 Subject: [PATCH] fix(labels): Allow user to label as `spam` or `trash` from the dropdown Also fixes the sort ordering of standard labels in the category picker. Fixes #555 --- .../category-picker/lib/category-picker.cjsx | 14 ++++++++------ src/flux/stores/category-store.coffee | 18 +++++++++--------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/internal_packages/category-picker/lib/category-picker.cjsx b/internal_packages/category-picker/lib/category-picker.cjsx index 5a21c6b4f..4d2e065bc 100644 --- a/internal_packages/category-picker/lib/category-picker.cjsx +++ b/internal_packages/category-picker/lib/category-picker.cjsx @@ -252,9 +252,12 @@ class CategoryPicker extends React.Component @_account = AccountStore.current() return unless @_account - categories = CategoryStore.getStandardCategories() - .concat([{divider: true, id: "category-divider"}]) - .concat(CategoryStore.getUserCategories()) + if @_account.usesLabels() + categories = CategoryStore.getCategories() + else + categories = CategoryStore.getStandardCategories() + .concat([{divider: true, id: "category-divider"}]) + .concat(CategoryStore.getUserCategories()) usageCount = @_categoryUsageCount(props, categories) @@ -292,9 +295,8 @@ class CategoryPicker extends React.Component currentCategoryId = FocusedMailViewStore.mailView()?.categoryId() if @_account?.usesLabels() - hiddenCategories = ["all", "spam", "trash", "drafts", "sent"] - if allInInbox - hiddenCategories.push("inbox") + hiddenCategories = ["all", "drafts", "sent", "archive", "starred", "important"] + hiddenCategories.push("inbox") if allInInbox return false if category.divider else if @_account?.usesFolders() hiddenCategories = ["drafts", "sent"] diff --git a/src/flux/stores/category-store.coffee b/src/flux/stores/category-store.coffee index b12b73f08..3ad530679 100644 --- a/src/flux/stores/category-store.coffee +++ b/src/flux/stores/category-store.coffee @@ -144,13 +144,7 @@ class CategoryStore extends NylasStore return unless categoryClass DatabaseStore.findAll(categoryClass).where(categoryClass.attributes.accountId.equal(account.id)).then (categories=[]) => - @_categoryCache = {} - @_categoryCache[category.id] = category for category in categories - - # Compute user categories - userCategories = _.reject _.values(@_categoryCache), (cat) => - cat.name in @StandardCategoryNames or cat.name in @HiddenCategoryNames - userCategories = userCategories.sort (catA, catB) => + categories = categories.sort (catA, catB) -> nameA = catA.displayName nameB = catB.displayName @@ -161,10 +155,16 @@ class CategoryStore extends NylasStore nameA.localeCompare(nameB) - @_userCategories = _.compact(userCategories) + @_categoryCache = {} + for category in categories + @_categoryCache[category.id] = category + + # Compute user categories + @_userCategories = _.compact _.reject categories, (cat) => + cat.name in @StandardCategoryNames or cat.name in @HiddenCategoryNames # Compute hidden categories - @_hiddenCategories = _.filter _.values(@_categoryCache), (cat) => + @_hiddenCategories = _.filter categories, (cat) => cat.name in @HiddenCategoryNames # Compute standard categories