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

Added File Upload Capability and Loading logic to confirmation screen #55

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
41 changes: 38 additions & 3 deletions src/components/upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,9 @@ const Upload: React.FC = () => {
const [isSandbox, setIsSandbox] = useState(false);
const [description, setDescription] = useState('');
const [expandedFile, setExpandedFile] = useState<string | null>(null);
const [submissionSuccess, setSubmissionSuccess] = useState(false);
const [submissionFailure, setSubmissionFailure] = useState(false);
const [isLoading, setIsLoading] = useState(false);

useEffect(() => {
async function fetchSandboxStatus() {
Expand Down Expand Up @@ -302,6 +305,7 @@ const Upload: React.FC = () => {
};

const handleConfirm = async () => {
setIsLoading(true);
const formData = new FormData();
selectedFilePaths.forEach(filePath => formData.append('filePaths', filePath));
formData.append('title', title);
Expand All @@ -326,8 +330,24 @@ const Upload: React.FC = () => {
console.log(`${key}: ${value}`);
}
console.log(JSON.stringify(payload));
const response = await depositUpload(payload);
console.log(response['status']);
try {
const response = await depositUpload(payload);
console.log(response['status']);

if (response['status'] == "200") {
setSubmissionSuccess(true); // Mark submission as successful
setIsConfirmationVisible(false); // Hide the confirmation section
setSubmissionFailure(false);
} else {
setSubmissionFailure(true);
setIsConfirmationVisible(false);
setSubmissionSuccess(false);
}
} catch (error) {
console.error('Error during submission:', error);
} finally {
setIsLoading(false);
}
};

const fileName = (filePath: string) => {
Expand All @@ -337,7 +357,12 @@ const Upload: React.FC = () => {

return (
<div className={classes.container}>
{isConfirmationVisible ? (
{isLoading ? (
<div>
<h2>Submitting...</h2>
<p>Please wait while your submission is being processed.</p>
</div>
) : isConfirmationVisible ? (
<Confirmation
title={title}
resourceType={resourceType}
Expand All @@ -349,6 +374,16 @@ const Upload: React.FC = () => {
onEdit={handleEdit}
onConfirm={handleConfirm}
/>
) : submissionSuccess ? (
<div>
<h2>Submission Successful!</h2>
<p>Your information has been successfully submitted.</p>
</div>
) : submissionFailure ? (
<div>
<h2>Submission Failure!</h2>
<p>Your information has NOT been successfully submitted.</p>
</div>
) : (
<>
<h1 className={classes.heading}>Upload</h1>
Expand Down
19 changes: 15 additions & 4 deletions zenodo_jupyterlab/server/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,27 @@ async def createMetadata(zAPI, recordID, form_data):
response = zAPI.set_deposit_metadata(recordID, json_metadata)
return response

async def uploadFiles(zAPI, recordID, fileArray):
for file in fileArray:
fileName = file.split('/')[-1]
try:
response = zAPI.upload_file_deposit(recordID, fileName, file)
except:
return None
return response

async def upload(zAPI, form_data):
if zAPI == None:
return None
try:
recordID = await createDeposit(zAPI)
response = await createMetadata(zAPI, str(recordID), form_data)
if response != None:
return "Success"
else:
return "Adding the metadata returned a None response."
if response == None:
return None
response = await uploadFiles(zAPI, recordID, form_data.get('filePaths'))
if response == None:
return "File failure in checking"
return "200"
except:
return None

Loading