mirror of
https://github.com/zulip/zulip.git
synced 2025-11-06 15:03:34 +00:00
topic_list: Convert widget to an ES6 class TopicListWidget.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
committed by
Tim Abbott
parent
4517c48de2
commit
b900e38dc6
@@ -104,20 +104,23 @@ exports.spinner_li = () => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.widget = function (parent_elem, my_stream_id) {
|
class TopicListWidget {
|
||||||
const self = {};
|
prior_dom = undefined;
|
||||||
|
|
||||||
self.prior_dom = undefined;
|
constructor(parent_elem, my_stream_id) {
|
||||||
|
this.parent_elem = parent_elem;
|
||||||
|
this.my_stream_id = my_stream_id;
|
||||||
|
}
|
||||||
|
|
||||||
self.build_list = function (spinner) {
|
build_list(spinner) {
|
||||||
const list_info = topic_list_data.get_list_info(my_stream_id, zoomed);
|
const list_info = topic_list_data.get_list_info(this.my_stream_id, zoomed);
|
||||||
|
|
||||||
const num_possible_topics = list_info.num_possible_topics;
|
const num_possible_topics = list_info.num_possible_topics;
|
||||||
const more_topics_unreads = list_info.more_topics_unreads;
|
const more_topics_unreads = list_info.more_topics_unreads;
|
||||||
|
|
||||||
const is_showing_all_possible_topics =
|
const is_showing_all_possible_topics =
|
||||||
list_info.items.length === num_possible_topics &&
|
list_info.items.length === num_possible_topics &&
|
||||||
stream_topic_history.is_complete_for_stream_id(my_stream_id);
|
stream_topic_history.is_complete_for_stream_id(this.my_stream_id);
|
||||||
|
|
||||||
const attrs = [["class", "topic-list"]];
|
const attrs = [["class", "topic-list"]];
|
||||||
|
|
||||||
@@ -135,40 +138,37 @@ exports.widget = function (parent_elem, my_stream_id) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
return dom;
|
return dom;
|
||||||
};
|
|
||||||
|
|
||||||
self.get_parent = function () {
|
|
||||||
return parent_elem;
|
|
||||||
};
|
|
||||||
|
|
||||||
self.get_stream_id = function () {
|
|
||||||
return my_stream_id;
|
|
||||||
};
|
|
||||||
|
|
||||||
self.remove = function () {
|
|
||||||
parent_elem.find(".topic-list").remove();
|
|
||||||
self.prior_dom = undefined;
|
|
||||||
};
|
|
||||||
|
|
||||||
self.build = function (spinner) {
|
|
||||||
const new_dom = self.build_list(spinner);
|
|
||||||
|
|
||||||
function replace_content(html) {
|
|
||||||
self.remove();
|
|
||||||
parent_elem.append(html);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function find() {
|
get_parent() {
|
||||||
return parent_elem.find(".topic-list");
|
return this.parent_elem;
|
||||||
}
|
}
|
||||||
|
|
||||||
vdom.update(replace_content, find, new_dom, self.prior_dom);
|
get_stream_id() {
|
||||||
|
return this.my_stream_id;
|
||||||
|
}
|
||||||
|
|
||||||
self.prior_dom = new_dom;
|
remove() {
|
||||||
|
this.parent_elem.find(".topic-list").remove();
|
||||||
|
this.prior_dom = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
build(spinner) {
|
||||||
|
const new_dom = this.build_list(spinner);
|
||||||
|
|
||||||
|
const replace_content = (html) => {
|
||||||
|
this.remove();
|
||||||
|
this.parent_elem.append(html);
|
||||||
};
|
};
|
||||||
|
|
||||||
return self;
|
const find = () => this.parent_elem.find(".topic-list");
|
||||||
};
|
|
||||||
|
vdom.update(replace_content, find, new_dom, this.prior_dom);
|
||||||
|
|
||||||
|
this.prior_dom = new_dom;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
exports.TopicListWidget = TopicListWidget;
|
||||||
|
|
||||||
exports.active_stream_id = function () {
|
exports.active_stream_id = function () {
|
||||||
const stream_ids = Array.from(active_widgets.keys());
|
const stream_ids = Array.from(active_widgets.keys());
|
||||||
@@ -200,7 +200,7 @@ exports.rebuild = function (stream_li, stream_id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
exports.clear();
|
exports.clear();
|
||||||
const widget = exports.widget(stream_li, stream_id);
|
const widget = new TopicListWidget(stream_li, stream_id);
|
||||||
widget.build();
|
widget.build();
|
||||||
|
|
||||||
active_widgets.set(stream_id, widget);
|
active_widgets.set(stream_id, widget);
|
||||||
|
|||||||
Reference in New Issue
Block a user