Skip to content

Commit

Permalink
#1133 | Show MediaOverlay only for images, allow video download
Browse files Browse the repository at this point in the history
  • Loading branch information
himeshr committed Apr 4, 2024
1 parent d8f1c6e commit 1909530
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/dataEntryApp/components/MediaUploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ export const MediaUploader = ({ label, obsValue, mediaType, update, formElement
<ReactImageVideoLightbox
data={data}
startIndex={startIndex}
showResourceCount={true}
onCloseCallback={() => setOpenImage()}
/>
</div>
Expand Down
25 changes: 22 additions & 3 deletions src/dataEntryApp/components/Observations.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ import { subjectService } from "../services/SubjectService";
import { useTranslation } from "react-i18next";
import ErrorIcon from "@material-ui/icons/Error";
import PropTypes from "prop-types";
import { find, get, includes, isEmpty, isNil, lowerCase, map } from "lodash";
import { filter, find, get, includes, isEmpty, isNil, lowerCase, map } from "lodash";
import clsx from "clsx";
import Colors from "dataEntryApp/Colors";
import { Link } from "react-router-dom";
import MediaObservations from "./MediaObservations";
import http from "../../common/utils/httpClient";
import { AudioPlayer } from "./AudioPlayer";
import VerifiedUserIcon from "@material-ui/icons/VerifiedUser";
Expand Down Expand Up @@ -128,6 +129,8 @@ const Observations = ({ observations, additionalRows, form, customKey, highlight
const { t } = useTranslation();
const classes = useStyles();

const [showMedia, setShowMedia] = React.useState(false);
const [currentMediaItemIndex, setCurrentMediaItemIndex] = React.useState(0);
const [mediaDataList, setMediaDataList] = React.useState([]);

if (isNil(observations)) {
Expand Down Expand Up @@ -201,12 +204,12 @@ const Observations = ({ observations, additionalRows, form, customKey, highlight
height={200}
onClick={event => {
event.preventDefault();
openMediaInNewTab(unsignedMediaUrl);
showMediaOverlay(unsignedMediaUrl);
}}
/>
),
[Concept.dataType.Video]: (
<video preload="auto" controls width={200} height={200} controlsList="nodownload">
<video preload="auto" controls width={200} height={200}>
<source src={unsignedMediaUrl} type="video/mp4" />
Sorry, your browser doesn't support embedded videos.
</video>
Expand Down Expand Up @@ -306,6 +309,15 @@ const Observations = ({ observations, additionalRows, form, customKey, highlight
}
};

const showMediaOverlay = unsignedMediaUrl => {
setCurrentMediaItemIndex(
filter(mediaDataList, mediaData => mediaData.type === "photo").findIndex(
img => img.url === unsignedMediaUrl
)
);
setShowMedia(true);
};

const StyledTableRow = styled(TableRow)(({ theme }) => ({
"&:nth-of-type(odd)": {
backgroundColor: theme.palette.action.hover
Expand Down Expand Up @@ -467,6 +479,13 @@ const Observations = ({ observations, additionalRows, form, customKey, highlight
>
<TableBody>{rows}</TableBody>
</Table>
{showMedia && (
<MediaObservations
mediaDataList={filter(mediaDataList, mediaData => mediaData.type === "photo")}
currentMediaItemIndex={currentMediaItemIndex}
onClose={() => setShowMedia(false)}
/>
)}
</div>
);
};
Expand Down

0 comments on commit 1909530

Please sign in to comment.