-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Form Builder] Added file review modal in TaskReview
- Loading branch information
Showing
16 changed files
with
892 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
mephisto/review_app/client/src/pages/TaskPage/InReviewFileModal/InReviewFileModal.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* Copyright (c) Meta Platforms and its affiliates. | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
.in-review-file-modal .modal-dialog { | ||
max-width: 98vw; | ||
min-width: 500px; | ||
width: fit-content; | ||
} | ||
|
||
.in-review-file-modal .modal-dialog .modal-header { | ||
background-color: #ecdadf; | ||
display: flex; | ||
justify-content: space-between; | ||
padding: 5px; | ||
border-radius: 0; | ||
} | ||
|
||
.in-review-file-modal .modal-dialog .modal-header .button-close { | ||
height: 38px; | ||
width: 38px; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
background-color: transparent; | ||
border: none; | ||
font-size: 38px; | ||
line-height: 1; | ||
cursor: pointer; | ||
} | ||
|
||
.in-review-file-modal .modal-dialog .modal-header .button-download-file { | ||
height: 38px; | ||
width: 38px; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
background-color: transparent; | ||
border: none; | ||
font-size: 30px; | ||
line-height: 1; | ||
cursor: pointer; | ||
text-decoration: none; | ||
color: black; | ||
} | ||
|
||
.in-review-file-modal .modal-dialog .modal-header .button-close:hover, | ||
.in-review-file-modal .modal-dialog .modal-header .button-download-file:hover { | ||
opacity: 0.7; | ||
background-color: lightgrey; | ||
} | ||
|
||
.in-review-file-modal .modal-dialog .modal-header .modal-title { | ||
font-size: 26px; | ||
} | ||
|
||
/* Body */ | ||
.in-review-file-modal .modal-dialog .modal-content { | ||
border-radius: initial; | ||
width: fit-content; | ||
min-width: 500px; | ||
} | ||
|
||
.in-review-file-modal .modal-dialog .modal-content .modal-body { | ||
/*width: fit-content;*/ | ||
display: flex; | ||
flex-direction: row; | ||
justify-content: center; | ||
} | ||
|
||
.in-review-file-modal .modal-dialog .modal-content .modal-body img, | ||
.in-review-file-modal .modal-dialog .modal-content .modal-body video { | ||
width: fit-content; | ||
max-width: 100%; | ||
} | ||
|
||
.in-review-file-modal .modal-dialog .modal-content .modal-body .iframe-wrapper { | ||
position: relative; | ||
width: 100%; | ||
padding-top: calc(129% + 2%); | ||
} | ||
.in-review-file-modal .modal-dialog .modal-content .modal-body iframe { | ||
position: absolute; | ||
top: 0; | ||
width: 100%; | ||
height: 100%; | ||
background-color: #f2f2f2; | ||
border: 1px solid #cccccc; | ||
} |
106 changes: 106 additions & 0 deletions
106
mephisto/review_app/client/src/pages/TaskPage/InReviewFileModal/InReviewFileModal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* | ||
* Copyright (c) Meta Platforms and its affiliates. | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import { AUDIO_TYPES_BY_EXT, FILE_TYPE_BY_EXT, FileType, VIDEO_TYPES_BY_EXT } from "consts/review"; | ||
import * as React from "react"; | ||
import { useEffect } from "react"; | ||
import { Modal } from "react-bootstrap"; | ||
import urls from "urls"; | ||
import "./InReviewFileModal.css"; | ||
|
||
|
||
type InReviewFileModalProps = { | ||
data: InReviewFileModalDataType; | ||
setData: React.Dispatch<React.SetStateAction<InReviewFileModalDataType>>; | ||
show: boolean; | ||
setShow: React.Dispatch<React.SetStateAction<boolean>>; | ||
}; | ||
|
||
function InReviewFileModal(props: InReviewFileModalProps) { | ||
const { data, show, setShow } = props; | ||
|
||
const [fileUrl, setFileUrl] = React.useState<string>(null); | ||
const [fileExt, setFileExt] = React.useState<string>(null); | ||
|
||
const fileType = FILE_TYPE_BY_EXT[fileExt]; | ||
|
||
function onModalClose() { | ||
setShow(!show); | ||
} | ||
|
||
function truncateFilename(filename: string, n: number): string { | ||
const ext = data.filename.split(".").pop(); | ||
const _filename = (filename.length > n) | ||
? (filename.slice(0, (n - 1 - ext.length)) + "…" + "." + ext) | ||
: filename; | ||
return _filename; | ||
} | ||
|
||
useEffect(() => { | ||
setFileUrl(null); | ||
setFileExt(null); | ||
|
||
if (data.filename) { | ||
setFileUrl(urls.server.unitFile(data.unitId, data.filename)); | ||
setFileExt(data.filename.split(".").pop().toLowerCase()); | ||
} | ||
}, [data]); | ||
|
||
return ( | ||
show && ( | ||
<Modal className={"in-review-file-modal"} show={show} onHide={onModalClose}> | ||
<Modal.Header closeButton={false}> | ||
<button className={"button-close"} onClick={() => setShow(false)}> | ||
✕ | ||
</button> | ||
<Modal.Title> | ||
{truncateFilename(data.title, 50)} | ||
</Modal.Title> | ||
<a | ||
className={"button-download-file"} | ||
title={"Download source"} | ||
href={fileUrl} | ||
target={"_blank"} | ||
> | ||
⤓ | ||
</a> | ||
</Modal.Header> | ||
|
||
<Modal.Body> | ||
{fileType ? (<> | ||
{fileType === FileType.IMAGE && ( | ||
<img className={""} src={fileUrl} alt={`image "${data.filename}}`} /> | ||
)} | ||
{fileType === FileType.VIDEO && ( | ||
<video className={""} controls={true}> | ||
<source src={fileUrl} type={VIDEO_TYPES_BY_EXT[fileExt]} /> | ||
</video> | ||
)} | ||
{fileType === FileType.AUDIO && ( | ||
<audio className={""} controls={true}> | ||
<source src={fileUrl} type={AUDIO_TYPES_BY_EXT[fileExt]} /> | ||
</audio> | ||
)} | ||
{fileType === FileType.PDF && ( | ||
<div className={"iframe-wrapper"}> | ||
<iframe | ||
className={""} | ||
src={`${fileUrl}#view=fit&page=1&toolbar=0&navpanes=0`} | ||
/> | ||
</div> | ||
)} | ||
</>) : (<> | ||
Cannot show preview for this type of file. | ||
<br /> | ||
You can download and open file on your computer | ||
</>)} | ||
</Modal.Body> | ||
</Modal> | ||
) | ||
); | ||
} | ||
|
||
export { InReviewFileModal }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
mephisto/review_app/client/src/types/inReviewFileModal.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* | ||
* Copyright (c) Meta Platforms and its affiliates. | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
type InReviewFileModalDataType = { | ||
filename?: string; | ||
title?: string; | ||
unitId?: number; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.