feat: read content from search params (#1607)

This commit is contained in:
Max Malm
2023-04-27 01:15:40 +02:00
committed by GitHub
parent 3fad718807
commit dbb544dc92
2 changed files with 22 additions and 1 deletions

View File

@ -105,3 +105,18 @@ export const formatBytes = (bytes: number) => {
i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + " " + sizes[i];
};
export const getContentQueryParam = (): string | undefined => {
const urlParams = new URLSearchParams(window.location.search);
return urlParams.get("content") ?? undefined;
};
export const clearContentQueryParam = () => {
const urlParams = new URLSearchParams(window.location.search);
urlParams.delete("content");
let url = window.location.pathname;
if (urlParams.toString()) {
url += `?${urlParams.toString()}`;
}
window.history.replaceState({}, "", url);
};