Web:Files:Added isFirstUrl data to localStorage. Changed the condition for changing the url.

This commit is contained in:
Vlada Gazizova 2022-01-28 16:34:15 +03:00
parent d01ae8b347
commit 8add87820c
3 changed files with 16 additions and 23 deletions

View File

@ -206,7 +206,6 @@ class MediaViewer extends React.Component {
document.addEventListener("keydown", this.onKeydown, false);
document.addEventListener("keyup", this.onKeyup, false);
localStorage.setItem("isMediaViewerOpen", true);
}
componentWillUnmount() {
@ -221,7 +220,6 @@ class MediaViewer extends React.Component {
document.removeEventListener("keydown", this.onKeydown, false);
document.removeEventListener("keyup", this.onKeyup, false);
this.onClose();
localStorage.setItem("isMediaViewerOpen", false);
}
mapSupplied = {
@ -427,9 +425,8 @@ class MediaViewer extends React.Component {
}
};
onClose = () => {
console.log("onClose");
this.props.onClose(event);
onClose = (e) => {
this.props.onClose(e);
this.setState({ visible: false });
};

View File

@ -6,7 +6,6 @@ import { AppServerConfig } from "@appserver/common/constants";
import { combineUrl } from "@appserver/common/utils";
import config from "../../package.json";
import { isMobile } from "react-device-detect";
//import history from "@appserver/common/history";
export default function withFileActions(WrappedFileItem) {
class WithFileActions extends React.Component {
@ -205,6 +204,7 @@ export default function withFileActions(WrappedFileItem) {
}
if (isMediaOrImage) {
localStorage.setItem("isFirstUrl", window.location.href);
setMediaViewerData({ visible: true, id });
const url = "/products/files/#preview/" + id;

View File

@ -30,8 +30,6 @@ const FilesMediaViewer = (props) => {
expandedKeys,
} = props;
const [firstUrl, setFirstUrl] = useState();
useEffect(() => {
const previewId = queryString.parse(location.search).preview;
@ -41,16 +39,7 @@ const FilesMediaViewer = (props) => {
}
}, [removeQuery, onMediaFileClick]);
const checkURLchange = () => {
if (!oldURL.includes("#preview")) {
setFirstUrl(oldURL);
}
};
let oldURL = window.location.href;
setInterval(checkURLchange, 1000);
window.onpopstate = function (event) {
window.onpopstate = function (e) {
const hash = window.location.hash;
const id = +hash.slice(9);
if (!id) {
@ -111,7 +100,7 @@ const FilesMediaViewer = (props) => {
}
};
const onMediaViewerClose = (event) => {
const onMediaViewerClose = (e) => {
if (previewFile) {
setIsLoading(true);
setFirstLoad(true);
@ -129,11 +118,18 @@ const FilesMediaViewer = (props) => {
}
setMediaViewerData({ visible: false, id: null });
if (event.currentTarget.closed === false) {
return;
} else {
window.history.replaceState(null, null, firstUrl);
console.log("event", e);
if (e) {
const url = localStorage.getItem("isFirstUrl");
if (!url) {
return;
}
window.history.replaceState(null, null, url);
}
localStorage.removeItem("isFirstUrl");
};
return (