Skip to content

Commit 8c53dbc

Browse files
committed
refactor: move ensureThatURLStartsWithHTTP to the url.ts
1 parent 78db425 commit 8c53dbc

2 files changed

Lines changed: 16 additions & 12 deletions

File tree

vis/js/utils/url.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ export const removeQueryParams = (...keys: string[]) => {
2323
window.history.pushState("", "", url.pathname + url.search);
2424
};
2525

26-
const addRemoveQueryParams = (paramsToAdd: Record<string, string>, paramsToRemove: string[]) => {
26+
const addRemoveQueryParams = (
27+
paramsToAdd: Record<string, string>,
28+
paramsToRemove: string[]
29+
) => {
2730
const url = new URL(window.location.href);
2831

2932
Object.keys(paramsToAdd).forEach((key) => {
@@ -39,7 +42,7 @@ const addRemoveQueryParams = (paramsToAdd: Record<string, string>, paramsToRemov
3942

4043
/**
4144
* Changes page url based on the current Redux action.
42-
*
45+
*
4346
* @param {Object} action the Redux action object
4447
*/
4548
export const handleUrlAction = (action: any) => {
@@ -98,3 +101,13 @@ const handleSelectPaper = (action: any) => {
98101
};
99102

100103
const handleDeselectPaper = () => removeQueryParams("paper");
104+
105+
export const ensureThatURLStartsWithHTTP = (url: string): string => {
106+
let formattedURL = url;
107+
108+
if (!/^https?:\/\//i.test(url)) {
109+
formattedURL = "https:" + url;
110+
}
111+
112+
return formattedURL;
113+
};

vis/js/utils/usePdfLookup.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import $ from "jquery";
44
import { isFileAvailable } from "./data";
55
import { Paper } from "../@types/paper";
66
import { useSelector } from "react-redux";
7+
import { ensureThatURLStartsWithHTTP } from "./url";
78

89
const getVisualizationIdFromStore = (state: any): string => {
910
return state.data.options.visualizationId;
@@ -105,16 +106,6 @@ const usePdfLookup = (paper: Paper, serverUrl: string, service: string) => {
105106

106107
export default usePdfLookup;
107108

108-
const ensureThatURLStartsWithHTTP = (url: string): string => {
109-
let formattedURL = url;
110-
111-
if (!/^https?:\/\//i.test(url)) {
112-
formattedURL = "https:" + url;
113-
}
114-
115-
return formattedURL;
116-
};
117-
118109
const requestPdfLookup = (
119110
server: string,
120111
url: string,

0 commit comments

Comments
 (0)