Skip to content
Snippets Groups Projects
Commit 72bffc84 authored by Alexandru Munteanu's avatar Alexandru Munteanu
Browse files

remove frament id

parent 9e05a375
No related branches found
No related tags found
No related merge requests found
...@@ -19,7 +19,15 @@ const parseFileSize = size => { ...@@ -19,7 +19,15 @@ const parseFileSize = size => {
return `${size} bytes` return `${size} bytes`
} }
const FileItem = ({ dragHandle, name, size, id, removeFile, ...rest }) => ( const FileItem = ({
dragHandle,
name,
size,
id,
removeFile,
previewFile,
...rest
}) => (
<div className={classnames(classes['file-item'])}> <div className={classnames(classes['file-item'])}>
{dragHandle} {dragHandle}
<div className={classnames(classes.info)}> <div className={classnames(classes.info)}>
...@@ -27,9 +35,9 @@ const FileItem = ({ dragHandle, name, size, id, removeFile, ...rest }) => ( ...@@ -27,9 +35,9 @@ const FileItem = ({ dragHandle, name, size, id, removeFile, ...rest }) => (
<span>{parseFileSize(size)}</span> <span>{parseFileSize(size)}</span>
</div> </div>
<div className={classnames(classes.buttons)}> <div className={classnames(classes.buttons)}>
<a href={rest.signedUrl} target="_blank"> <button onClick={previewFile(id)}>
<Icon color="#666">eye</Icon> <Icon color="#666">eye</Icon>
</a> </button>
<button onClick={removeFile(id)} title="Delete"> <button onClick={removeFile(id)} title="Delete">
<Icon color="#666">trash-2</Icon> <Icon color="#666">trash-2</Icon>
</button> </button>
......
...@@ -40,6 +40,7 @@ const FileSection = ({ ...@@ -40,6 +40,7 @@ const FileSection = ({
canDropFile, canDropFile,
disabledFilepicker, disabledFilepicker,
dropSortableFile, dropSortableFile,
previewFile,
}) => }) =>
connectFileDrop( connectFileDrop(
connectDropTarget( connectDropTarget(
...@@ -87,6 +88,7 @@ const FileSection = ({ ...@@ -87,6 +88,7 @@ const FileSection = ({
listId={listId} listId={listId}
listItem={FileItem} listItem={FileItem}
moveItem={moveItem} moveItem={moveItem}
previewFile={previewFile}
removeFile={removeFile} removeFile={removeFile}
/> />
<FileDropzone label="Drag files here or use the add button." /> <FileDropzone label="Drag files here or use the add button." />
......
...@@ -21,6 +21,7 @@ import { ...@@ -21,6 +21,7 @@ import {
getRequestStatus, getRequestStatus,
setAllFiles, setAllFiles,
moveFiles, moveFiles,
getSignedUrl,
} from '../redux/files' } from '../redux/files'
const Files = ({ const Files = ({
...@@ -30,6 +31,7 @@ const Files = ({ ...@@ -30,6 +31,7 @@ const Files = ({
removeFile, removeFile,
changeList, changeList,
dropSortableFile, dropSortableFile,
previewFile,
...rest ...rest
}) => ( }) => (
<div> <div>
...@@ -43,6 +45,7 @@ const Files = ({ ...@@ -43,6 +45,7 @@ const Files = ({
listId="manuscripts" listId="manuscripts"
maxFiles={Number.POSITIVE_INFINITY} maxFiles={Number.POSITIVE_INFINITY}
moveItem={moveItem('manuscripts')} moveItem={moveItem('manuscripts')}
previewFile={previewFile}
removeFile={removeFile('manuscripts')} removeFile={removeFile('manuscripts')}
title="Main manuscript" title="Main manuscript"
/> />
...@@ -54,6 +57,7 @@ const Files = ({ ...@@ -54,6 +57,7 @@ const Files = ({
listId="supplementary" listId="supplementary"
maxFiles={Number.POSITIVE_INFINITY} maxFiles={Number.POSITIVE_INFINITY}
moveItem={moveItem('supplementary')} moveItem={moveItem('supplementary')}
previewFile={previewFile}
removeFile={removeFile('supplementary')} removeFile={removeFile('supplementary')}
title="Supplementarry files" title="Supplementarry files"
/> />
...@@ -67,6 +71,7 @@ const Files = ({ ...@@ -67,6 +71,7 @@ const Files = ({
listId="coverLetter" listId="coverLetter"
maxFiles={1} maxFiles={1}
moveItem={moveItem('coverLetter')} moveItem={moveItem('coverLetter')}
previewFile={previewFile}
removeFile={removeFile('coverLetter')} removeFile={removeFile('coverLetter')}
title="Cover letter" title="Cover letter"
/> />
...@@ -86,6 +91,7 @@ export default compose( ...@@ -86,6 +91,7 @@ export default compose(
deleteFile, deleteFile,
setAllFiles, setAllFiles,
moveFiles, moveFiles,
getSignedUrl,
}, },
), ),
lifecycle({ lifecycle({
...@@ -95,6 +101,12 @@ export default compose( ...@@ -95,6 +101,12 @@ export default compose(
}, },
}), }),
withHandlers({ withHandlers({
previewFile: ({ getSignedUrl }) => fileId => e => {
e.preventDefault()
getSignedUrl(fileId).then(({ signedUrl }) => {
window.open(signedUrl)
})
},
dropSortableFile: ({ files, setAllFiles }) => () => { dropSortableFile: ({ files, setAllFiles }) => () => {
setAllFiles(files) setAllFiles(files)
}, },
...@@ -134,7 +146,7 @@ export default compose( ...@@ -134,7 +146,7 @@ export default compose(
version, version,
}) => type => id => e => { }) => type => id => e => {
e.preventDefault() e.preventDefault()
deleteFile(id, version.id) deleteFile(id)
const newFiles = { const newFiles = {
...files, ...files,
[type]: files[type].filter(f => f.id !== id), [type]: files[type].filter(f => f.id !== id),
......
...@@ -66,6 +66,7 @@ export default ({ ...@@ -66,6 +66,7 @@ export default ({
) )
}, },
)} )}
<Files />
<div className={classnames(classes.buttons)}> <div className={classnames(classes.buttons)}>
<Button onClick={isFirst ? () => history.push('/') : prevStep}> <Button onClick={isFirst ? () => history.push('/') : prevStep}>
{isFirst {isFirst
......
...@@ -89,7 +89,7 @@ export const getRequestStatus = state => state.files.isFetching ...@@ -89,7 +89,7 @@ export const getRequestStatus = state => state.files.isFetching
// thunked actions // thunked actions
export const uploadFile = (file, type, fragmentId) => dispatch => { export const uploadFile = (file, type, fragmentId) => dispatch => {
dispatch(uploadRequest(type)) dispatch(uploadRequest(type))
return request('/aws-upload', createFileData(file, type, fragmentId)) return request('/aws', createFileData(file, type, fragmentId))
.then(r => { .then(r => {
dispatch(uploadSuccess()) dispatch(uploadSuccess())
return r return r
...@@ -97,9 +97,9 @@ export const uploadFile = (file, type, fragmentId) => dispatch => { ...@@ -97,9 +97,9 @@ export const uploadFile = (file, type, fragmentId) => dispatch => {
.catch(err => dispatch(uploadFailure(err.message))) .catch(err => dispatch(uploadFailure(err.message)))
} }
export const deleteFile = (fileId, fragmentId) => dispatch => { export const deleteFile = fileId => dispatch => {
dispatch(removeRequest()) dispatch(removeRequest())
return remove(`/aws-delete/${fragmentId}/${fileId}`) return remove(`/aws/${fileId}`)
.then(r => { .then(r => {
dispatch(removeSuccess()) dispatch(removeSuccess())
return r return r
...@@ -107,8 +107,7 @@ export const deleteFile = (fileId, fragmentId) => dispatch => { ...@@ -107,8 +107,7 @@ export const deleteFile = (fileId, fragmentId) => dispatch => {
.catch(err => dispatch(removeFailure(err.message))) .catch(err => dispatch(removeFailure(err.message)))
} }
export const getSignedUrl = (fileId, fragmentId) => export const getSignedUrl = fileId => dispatch => get(`/aws/${fileId}`)
get(`aws-signed-url/${fragmentId}/${fileId}`)
// reducer // reducer
export default (state = initialState, action) => { export default (state = initialState, action) => {
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment