mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-10 11:59:23 +00:00
Go for a more generic js bundling architecture
* Don't tie the output name to webpack itself * Don't call js bundling webpack in python code * Make the doc more generic about js bundling
This commit is contained in:
40
core/static/bundled/utils/history.ts
Normal file
40
core/static/bundled/utils/history.ts
Normal file
@ -0,0 +1,40 @@
|
||||
export enum History {
|
||||
None = 0,
|
||||
Push = 1,
|
||||
Replace = 2,
|
||||
}
|
||||
|
||||
export const initialUrlParams = new URLSearchParams(window.location.search);
|
||||
export const getCurrentUrlParams = () => {
|
||||
return new URLSearchParams(window.location.search);
|
||||
};
|
||||
|
||||
export function updateQueryString(
|
||||
key: string,
|
||||
value?: string | string[],
|
||||
action?: History,
|
||||
url?: string,
|
||||
) {
|
||||
const historyAction = action ?? History.Replace;
|
||||
const ret = new URL(url ?? window.location.href);
|
||||
|
||||
if (value === undefined || value === null || value === "") {
|
||||
// If the value is null, undefined or empty => delete it
|
||||
ret.searchParams.delete(key);
|
||||
} else if (Array.isArray(value)) {
|
||||
ret.searchParams.delete(key);
|
||||
for (const v of value) {
|
||||
ret.searchParams.append(key, v);
|
||||
}
|
||||
} else {
|
||||
ret.searchParams.set(key, value);
|
||||
}
|
||||
|
||||
if (historyAction === History.Push) {
|
||||
window.history.pushState(null, "", ret.toString());
|
||||
} else if (historyAction === History.Replace) {
|
||||
window.history.replaceState(null, "", ret.toString());
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
Reference in New Issue
Block a user