favgroups: fix add to favgroup not working.

Fix the Add to Favgroup button not working when the user only has 1
favgroup.
This commit is contained in:
evazion
2020-01-15 13:17:04 -06:00
parent 27bd94abec
commit 1ce628c31f

View File

@@ -1,3 +1,5 @@
import Rails from "@rails/ujs";
let FavoriteGroup = {};
FavoriteGroup.initialize_all = function() {
@@ -23,8 +25,9 @@ FavoriteGroup.initialize_add_to_favgroup_dialog = function() {
FavoriteGroup.open_favgroup_dialog = function(e) {
if ($(".add-to-favgroup").length === 1) {
// If the user only has one favorite group we don't need to ask which group to add the post to.
$(".add-to-favgroup").click();
} else if ($(".add-to-favgroup").length > 1) {
let favgroup = $(".add-to-favgroup").get(0);
Rails.fire(favgroup, "click");
} else {
$("#add-to-favgroup-dialog").dialog("open");
}
e.preventDefault();