History

Sanity-check decaffeinate app.views.Notif

Simon Legner committed 2 years ago

Commit 1efb7941 parent 9073fa25 files · +37 −96Browse files

Unified · Split

5 files
  1. assets/javascripts/views/misc/news.js +12 −27
  2. assets/javascripts/views/misc/notice.js +2 −12
  3. assets/javascripts/views/misc/notif.js +9 −18
  4. assets/javascripts/views/misc/tip.js +2 −12
  5. assets/javascripts/views/misc/updates.js +12 −27
assets/javascripts/views/misc/news.js+12−27
@@ -1,23 +1,11 @@
1−// TODO: This file was created by bulk-decaffeinate.
2−// Sanity-check the conversion and remove this comment.
3−/*
4− * decaffeinate suggestions:
5− * DS101: Remove unnecessary use of Array.from
6− * DS102: Remove unnecessary code created because of implicit returns
7− * DS205: Consider reworking code to avoid use of IIFEs
8− * DS206: Consider reworking classes to avoid initClass
9− * Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
10− */
111 //= require views/misc/notif
122
133 app.views.News = class News extends app.views.Notif {
14− static initClass() {
15− this.className += " _notif-news";
4+ static className = "_notif _notif-news";
165
17− this.defautOptions = { autoHide: 30000 };
18− }
6+ static defaultOptions = { autoHide: 30000 };
197
20− init() {
8+ init0() {
219 this.unreadNews = this.getUnreadNews();
2210 if (this.unreadNews.length) {
2311 this.show();
@@ -30,21 +18,19 @@ app.views.News = class News extends app.views.Notif { · 6 unmodified lines
3018 }
3119
3220 getUnreadNews() {
33− let time;
34− if (!(time = this.getLastReadTime())) {
21+ let time = this.getLastReadTime();
22+ if (!time) {
3523 return [];
3624 }
3725
38− return (() => {
39− const result = [];
40− for (var news of Array.from(app.news)) {
41− if (new Date(news[0]).getTime() <= time) {
42− break;
43− }
44− result.push(news);
26+ const result = [];
27+ for (var news of app.news) {
28+ if (new Date(news[0]).getTime() <= time) {
29+ break;
4530 }
46− return result;
47− })();
31+ result.push(news);
32+ }
33+ return result;
4834 }
4935
5036 getLastNewsTime() {
@@ -59,4 +45,3 @@ app.views.News = class News extends app.views.Notif { · 8 unmodified lines
5945 app.settings.set("news", this.getLastNewsTime());
6046 }
6147 };
62−app.views.News.initClass();
assets/javascripts/views/misc/notice.js+2−12
@@ -1,15 +1,6 @@
1−// TODO: This file was created by bulk-decaffeinate.
2−// Sanity-check the conversion and remove this comment.
3−/*
4− * decaffeinate suggestions:
5− * DS206: Consider reworking classes to avoid initClass
6− * Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
7− */
81 app.views.Notice = class Notice extends app.View {
9− static initClass() {
10− this.className = "_notice";
11− this.attributes = { role: "alert" };
12− }
2+ static className = "_notice";
3+ static attributes = { role: "alert" };
134
145 constructor(type, ...args) {
156 super();
@@ -44,4 +35,3 @@ app.views.Notice = class Notice extends app.View { · 28 unmodified lines
4435 $.remove(this.el);
4536 }
4637 };
47−app.views.Notice.initClass();
assets/javascripts/views/misc/notif.js+9−18
@@ -1,29 +1,21 @@
1−// TODO: This file was created by bulk-decaffeinate.
2−// Sanity-check the conversion and remove this comment.
3−/*
4− * decaffeinate suggestions:
5− * DS206: Consider reworking classes to avoid initClass
6− * DS207: Consider shorter variations of null checks
7− * Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
8− */
91 app.views.Notif = class Notif extends app.View {
10− static initClass() {
11− this.className = "_notif";
12− this.activeClass = "_in";
13− this.attributes = { role: "alert" };
2+ static className = "_notif";
3+ static activeClass = "_in";
4+ static attributes = { role: "alert" };
145
15− this.defaultOptions = { autoHide: 15000 };
6+ static defaultOptions = { autoHide: 15000 };
167
17− this.events = { click: "onClick" };
18− }
8+ static events = { click: "onClick" };
199
2010 constructor(type, options) {
2111 super();
2212 this.type = type;
2313 this.options = $.extend({}, this.constructor.defaultOptions, options || {});
14+ this.init0(); // needs this.options
15+ this.refreshElements();
2416 }
2517
26− init() {
18+ init0() {
2719 this.show();
2820 }
2921
@@ -55,7 +47,7 @@ app.views.Notif = class Notif extends app.View { · 25 unmodified lines
5547 }
5648
5749 position() {
58− const notifications = $$(`.${app.views.Notif.className}`);
50+ const notifications = $$(`.${Notif.className}`);
5951 if (notifications.length) {
6052 const lastNotif = notifications[notifications.length - 1];
6153 this.el.style.top =
@@ -77,4 +69,3 @@ app.views.Notif = class Notif extends app.View { · 15 unmodified lines
7769 }
7870 }
7971 };
80−app.views.Notif.initClass();
assets/javascripts/views/misc/tip.js+2−12
@@ -1,21 +1,11 @@
1−// TODO: This file was created by bulk-decaffeinate.
2−// Sanity-check the conversion and remove this comment.
3−/*
4− * decaffeinate suggestions:
5− * DS206: Consider reworking classes to avoid initClass
6− * Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
7− */
81 //= require views/misc/notif
92
103 app.views.Tip = class Tip extends app.views.Notif {
11− static initClass() {
12− this.className = "_notif _notif-tip";
4+ static className = "_notif _notif-tip";
135
14− this.defautOptions = { autoHide: false };
15− }
6+ static defautOptions = { autoHide: false };
167
178 render() {
189 this.html(this.tmpl(`tip${this.type}`));
1910 }
2011 };
21−app.views.Tip.initClass();
assets/javascripts/views/misc/updates.js+12−27
@@ -1,23 +1,11 @@
1−// TODO: This file was created by bulk-decaffeinate.
2−// Sanity-check the conversion and remove this comment.
3−/*
4− * decaffeinate suggestions:
5− * DS101: Remove unnecessary use of Array.from
6− * DS102: Remove unnecessary code created because of implicit returns
7− * DS205: Consider reworking code to avoid use of IIFEs
8− * DS206: Consider reworking classes to avoid initClass
9− * Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
10− */
111 //= require views/misc/notif
122
133 app.views.Updates = class Updates extends app.views.Notif {
14− static initClass() {
15− this.className += " _notif-news";
4+ static className = "_notif _notif-news";
165
17− this.defautOptions = { autoHide: 30000 };
18− }
6+ static defautOptions = { autoHide: 30000 };
197
20− init() {
8+ init0() {
219 this.lastUpdateTime = this.getLastUpdateTime();
2210 this.updatedDocs = this.getUpdatedDocs();
2311 this.updatedDisabledDocs = this.getUpdatedDisabledDocs();
@@ -46,18 +34,16 @@ app.views.Updates = class Updates extends app.views.Notif { · 22 unmodified lines
4634 if (!this.lastUpdateTime) {
4735 return [];
4836 }
49− return (() => {
50− const result = [];
51− for (var doc of Array.from(app.disabledDocs.all())) {
52− if (
53− doc.mtime > this.lastUpdateTime &&
54− app.docs.findBy("slug_without_version", doc.slug_without_version)
55− ) {
56− result.push(doc);
57− }
37+ const result = [];
38+ for (var doc of Array.from(app.disabledDocs.all())) {
39+ if (
40+ doc.mtime > this.lastUpdateTime &&
41+ app.docs.findBy("slug_without_version", doc.slug_without_version)
42+ ) {
43+ result.push(doc);
5844 }
59− return result;
60− })();
45+ }
46+ return result;
6147 }
6248
6349 getLastUpdateTime() {
@@ -73,4 +59,3 @@ app.views.Updates = class Updates extends app.views.Notif { · 9 unmodified lines
7359 );
7460 }
7561 };
76−app.views.Updates.initClass();