Skip to content

Commit

Permalink
rate limiting additions
Browse files Browse the repository at this point in the history
  • Loading branch information
sam-morin committed Jan 29, 2024
1 parent 1a9b394 commit a288e75
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ function App() {
const [removeToggle, setRemoveToggle] = useState(false);
const [renameToggle, setRenameToggle] = useState(false);
const [newName, setNewName] = useState('');
const [tooManyUploads, setTooManyUploads] = useState();

const uploadEndpoint = uploadEndpointRoot + (removeToggle ? '/remove' : '')

Expand Down Expand Up @@ -46,6 +47,7 @@ function App() {
} else {
console.error('Error uploading file:', response.statusText);
setSuccess(false);
response.status === 429 ? (setTooManyUploads(true) && setTimeout(() => {setTooManyUploads(false) && setSuccess(true)}, 20000)) : setTooManyUploads(false)
}
} catch (error) {
console.error('Error uploading file:', error);
Expand Down Expand Up @@ -120,6 +122,7 @@ function App() {
renameToggle={renameToggle}
renameToggleAction={'Upload'}
handleFileUpload={handleFileUpload}
tooManyUploads={tooManyUploads}
/>
<Footer />
</div>
Expand Down
7 changes: 5 additions & 2 deletions src/components/UploadButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import CheckCircleOutlineOutlinedIcon from '@mui/icons-material/CheckCircleOutli
import ErrorOutlineOutlinedIcon from '@mui/icons-material/ErrorOutlineOutlined';
import CircularProgress from '@mui/material/CircularProgress';

export default function UploadButton({ uploading, success, handleFileUpload, renameToggleAction }) {
export default function UploadButton({ uploading, success, handleFileUpload, renameToggleAction, tooManyUploads }) {
const handleFileChange = (event) => {
const file = event.target.files[0];
if (file) {
Expand Down Expand Up @@ -37,6 +37,7 @@ export default function UploadButton({ uploading, success, handleFileUpload, ren
style={{ display: 'none' }}
id="file-input"
onChange={handleFileChange}
disabled={tooManyUploads}
/>
<label htmlFor="file-input">
<Button
Expand All @@ -54,7 +55,7 @@ export default function UploadButton({ uploading, success, handleFileUpload, ren
startIcon={
success ? (
<CheckCircleOutlineOutlinedIcon />
) : success === false ? (
) : (success === false || tooManyUploads) ? (
<ErrorOutlineOutlinedIcon />
) : uploading ? (
<CircularProgress size={20} thickness={5.5} style={{ color: 'white' }} />
Expand All @@ -65,6 +66,8 @@ export default function UploadButton({ uploading, success, handleFileUpload, ren
>
{success
? 'Downloaded PDF'
: tooManyUploads
? `Hey! Too many requests!`
: success === false
? 'Something went wrong!'
: uploading
Expand Down

0 comments on commit a288e75

Please sign in to comment.