-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #682 from dali-lab/dev
Homepage redesign & blog functionality
- Loading branch information
Showing
102 changed files
with
2,581 additions
and
973 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
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 |
---|---|---|
|
@@ -7,3 +7,4 @@ yarn-error.log | |
.env | ||
|
||
.eslintcache | ||
.vscode |
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
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,13 @@ | ||
import React from 'react'; | ||
|
||
import './style.scss'; | ||
|
||
const Button = (props) => { | ||
const { | ||
onClick, buttonStyle = 'primary', children, className = '', | ||
} = props; | ||
|
||
return <button type="button" onClick={onClick} className={`button animated-button button button-${buttonStyle} ${className}`}>{children}</button>; | ||
}; | ||
|
||
export default Button; |
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,3 @@ | ||
import Button from './component'; | ||
|
||
export default Button; |
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,18 @@ | ||
.button { | ||
padding: 10px; | ||
border-radius: 6px; | ||
font-size: 18px; | ||
font-weight: 500; | ||
text-decoration: none; | ||
|
||
&-primary { | ||
color: #ffffff; | ||
background-color: #424755; | ||
} | ||
|
||
&-secondary { | ||
background-color: white; | ||
border: 1px solid #424755 !important; | ||
color: #424755 | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
import React, { useState } from 'react'; | ||
|
||
import './style.scss'; | ||
|
||
const FileInput = (props) => { | ||
const { | ||
guideURL, component, onResetFiles, fileFormat = '.csv', | ||
} = props; | ||
|
||
const [isUploadingFile, setIsUploadingFile] = useState(false); | ||
const [uploadingFileError, setUploadingFileError] = useState(''); | ||
const [successMessage, setSuccessMessage] = useState({}); | ||
|
||
const clearSuccessMessage = () => setSuccessMessage({}); | ||
|
||
const clearError = () => { | ||
setUploadingFileError(''); | ||
onResetFiles(); | ||
setIsUploadingFile(false); | ||
setSuccessMessage({}); | ||
}; | ||
|
||
if (isUploadingFile) { | ||
return ( | ||
<div className="uploading-message-container"> | ||
<h3>Uploading File...</h3> | ||
</div> | ||
); | ||
} | ||
|
||
if (uploadingFileError) { | ||
return ( | ||
<div id="uploading-error-container" className="uploading-message-container"> | ||
{ | ||
guideURL | ||
? <h3>{uploadingFileError} Please read <a href={guideURL} target="_blank" rel="noopener noreferrer">this guide</a> for uploading data.</h3> | ||
: <h3>{uploadingFileError}</h3> | ||
} | ||
<button | ||
type="button" | ||
onClick={clearError} | ||
>Try Again | ||
</button> | ||
</div> | ||
); | ||
} | ||
|
||
/** | ||
* @description uploads given file | ||
* @param {Function} uploadFunction function to upload file | ||
* @param {File} file file object | ||
* @param {Function} clearFile function to clear the file | ||
* @param {String} id file id | ||
*/ | ||
const uploadFile = async (uploadFunction, file, clearFile, id) => { | ||
setIsUploadingFile(true); | ||
|
||
try { | ||
await uploadFunction(file); | ||
clearFile(); | ||
setSuccessMessage({ [id]: 'Successfully uploaded file' }); | ||
setTimeout(clearSuccessMessage, 1000 * 7); | ||
} catch (err) { | ||
const { data, status } = err?.response || {}; | ||
|
||
const strippedError = data?.error.toString().replace('Error: ', ''); | ||
|
||
const badRequest = status === 400; | ||
const badColumnNames = strippedError.includes('missing fields in csv'); | ||
const wrongFileFormat = strippedError.includes('Invalid file type'); | ||
|
||
if (badColumnNames) setUploadingFileError('Incorrect column names. Please upload a different CSV.'); | ||
else if (wrongFileFormat) setUploadingFileError('Invalid file type. Only PNG, JPG, and JPEG files are allowed! Please, choose a different file.'); | ||
else if (badRequest) setUploadingFileError(`Bad request: ${strippedError}`); | ||
else setUploadingFileError(strippedError || data?.error.toString() || 'We encountered an error. Please try again.'); | ||
} finally { | ||
setIsUploadingFile(false); | ||
} | ||
}; | ||
|
||
return ( | ||
<div id={component.id} key={component.id}> | ||
<p>{component.name}</p> | ||
<p id="file-selected"> | ||
{component.file ? component.file.name : ''} | ||
</p> | ||
{component.file && component.uploadFile ? ( | ||
<button | ||
id="upload-button" | ||
className="custom-file-upload" | ||
type="button" | ||
onClick={() => uploadFile( | ||
component.uploadFile, | ||
component.file, | ||
component.selectFile, | ||
component.id, | ||
)} | ||
> | ||
Upload File | ||
</button> | ||
) : ( | ||
<> | ||
{successMessage[component.id] && ( | ||
<p id="success-message">{successMessage[component.id]}</p> | ||
)} | ||
<label htmlFor={`file-upload-${component.id}`} className="custom-file-upload"> | ||
<input | ||
id={`file-upload-${component.id}`} | ||
type="file" | ||
accept={fileFormat} | ||
onChange={(e) => component.selectFile(e.target.files[0]) && clearSuccessMessage()} | ||
/> | ||
Select File | ||
</label> | ||
</> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default FileInput; |
File renamed without changes.
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 |
---|---|---|
@@ -1,9 +1,11 @@ | ||
import ChoiceInput from './choice-input'; | ||
import TextInput from './text-input'; | ||
import MultiSelectInput from './multi-select-input'; | ||
import FileInput from './file-input'; | ||
|
||
export { | ||
ChoiceInput, | ||
TextInput, | ||
MultiSelectInput, | ||
FileInput, | ||
}; |
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.