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

feat: add a progression view for media backup #184

Merged
merged 4 commits into from
Mar 22, 2017
Merged

feat: add a progression view for media backup #184

merged 4 commits into from
Mar 22, 2017

Conversation

enguerran
Copy link
Contributor

@enguerran enguerran commented Mar 17, 2017

We could use Alerter from cozy-ui but it seems not correct for this kind of progression message (see @goldoraf and @gregorylegarec for more information).

So the UploadProgression component is the very same UI than an Alerter, but it did not have the same behavior, it is very simpler: if a message is display, it is shown, otherwise it is not.

Hope it fits the needs.

vgdmi9t

@enguerran enguerran requested a review from kosssi March 17, 2017 12:11
@enguerran enguerran self-assigned this Mar 17, 2017

export const startMediaUpload = () => ({ type: MEDIA_UPLOAD_START })
export const endMediaUpload = () => ({ type: MEDIA_UPLOAD_END })
export const successImageUpload = (image) => ({ type: IMAGE_UPLOAD_SUCCESS, id: image.id })
export const successImageUpload = (media) => ({ type: IMAGE_UPLOAD_SUCCESS, id: media.id })
Copy link
Contributor

@kosssi kosssi Mar 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you change (image) to (media)? (we have successImageUpload and IMAGE_UPLOAD_SUCCESS)

This is not blocking

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't backup images but photos. And soon we won't upload photos but photos and videos. So I think media is a good shell to address all the needs.

@@ -33,8 +45,11 @@ export const mediaBackup = (dir) => async (dispatch, getState) => {
let photos = await getFilteredPhotos()
const alreadyUploaded = getState().mobile.mediaBackup.uploaded
const dirID = await getDirID(dir)
const totalUpload = photos.length - alreadyUploaded.length
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not good here.
I think you can filter photos like that:

photos = photos.filter(photo => !alreadyUploaded.includes(photo.id))
const totalUpload = photos.length

and remove if (!alreadyUploaded.includes(photo.id)) { line 51

Copy link
Contributor Author

@enguerran enguerran Mar 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I needed to get the total of going to be uploaded photos.

I think that

photos.length - alreadyUploaded.length === photos.filter(photo => !alreadyUploaded.includes(photo.id)).length

So this remark, though good enough, is just a matter of refactoring.

And as this code is not covered by tests, I refused to refactor it (red ⇒ green ⇒ refactor).

Copy link
Contributor

@kosssi kosssi Mar 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Precisely it's not the same.

If a user deletes already uploaded photos, they will count in alreadyUploaded but not in photos, which will distort the calculation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a very good remark. Please find 77a6a49 to fix this.

case IMAGE_UPLOAD_SUCCESS:
return { ...state, uploaded: [...state.uploaded, action.id] }
return { ...state, uploaded: [...state.uploaded, action.id], currentUpload: undefined }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you do that (currentUpload: undefined) for each photo, the UploadProgression component will blinking...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good remarks, it is an oversight.

@enguerran
Copy link
Contributor Author

enguerran commented Mar 22, 2017

@kosssi did you have something else to add or do you approve this PR?

I added a spinner

screenshot at 12-25-16

@@ -27,21 +39,25 @@ async function getDirID (dir) {

export const mediaBackup = (dir) => async (dispatch, getState) => {
if (backupAllowed(getState().mobile.settings.wifiOnly)) {
let photos = await getFilteredPhotos()
const photosOnDevice = await getFilteredPhotos()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@kosssi kosssi self-requested a review March 22, 2017 14:36
@enguerran
Copy link
Contributor Author

Alright

@enguerran enguerran merged commit 9156d5b into cozy:master Mar 22, 2017
@enguerran enguerran deleted the backup.progression branch March 22, 2017 14:44
m4dz pushed a commit that referenced this pull request Mar 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants