Skip to content

Commit

Permalink
Overwrite indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
scatwang committed Oct 27, 2024
1 parent 3142f96 commit bc26dce
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ const GoogleDriveUploadDialog: React.FunctionComponent = () => {
const isUploadFailed = useSelector(
(s) => s.explorer.googleDriveUploadDialog.isUploadFailed,
);
const overwroteExistingFile = useSelector(
(s) => s.explorer.googleDriveUploadDialog.overwroteExistingFile,
);

const inputRef = useRef<HTMLInputElement>(null);

Expand Down Expand Up @@ -122,6 +125,7 @@ const GoogleDriveUploadDialog: React.FunctionComponent = () => {
>
{fileName}
</a>
{(overwroteExistingFile && ' (Overwrote)') || ' (New file)'}
</div>
)}
{isUploadFailed && <div>Upload failed.</div>}
Expand Down
12 changes: 12 additions & 0 deletions src/explorer/googleDriveUploadDialog/reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ const uploadedDocId: Reducer<string> = (state = '', action) => {
return state;
};

const overwroteExistingFile: Reducer<boolean> = (state = false, action) => {
if (googleDriveUploadDialogShow.matches(action)) {
return false;
}
if (googleDriveDidUploadFile.matches(action)) {
return action.overwroteExistingFile;
}
return state;
};

const isUploadFailed: Reducer<boolean> = (state = false, action) => {
if (googleDriveUploadDialogShow.matches(action)) {
return false;
Expand All @@ -66,10 +76,12 @@ const isUploadFailed: Reducer<boolean> = (state = false, action) => {
}
return state;
};

export default combineReducers({
isOpen,
fileName,
descFolder,
uploadedDocId,
isUploadFailed,
overwroteExistingFile,
});
11 changes: 7 additions & 4 deletions src/googleDrive/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ export const googleDriveUploadFile = createAction(
}),
);

export const googleDriveDidUploadFile = createAction((uploadedFileId: string) => ({
type: 'googleDrive.action.didUploadFile',
uploadedFileId,
}));
export const googleDriveDidUploadFile = createAction(
(uploadedFileId: string, overwroteExistingFile: boolean) => ({
type: 'googleDrive.action.didUploadFile',
uploadedFileId,
overwroteExistingFile,
}),
);

export const googleDriveFailToUploadFile = createAction((err: Error) => ({
type: 'googleDrive.action.failToUploadFile',
Expand Down
2 changes: 1 addition & 1 deletion src/googleDrive/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ function* handleUploadFile(

const fileId = yield* call(() => uploadFile);

yield* put(googleDriveDidUploadFile(fileId));
yield* put(googleDriveDidUploadFile(fileId, existingFile !== undefined));
} catch (err) {
console.log('Failed to upload file to Google Drive:', err);
yield* put(googleDriveFailToUploadFile(ensureError(err)));
Expand Down

0 comments on commit bc26dce

Please sign in to comment.