Skip to content

Commit

Permalink
adding logic for removing from localStorage after saving to s3 and db
Browse files Browse the repository at this point in the history
relates to #163
  • Loading branch information
pbywater committed Aug 3, 2017
1 parent d82d023 commit 22dc096
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions public/scripts/s3-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,8 @@ function dataURLtoFile(dataurl, filename) {
}
return new File([u8arr], filename, { type: mime });
}

function removeImagesFromStorage() {
localStorage.removeItem('imageToSave');
localStorage.removeItem('tagAndHeading');
}
6 changes: 6 additions & 0 deletions public/scripts/s3-uploads.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ function getSignedRequest(file) {
imageUploadPending = true;
updateTagAndHeading(response.imageId);
} else {
removeImagesFromStorage();
return new Error('Could not get signed URL.');
}
}
Expand Down Expand Up @@ -69,6 +70,7 @@ function updateTagAndHeading(imageId) {
if (navigator.onLine && localStorage.getItem('imageTagAndHeading')) {
const tagAndHeading = localStorage.getItem('imageTagAndHeading');
addTagAndHeadingToDB(tagAndHeading.tag, tagAndHeading.heading, imageId);
localStorage.removeItem('imageToSave');
}
}

Expand All @@ -78,6 +80,10 @@ document.addEventListener('DOMContentLoaded', (event) => {
if (file) {
console.log('file is ', file);
getSignedRequest(file);
} else {
localStorage.removeItem('imageTagAndHeading');
}
} else if (localStorage.getItem('imageToSave')) {
localStorage.removeItem('imageToSave');
}
});

0 comments on commit 22dc096

Please sign in to comment.