From fd3c3fa565875e9bd52c055293d5b0ed28244487 Mon Sep 17 00:00:00 2001 From: Jarek Radosz Date: Wed, 24 Jan 2024 15:59:44 +0100 Subject: [PATCH] DEV: Use `service:` lookups instead of `:main` (#25402) where applicable --- app/assets/javascripts/discourse/app/lib/url.js | 10 ++++------ .../javascripts/discourse/initializers/checklist.js | 2 +- .../assets/javascripts/initializers/lazy-videos.js | 2 +- .../javascripts/initializers/inline-footnotes.js | 2 +- .../discourse/initializers/extend-for-poll.js | 2 +- .../assets/javascripts/initializers/spoiler-alert.js | 2 +- 6 files changed, 9 insertions(+), 11 deletions(-) diff --git a/app/assets/javascripts/discourse/app/lib/url.js b/app/assets/javascripts/discourse/app/lib/url.js index fd799a1e54d..a47edc3710b 100644 --- a/app/assets/javascripts/discourse/app/lib/url.js +++ b/app/assets/javascripts/discourse/app/lib/url.js @@ -160,12 +160,12 @@ const DiscourseURL = EmberObject.extend({ replaceState(path) { if (path.startsWith("#")) { - path = this.router.currentURL.replace(/#.*$/, "") + path; + path = this.routerService.currentURL.replace(/#.*$/, "") + path; } path = withoutPrefix(path); - if (this.router.currentURL !== path) { + if (this.routerService.currentURL !== path) { // Always use replaceState in the next runloop to prevent weird routes changing // while URLs are loading. For example, while a topic loads it sets `currentPost` // which triggers a replaceState even though the topic hasn't fully loaded yet! @@ -228,7 +228,7 @@ const DiscourseURL = EmberObject.extend({ return this.replaceState(path); } - const oldPath = this.router.currentURL; + const oldPath = this.routerService.currentURL; path = path.replace(/(https?\:)?\/\/[^\/]+/, ""); @@ -415,8 +415,6 @@ const DiscourseURL = EmberObject.extend({ handleURL(path, opts) { opts = opts || {}; - const router = this.router; - if (opts.replaceURL) { this.replaceState(path); } @@ -429,7 +427,7 @@ const DiscourseURL = EmberObject.extend({ elementId = split[1]; } - const transition = router.transitionTo(path); + const transition = this.routerService.transitionTo(path); transition._discourse_intercepted = true; transition._discourse_anchor = elementId; diff --git a/plugins/checklist/assets/javascripts/discourse/initializers/checklist.js b/plugins/checklist/assets/javascripts/discourse/initializers/checklist.js index 8e21eb5ef23..a9dc891ae0d 100644 --- a/plugins/checklist/assets/javascripts/discourse/initializers/checklist.js +++ b/plugins/checklist/assets/javascripts/discourse/initializers/checklist.js @@ -4,7 +4,7 @@ import { iconHTML } from "discourse-common/lib/icon-library"; import I18n from "discourse-i18n"; function initializePlugin(api) { - const siteSettings = api.container.lookup("site-settings:main"); + const siteSettings = api.container.lookup("service:site-settings"); if (siteSettings.checklist_enabled) { api.decorateCookedElement(checklistSyntax); diff --git a/plugins/discourse-lazy-videos/assets/javascripts/initializers/lazy-videos.js b/plugins/discourse-lazy-videos/assets/javascripts/initializers/lazy-videos.js index bd975b1ded0..3705ec38c69 100644 --- a/plugins/discourse-lazy-videos/assets/javascripts/initializers/lazy-videos.js +++ b/plugins/discourse-lazy-videos/assets/javascripts/initializers/lazy-videos.js @@ -12,7 +12,7 @@ function initLazyEmbed(api) { const lazyContainers = cooked.querySelectorAll(".lazy-video-container"); lazyContainers.forEach((container) => { - const siteSettings = api.container.lookup("site-settings:main"); + const siteSettings = api.container.lookup("service:site-settings"); const videoAttributes = getVideoAttributes(container); if (siteSettings[`lazy_${videoAttributes.providerName}_enabled`]) { diff --git a/plugins/footnote/assets/javascripts/initializers/inline-footnotes.js b/plugins/footnote/assets/javascripts/initializers/inline-footnotes.js index e910e1f4a83..1d209a637f7 100644 --- a/plugins/footnote/assets/javascripts/initializers/inline-footnotes.js +++ b/plugins/footnote/assets/javascripts/initializers/inline-footnotes.js @@ -100,7 +100,7 @@ export default { name: "inline-footnotes", initialize(container) { - if (!container.lookup("site-settings:main").display_footnotes_inline) { + if (!container.lookup("service:site-settings").display_footnotes_inline) { return; } diff --git a/plugins/poll/assets/javascripts/discourse/initializers/extend-for-poll.js b/plugins/poll/assets/javascripts/discourse/initializers/extend-for-poll.js index 55812acb4f4..1ec9a0f8ace 100644 --- a/plugins/poll/assets/javascripts/discourse/initializers/extend-for-poll.js +++ b/plugins/poll/assets/javascripts/discourse/initializers/extend-for-poll.js @@ -134,7 +134,7 @@ function initializePolls(api) { }); api.cleanupStream(cleanUpPolls); - const siteSettings = api.container.lookup("site-settings:main"); + const siteSettings = api.container.lookup("service:site-settings"); if (siteSettings.poll_enabled) { api.addSearchSuggestion("in:polls"); } diff --git a/plugins/spoiler-alert/assets/javascripts/initializers/spoiler-alert.js b/plugins/spoiler-alert/assets/javascripts/initializers/spoiler-alert.js index 6b246c22e4c..4e51bf88751 100644 --- a/plugins/spoiler-alert/assets/javascripts/initializers/spoiler-alert.js +++ b/plugins/spoiler-alert/assets/javascripts/initializers/spoiler-alert.js @@ -49,7 +49,7 @@ export default { name: "spoiler-alert", initialize(container) { - const siteSettings = container.lookup("site-settings:main"); + const siteSettings = container.lookup("service:site-settings"); if (siteSettings.spoiler_enabled) { withPluginApi("1.15.0", initializeSpoiler);