From 3412201532615571cfe9e7d2a87b4f4f3508a859 Mon Sep 17 00:00:00 2001 From: Bill Thornton Date: Wed, 6 Apr 2022 17:31:54 -0400 Subject: [PATCH] Simplify url utils --- src/components/appRouter.js | 3 +-- src/scripts/clientUtils.js | 3 +-- src/scripts/editorsidebar.js | 4 ++-- src/scripts/site.js | 2 -- src/utils/url.ts | 26 ++++---------------------- 5 files changed, 8 insertions(+), 30 deletions(-) diff --git a/src/components/appRouter.js b/src/components/appRouter.js index 4a7224fe5e..ce10d6e93a 100644 --- a/src/components/appRouter.js +++ b/src/components/appRouter.js @@ -12,7 +12,6 @@ import Dashboard from '../scripts/clientUtils'; import ServerConnections from './ServerConnections'; import alert from './alert'; import reactControllerFactory from './reactControllerFactory'; -import { getWindowLocationSearch } from '../utils/url.ts'; class AppRouter { allRoutes = []; @@ -121,7 +120,7 @@ class AppRouter { const regexS = '[\\?&]' + name + '=([^&#]*)'; const regex = new RegExp(regexS, 'i'); - const results = regex.exec(url || getWindowLocationSearch()); + const results = regex.exec(url || window.location.search); if (results == null) { return ''; } else { diff --git a/src/scripts/clientUtils.js b/src/scripts/clientUtils.js index bc9e899490..6d4e3be683 100644 --- a/src/scripts/clientUtils.js +++ b/src/scripts/clientUtils.js @@ -10,7 +10,6 @@ import datetime from '../scripts/datetime'; import DirectoryBrowser from '../components/directorybrowser/directorybrowser'; import dialogHelper from '../components/dialogHelper/dialogHelper'; import itemIdentifier from '../components/itemidentifier/itemidentifier'; -import { getWindowLocationSearch } from '../utils/url.ts'; export function getCurrentUser() { return window.ApiClient.getCurrentUser(false); @@ -113,7 +112,7 @@ export function navigate(url, preserveQueryString) { throw new Error('url cannot be null or empty'); } - const queryString = getWindowLocationSearch(); + const queryString = window.location.search; if (preserveQueryString && queryString) { url += queryString; diff --git a/src/scripts/editorsidebar.js b/src/scripts/editorsidebar.js index 2861999974..220597d64e 100644 --- a/src/scripts/editorsidebar.js +++ b/src/scripts/editorsidebar.js @@ -300,9 +300,9 @@ import { getParameterByName } from '../utils/url.ts'; if (itemId) { return itemId; } - const url = window.location.hash || window.location.href; - return getParameterByName('id', url); + return getParameterByName('id'); } + let nodesToLoad = []; let selectedNodeId; $(document).on('itemsaved', '.metadataEditorPage', function (e, item) { diff --git a/src/scripts/site.js b/src/scripts/site.js index 7f8c4d751f..b346e7dcc7 100644 --- a/src/scripts/site.js +++ b/src/scripts/site.js @@ -41,8 +41,6 @@ import SyncPlayHtmlAudioPlayer from '../components/syncPlay/ui/players/HtmlAudio import { currentSettings } from './settings/userSettings'; import taskButton from './taskbutton'; -// TODO: Move this elsewhere - function loadCoreDictionary() { const languages = ['af', 'ar', 'be-by', 'bg-bg', 'bn_bd', 'ca', 'cs', 'da', 'de', 'el', 'en-gb', 'en-us', 'eo', 'es', 'es-419', 'es-ar', 'es_do', 'es-mx', 'fa', 'fi', 'fil', 'fr', 'fr-ca', 'gl', 'gsw', 'he', 'hi-in', 'hr', 'hu', 'id', 'it', 'ja', 'kk', 'ko', 'lt-lt', 'mr', 'ms', 'nb', 'nl', 'pl', 'pr', 'pt', 'pt-br', 'pt-pt', 'ro', 'ru', 'sk', 'sl-si', 'sq', 'sv', 'ta', 'th', 'tr', 'uk', 'ur_pk', 'vi', 'zh-cn', 'zh-hk', 'zh-tw']; const translations = languages.map(function (language) { diff --git a/src/utils/url.ts b/src/utils/url.ts index 836617e96c..637f22fed8 100644 --- a/src/utils/url.ts +++ b/src/utils/url.ts @@ -1,26 +1,8 @@ -export const getWindowLocationSearch = (win?: Window | null | undefined) => { - let search = (win || window).location.search; - - if (!search) { - const index = window.location.href.indexOf('?'); - - if (index != -1) { - search = window.location.href.substring(index); - } - } - - return search || ''; -}; - export const getParameterByName = (name: string, url?: string | null | undefined) => { - name = name.replace(/[[]/, '\\[').replace(/[\]]/, '\\]'); - const regexS = '[\\?&]' + name + '=([^&#]*)'; - const regex = new RegExp(regexS, 'i'); - const results = regex.exec(url || getWindowLocationSearch()); - - if (results == null) { - return ''; + if (!url) { + url = window.location.search; } - return decodeURIComponent(results[1].replace(/\+/g, ' ')); + // eslint-disable-next-line compat/compat + return new URLSearchParams(url).get(name) || ''; };