mirror of https://github.com/zulip/zulip.git
list_render: Fix broken reversing operation.
This commit fixes an issue where when you click on the sort button of a table twice, reversing stops. The problem is we are checking the truthness of meta.sorting_function instead of just the function argument sorting_function. This commit extract the reverse operation out of sort() to unclutter the logic.
This commit is contained in:
parent
d86299309a
commit
3d7b9a1349
|
@ -179,6 +179,12 @@ var list_render = (function () {
|
|||
return this;
|
||||
},
|
||||
|
||||
reverse: function () {
|
||||
meta.filtered_list.reverse();
|
||||
prototype.init();
|
||||
return this;
|
||||
},
|
||||
|
||||
// the sorting function is either the function or string that calls the
|
||||
// function to sort the list by. The prop is used for generic functions
|
||||
// that can be called to sort with a particular prop.
|
||||
|
@ -188,7 +194,7 @@ var list_render = (function () {
|
|||
|
||||
// `do_not_display` will signal to not update the DOM, likely because in
|
||||
// the next function it will be updated in the DOM.
|
||||
sort: function (sorting_function, prop, map, do_not_display, reverse) {
|
||||
sort: function (sorting_function, prop, do_not_display) {
|
||||
meta.prop = prop;
|
||||
|
||||
if (typeof sorting_function === "function") {
|
||||
|
@ -208,11 +214,6 @@ var list_render = (function () {
|
|||
meta.filtered_list = meta.filtered_list.sort(meta.sorting_function);
|
||||
}
|
||||
|
||||
if (reverse) {
|
||||
// simple mutable array reversal.
|
||||
meta.filtered_list.reverse();
|
||||
}
|
||||
|
||||
if (!do_not_display) {
|
||||
// clear and re-initialize the list with the newly filtered subset
|
||||
// of items.
|
||||
|
@ -274,7 +275,7 @@ var list_render = (function () {
|
|||
// it will then also not run an update in the DOM (because we
|
||||
// pass `true`), because it will update regardless below at
|
||||
// `prototype.init()`.
|
||||
prototype.sort(undefined, meta.prop, undefined, true);
|
||||
prototype.sort(undefined, meta.prop, true);
|
||||
meta.filter_list(value, opts.filter.callback);
|
||||
|
||||
// clear and re-initialize the list with the newly filtered subset
|
||||
|
@ -376,7 +377,7 @@ var list_render = (function () {
|
|||
$this.removeClass("descend");
|
||||
}
|
||||
|
||||
list.sort(undefined, undefined, undefined, undefined, true);
|
||||
list.reverse();
|
||||
// Table has already been sorted by this property; do not re-sort.
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue