use shouldAllowNewUpload to prevent uploads

This commit is contained in:
Abhinav 2022-09-02 15:33:37 +05:30
parent dc65cbf7d8
commit 022826dfa6
4 changed files with 32 additions and 11 deletions

View file

@ -3,6 +3,7 @@ import { Button, styled, Typography } from '@mui/material';
import constants from 'utils/strings/constants'; import constants from 'utils/strings/constants';
import { DeduplicateContext } from 'pages/deduplicate'; import { DeduplicateContext } from 'pages/deduplicate';
import VerticallyCentered from './Container'; import VerticallyCentered from './Container';
import uploadManager from 'services/upload/uploadManager';
const Wrapper = styled(VerticallyCentered)` const Wrapper = styled(VerticallyCentered)`
& > svg { & > svg {
@ -34,12 +35,20 @@ export default function EmptyScreen({ openUploader }) {
{constants.UPLOAD_FIRST_PHOTO_DESCRIPTION()} {constants.UPLOAD_FIRST_PHOTO_DESCRIPTION()}
</Typography> </Typography>
<span
style={{
cursor:
!uploadManager.shouldAllowNewUpload() &&
'not-allowed',
}}>
<Button <Button
color="accent" color="accent"
onClick={openUploader} onClick={openUploader}
disabled={!uploadManager.shouldAllowNewUpload()}
sx={{ mt: 4 }}> sx={{ mt: 4 }}>
{constants.UPLOAD_FIRST_PHOTO} {constants.UPLOAD_FIRST_PHOTO}
</Button> </Button>
</span>
</> </>
)} )}
</Wrapper> </Wrapper>

View file

@ -3,6 +3,7 @@ import { IconButton, styled } from '@mui/material';
import FileUploadOutlinedIcon from '@mui/icons-material/FileUploadOutlined'; import FileUploadOutlinedIcon from '@mui/icons-material/FileUploadOutlined';
import { Button } from '@mui/material'; import { Button } from '@mui/material';
import constants from 'utils/strings/constants'; import constants from 'utils/strings/constants';
import uploadManager from 'services/upload/uploadManager';
const Wrapper = styled('div')` const Wrapper = styled('div')`
display: flex; display: flex;
@ -28,14 +29,23 @@ interface Iprops {
} }
function UploadButton({ openUploader }: Iprops) { function UploadButton({ openUploader }: Iprops) {
return ( return (
<Wrapper onClick={openUploader}> <Wrapper
style={{
cursor: !uploadManager.shouldAllowNewUpload() && 'not-allowed',
}}>
<Button <Button
onClick={openUploader}
disabled={!uploadManager.shouldAllowNewUpload()}
className="desktop-button" className="desktop-button"
color="secondary" color="secondary"
startIcon={<FileUploadOutlinedIcon />}> startIcon={<FileUploadOutlinedIcon />}>
{constants.UPLOAD} {constants.UPLOAD}
</Button> </Button>
<IconButton className="mobile-button">
<IconButton
onClick={openUploader}
disabled={!uploadManager.shouldAllowNewUpload()}
className="mobile-button">
<FileUploadOutlinedIcon /> <FileUploadOutlinedIcon />
</IconButton> </IconButton>
</Wrapper> </Wrapper>

View file

@ -564,9 +564,7 @@ export default function Gallery() {
}; };
const openUploader = () => { const openUploader = () => {
if (!uploadInProgress) {
setUploadTypeSelectorView(true); setUploadTypeSelectorView(true);
}
}; };
return ( return (

View file

@ -545,6 +545,10 @@ class UploadManager {
const updatedFile = await appendNewFilePath(decryptedFile, filePath); const updatedFile = await appendNewFilePath(decryptedFile, filePath);
await updateFileMagicMetadata([updatedFile]); await updateFileMagicMetadata([updatedFile]);
} }
public shouldAllowNewUpload = () => {
return !this.uploadInProgress || watchFolderService.isUploadRunning();
};
} }
export default new UploadManager(); export default new UploadManager();