Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/fix display images in media viewer #502

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
28bbc72
Web:Files:Added history.pushState method to display images in HOC wit…
gazizova-vlada Jan 18, 2022
5222666
Web:Common:Added history.pushState method to display images in MediaV…
gazizova-vlada Jan 18, 2022
fde1f1c
Web:Files:Сhanged history.pushState method to history.push.
gazizova-vlada Jan 19, 2022
5dbe35f
Web:Common:Сhanged history.pushState method to history.push.
gazizova-vlada Jan 19, 2022
ee2fd6b
Web:Files:Added a check for the absence of other pictures in the play…
gazizova-vlada Jan 21, 2022
ef6682a
Web:Files:Added check for open MediaViewer. Added checkURLchange func…
gazizova-vlada Jan 25, 2022
e200898
Added isMediaViewerOpen key to localStorage.
gazizova-vlada Jan 25, 2022
4c6d130
Web:Files:Added MediaViewer closing handling when the Close button is…
gazizova-vlada Jan 26, 2022
218990c
b:Common: Added props onChangeUrl to the MediaViewer component.
gazizova-vlada Jan 27, 2022
d01ae8b
Web:Files:Added onChangeUrl function to MediaViewer. Added onpopstate…
gazizova-vlada Jan 27, 2022
8add878
Web:Files:Added isFirstUrl data to localStorage. Changed the conditio…
gazizova-vlada Jan 28, 2022
b913486
Web:Common:Changed props previewFile to isPreviewFile. Changed propTy…
gazizova-vlada Jan 30, 2022
29930f2
Web:Files:Added setToPreviewFile to MediaViewer. Changed setToPreview…
gazizova-vlada Jan 31, 2022
9e35b79
Web:Files:Added removal of the isFirstUrl key from localStorage.
gazizova-vlada Feb 2, 2022
bf07a14
Web:Common:Fix.
gazizova-vlada Feb 2, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions packages/asc-web-common/components/MediaViewer/MediaViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,9 @@ class MediaViewer extends React.Component {
this.setState({
playlistPos: currentPlaylistPos,
});

const id = playlist[currentPlaylistPos].fileId;
this.props.onChangeUrl(id);
};

nextMedia = () => {
Expand All @@ -319,6 +322,9 @@ class MediaViewer extends React.Component {
this.setState({
playlistPos: currentPlaylistPos,
});

const id = playlist[currentPlaylistPos].fileId;
this.props.onChangeUrl(id);
};

getOffset = () => {
Expand Down Expand Up @@ -419,8 +425,8 @@ class MediaViewer extends React.Component {
}
};

onClose = () => {
this.props.onClose();
onClose = (e) => {
this.props.onClose(e);
this.setState({ visible: false });
};

Expand Down Expand Up @@ -450,7 +456,7 @@ class MediaViewer extends React.Component {
canDelete,
canDownload,
errorLabel,
previewFile,
isPreviewFile,
} = this.props;

const currentFileId =
Expand Down Expand Up @@ -547,7 +553,7 @@ class MediaViewer extends React.Component {
<div className="mediaViewerToolbox" ref={this.viewerToolbox}>
{!isImage && (
<span>
{canDelete(currentFileId) && !previewFile && (
{canDelete(currentFileId) && !isPreviewFile && (
<ControlBtn onClick={this.onDelete}>
<div className="deleteBtnContainer">
<StyledMediaDeleteIcon size="scale" />
Expand Down Expand Up @@ -585,7 +591,8 @@ MediaViewer.propTypes = {
onEmptyPlaylistError: PropTypes.func,
deleteDialogVisible: PropTypes.bool,
errorLabel: PropTypes.string,
previewFile: PropTypes.bool,
isPreviewFile: PropTypes.bool,
onChangeUrl: PropTypes.func,
};

MediaViewer.defaultProps = {
Expand All @@ -598,7 +605,7 @@ MediaViewer.defaultProps = {
canDownload: () => {
return true;
},
previewFile: false,
isPreviewFile: false,
};

export default MediaViewer;
4 changes: 4 additions & 0 deletions products/ASC.Files/Client/src/HOCs/withFileActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,11 @@ export default function withFileActions(WrappedFileItem) {
}

if (isMediaOrImage) {
localStorage.setItem("isFirstUrl", window.location.href);
setMediaViewerData({ visible: true, id });

const url = "/products/files/#preview/" + id;
history.pushState(null, null, url);
return;
}

Expand Down
38 changes: 36 additions & 2 deletions products/ASC.Files/Client/src/pages/Home/MediaViewer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const FilesMediaViewer = (props) => {
setIsLoading,
setFirstLoad,
setExpandedKeys,
setToPreviewFile,
expandedKeys,
} = props;

Expand All @@ -39,6 +40,25 @@ const FilesMediaViewer = (props) => {
}
}, [removeQuery, onMediaFileClick]);

useEffect(() => {
window.addEventListener("popstate", onButtonBackHandler);
}, [onButtonBackHandler]);

const onButtonBackHandler = () => {
const hash = window.location.hash;
const id = +hash.slice(9);
if (!id) {
setMediaViewerData({ visible: false, id: null });
return;
}
setMediaViewerData({ visible: true, id });
};

const onChangeUrl = (id) => {
const url = "/products/files/#preview/" + id;
window.history.pushState(null, null, url);
};

const removeQuery = (queryName) => {
const queryParams = new URLSearchParams(location.search);

Expand All @@ -52,6 +72,7 @@ const FilesMediaViewer = (props) => {

const onMediaFileClick = (id) => {
//const itemId = typeof id !== "object" ? id : this.props.selection[0].id; TODO:

if (typeof id !== "object") {
const item = { visible: true, id };
setMediaViewerData(item);
Expand Down Expand Up @@ -84,7 +105,7 @@ const FilesMediaViewer = (props) => {
}
};

const onMediaViewerClose = () => {
const onMediaViewerClose = (e) => {
if (previewFile) {
setIsLoading(true);
setFirstLoad(true);
Expand All @@ -98,9 +119,19 @@ const FilesMediaViewer = (props) => {
.finally(() => {
setIsLoading(false);
setFirstLoad(false);
setToPreviewFile(null);
});
}
setMediaViewerData({ visible: false, id: null });

if (e) {
const url = localStorage.getItem("isFirstUrl");

if (!url) {
return;
}
window.history.replaceState(null, null, url);
}
};

return (
Expand All @@ -121,7 +152,8 @@ const FilesMediaViewer = (props) => {
extsMediaPreviewed={mediaViewerMediaFormats} //TODO:
extsImagePreviewed={mediaViewerImageFormats} //TODO:
errorLabel={t("Translations:MediaLoadError")}
previewFile={previewFile}
isPreviewFile={!!previewFile}
onChangeUrl={onChangeUrl}
/>
)
);
Expand Down Expand Up @@ -149,6 +181,7 @@ export default inject(
setMediaViewerData,
playlist,
previewFile,
setToPreviewFile,
} = mediaViewerDataStore;
const { deleteItemAction } = filesActionsStore;
const { media, images } = formatsStore.mediaViewersFormatsStore;
Expand All @@ -171,6 +204,7 @@ export default inject(
setIsLoading,
setFirstLoad,
setExpandedKeys,
setToPreviewFile,
expandedKeys,
};
}
Expand Down
17 changes: 15 additions & 2 deletions products/ASC.Files/Client/src/pages/Home/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,23 @@ class PureHome extends React.Component {
expandedKeys,
setExpandedKeys,
setToPreviewFile,
playlist,
mediaViewersFormatsStore,
getFileInfo,
} = this.props;

if (!window.location.href.includes("#preview")) {
localStorage.removeItem("isFirstUrl");
}

const reg = new RegExp(`${homepage}((/?)$|/filter)`, "gmi"); //TODO: Always find?
const match = window.location.pathname.match(reg);
let filterObj = null;

if (window.location.href.indexOf("/files/#preview") > 1) {
if (
window.location.href.indexOf("/files/#preview") > 1 &&
playlist.length < 1
) {
const pathname = window.location.href;
const fileId = pathname.slice(pathname.indexOf("#preview") + 9);

Expand All @@ -67,6 +75,10 @@ class PureHome extends React.Component {
}

if (match && match.length > 0) {
if (window.location.href.includes("#preview")) {
return;
}

filterObj = FilesFilter.getFilter(window.location);

if (!filterObj) {
Expand Down Expand Up @@ -393,7 +405,7 @@ export default inject(
? filesStore.selectionTitle
: null;

const { setToPreviewFile } = mediaViewerDataStore;
const { setToPreviewFile, playlist } = mediaViewerDataStore;
if (!firstLoad) {
if (isLoading) {
showLoader();
Expand Down Expand Up @@ -441,6 +453,7 @@ export default inject(
isHeaderVisible: auth.settingsStore.isHeaderVisible,
setHeaderVisible: auth.settingsStore.setHeaderVisible,
setToPreviewFile,
playlist,
mediaViewersFormatsStore,
getFileInfo,
};
Expand Down
9 changes: 9 additions & 0 deletions products/ASC.Files/Client/src/store/MediaViewerDataStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,15 @@ class MediaViewerDataStore {
};

setToPreviewFile = (file, visible) => {
if (file === null) {
this.previewFile = null;
this.id = null;
this.visible = false;
return;
}

if (!file.canOpenPlayer) return;

this.previewFile = file;
this.id = file.id;
this.visible = visible;
Expand Down Expand Up @@ -55,6 +63,7 @@ class MediaViewerDataStore {
title: this.previewFile.title,
});
}

return playlist;
}
}
Expand Down