From 1efb79404f9bd0421503ca6fafe693afd019a6ce Mon Sep 17 00:00:00 2001 From: Simon Legner Date: Sat, 6 Jan 2024 15:09:47 +0100 Subject: [PATCH] Sanity-check decaffeinate app.views.Notif --- assets/javascripts/views/misc/news.js | 39 ++++++++---------------- assets/javascripts/views/misc/notice.js | 14 ++------- assets/javascripts/views/misc/notif.js | 27 ++++++---------- assets/javascripts/views/misc/tip.js | 14 ++------- assets/javascripts/views/misc/updates.js | 39 ++++++++---------------- 5 files changed, 37 insertions(+), 96 deletions(-) diff --git a/assets/javascripts/views/misc/news.js b/assets/javascripts/views/misc/news.js index 81d84218..339cc386 100644 --- a/assets/javascripts/views/misc/news.js +++ b/assets/javascripts/views/misc/news.js @@ -1,23 +1,11 @@ -// TODO: This file was created by bulk-decaffeinate. -// Sanity-check the conversion and remove this comment. -/* - * decaffeinate suggestions: - * DS101: Remove unnecessary use of Array.from - * DS102: Remove unnecessary code created because of implicit returns - * DS205: Consider reworking code to avoid use of IIFEs - * DS206: Consider reworking classes to avoid initClass - * Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md - */ //= require views/misc/notif app.views.News = class News extends app.views.Notif { - static initClass() { - this.className += " _notif-news"; + static className = "_notif _notif-news"; - this.defautOptions = { autoHide: 30000 }; - } + static defaultOptions = { autoHide: 30000 }; - init() { + init0() { this.unreadNews = this.getUnreadNews(); if (this.unreadNews.length) { this.show(); @@ -30,21 +18,19 @@ app.views.News = class News extends app.views.Notif { } getUnreadNews() { - let time; - if (!(time = this.getLastReadTime())) { + let time = this.getLastReadTime(); + if (!time) { return []; } - return (() => { - const result = []; - for (var news of Array.from(app.news)) { - if (new Date(news[0]).getTime() <= time) { - break; - } - result.push(news); + const result = []; + for (var news of app.news) { + if (new Date(news[0]).getTime() <= time) { + break; } - return result; - })(); + result.push(news); + } + return result; } getLastNewsTime() { @@ -59,4 +45,3 @@ app.views.News = class News extends app.views.Notif { app.settings.set("news", this.getLastNewsTime()); } }; -app.views.News.initClass(); diff --git a/assets/javascripts/views/misc/notice.js b/assets/javascripts/views/misc/notice.js index 74a4aae3..13707337 100644 --- a/assets/javascripts/views/misc/notice.js +++ b/assets/javascripts/views/misc/notice.js @@ -1,15 +1,6 @@ -// TODO: This file was created by bulk-decaffeinate. -// Sanity-check the conversion and remove this comment. -/* - * decaffeinate suggestions: - * DS206: Consider reworking classes to avoid initClass - * Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md - */ app.views.Notice = class Notice extends app.View { - static initClass() { - this.className = "_notice"; - this.attributes = { role: "alert" }; - } + static className = "_notice"; + static attributes = { role: "alert" }; constructor(type, ...args) { super(); @@ -44,4 +35,3 @@ app.views.Notice = class Notice extends app.View { $.remove(this.el); } }; -app.views.Notice.initClass(); diff --git a/assets/javascripts/views/misc/notif.js b/assets/javascripts/views/misc/notif.js index d8aa5002..03c2c261 100644 --- a/assets/javascripts/views/misc/notif.js +++ b/assets/javascripts/views/misc/notif.js @@ -1,29 +1,21 @@ -// TODO: This file was created by bulk-decaffeinate. -// Sanity-check the conversion and remove this comment. -/* - * decaffeinate suggestions: - * DS206: Consider reworking classes to avoid initClass - * DS207: Consider shorter variations of null checks - * Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md - */ app.views.Notif = class Notif extends app.View { - static initClass() { - this.className = "_notif"; - this.activeClass = "_in"; - this.attributes = { role: "alert" }; + static className = "_notif"; + static activeClass = "_in"; + static attributes = { role: "alert" }; - this.defaultOptions = { autoHide: 15000 }; + static defaultOptions = { autoHide: 15000 }; - this.events = { click: "onClick" }; - } + static events = { click: "onClick" }; constructor(type, options) { super(); this.type = type; this.options = $.extend({}, this.constructor.defaultOptions, options || {}); + this.init0(); // needs this.options + this.refreshElements(); } - init() { + init0() { this.show(); } @@ -55,7 +47,7 @@ app.views.Notif = class Notif extends app.View { } position() { - const notifications = $$(`.${app.views.Notif.className}`); + const notifications = $$(`.${Notif.className}`); if (notifications.length) { const lastNotif = notifications[notifications.length - 1]; this.el.style.top = @@ -77,4 +69,3 @@ app.views.Notif = class Notif extends app.View { } } }; -app.views.Notif.initClass(); diff --git a/assets/javascripts/views/misc/tip.js b/assets/javascripts/views/misc/tip.js index 401cf6e3..c9b4cf89 100644 --- a/assets/javascripts/views/misc/tip.js +++ b/assets/javascripts/views/misc/tip.js @@ -1,21 +1,11 @@ -// TODO: This file was created by bulk-decaffeinate. -// Sanity-check the conversion and remove this comment. -/* - * decaffeinate suggestions: - * DS206: Consider reworking classes to avoid initClass - * Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md - */ //= require views/misc/notif app.views.Tip = class Tip extends app.views.Notif { - static initClass() { - this.className = "_notif _notif-tip"; + static className = "_notif _notif-tip"; - this.defautOptions = { autoHide: false }; - } + static defautOptions = { autoHide: false }; render() { this.html(this.tmpl(`tip${this.type}`)); } }; -app.views.Tip.initClass(); diff --git a/assets/javascripts/views/misc/updates.js b/assets/javascripts/views/misc/updates.js index 508d5915..480f8599 100644 --- a/assets/javascripts/views/misc/updates.js +++ b/assets/javascripts/views/misc/updates.js @@ -1,23 +1,11 @@ -// TODO: This file was created by bulk-decaffeinate. -// Sanity-check the conversion and remove this comment. -/* - * decaffeinate suggestions: - * DS101: Remove unnecessary use of Array.from - * DS102: Remove unnecessary code created because of implicit returns - * DS205: Consider reworking code to avoid use of IIFEs - * DS206: Consider reworking classes to avoid initClass - * Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md - */ //= require views/misc/notif app.views.Updates = class Updates extends app.views.Notif { - static initClass() { - this.className += " _notif-news"; + static className = "_notif _notif-news"; - this.defautOptions = { autoHide: 30000 }; - } + static defautOptions = { autoHide: 30000 }; - init() { + init0() { this.lastUpdateTime = this.getLastUpdateTime(); this.updatedDocs = this.getUpdatedDocs(); this.updatedDisabledDocs = this.getUpdatedDisabledDocs(); @@ -46,18 +34,16 @@ app.views.Updates = class Updates extends app.views.Notif { if (!this.lastUpdateTime) { return []; } - return (() => { - const result = []; - for (var doc of Array.from(app.disabledDocs.all())) { - if ( - doc.mtime > this.lastUpdateTime && - app.docs.findBy("slug_without_version", doc.slug_without_version) - ) { - result.push(doc); - } + const result = []; + for (var doc of Array.from(app.disabledDocs.all())) { + if ( + doc.mtime > this.lastUpdateTime && + app.docs.findBy("slug_without_version", doc.slug_without_version) + ) { + result.push(doc); } - return result; - })(); + } + return result; } getLastUpdateTime() { @@ -73,4 +59,3 @@ app.views.Updates = class Updates extends app.views.Notif { ); } }; -app.views.Updates.initClass();