From e062b94e7fbbc95df9d37892ffc53dc52aa81c4f Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Thu, 15 Oct 2020 19:26:05 +0200 Subject: [PATCH] REFACTOR: merges redirectTo implementation into one function (#10919) --- .../javascripts/discourse/app/lib/url.js | 20 ++++++------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/app/assets/javascripts/discourse/app/lib/url.js b/app/assets/javascripts/discourse/app/lib/url.js index 7f90a935703..360c7626752 100644 --- a/app/assets/javascripts/discourse/app/lib/url.js +++ b/app/assets/javascripts/discourse/app/lib/url.js @@ -12,11 +12,6 @@ import { setOwner } from "@ember/application"; const rewrites = []; const TOPIC_REGEXP = /\/t\/([^\/]+)\/(\d+)\/?(\d+)?/; -function redirectTo(url) { - document.location = url; - return true; -} - // We can add links here that have server side responses but not client side. const SERVER_SIDE_ONLY = [ /^\/assets\//, @@ -228,22 +223,18 @@ const DiscourseURL = EmberObject.extend({ } if (Session.currentProp("requiresRefresh")) { - return redirectTo(getURL(path)); + return this.redirectTo(getURL(path)); } const pathname = path.replace(/(https?\:)?\/\/[^\/]+/, ""); if (!this.isInternal(path)) { - return redirectTo(path); + return this.redirectTo(path); } - const serverSide = SERVER_SIDE_ONLY.some((r) => { - if (pathname.match(r)) { - return redirectTo(path); - } - }); - + const serverSide = SERVER_SIDE_ONLY.some((r) => pathname.match(r)); if (serverSide) { + this.redirectTo(path); return; } @@ -268,7 +259,7 @@ const DiscourseURL = EmberObject.extend({ userPath(currentUser.get("username_lower")) ); } else { - return redirectTo("/login-preferences"); + return this.redirectTo("/login-preferences"); } } @@ -316,6 +307,7 @@ const DiscourseURL = EmberObject.extend({ redirectTo(url) { window.location = getURL(url); + return true; }, /**