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

Adding text memories offline #168

Merged
merged 11 commits into from
Aug 5, 2017
Merged

Adding text memories offline #168

merged 11 commits into from
Aug 5, 2017

Conversation

pbywater
Copy link
Owner

@pbywater pbywater commented Aug 2, 2017

  • Changes deletePendingMemories helper to processPendingMemories to deal with both adding and deleting
  • Saves memory to local storage and generates a temporary fake id to allow memory to appear in the DOM
  • Makes the POST request when back online and removes temporary memories from local storage

Relates to #163

@pbywater pbywater requested a review from a user August 2, 2017 13:32
const heading = splitData[0].split('=')[1];
const text = splitData[1].split('=')[1];
const tag = splitData[2].split('=')[1];
const id = getRandomInt(10000, 999999);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not convinced by this approach to id generation

Copy link
Collaborator

Choose a reason for hiding this comment

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

  1. Use uuid or something similar for client side id generation.
  2. Either generate ids on the server, or on the client, do not do some mixture of the 2.

If 2 is too difficult, you could try and generate some kind of temporary id on the client, then replace it with the one generated by the db..

Copy link
Owner Author

Choose a reason for hiding this comment

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

This is just temporary - a real id is created in the normal way once the user goes back online

Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

} else {
const data = $('#add-text-form').serialize();
const splitData = data.split('&');
const heading = splitData[0].split('=')[1];
Copy link
Collaborator

Choose a reason for hiding this comment

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

Dont do this, just get the data from each field separately.

Copy link
Collaborator

Choose a reason for hiding this comment

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

ie heading = $('sel').value

Copy link
Owner Author

Choose a reason for hiding this comment

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

Tried this but I'm getting undefined :(

@@ -287,6 +296,21 @@ function deletePendingMemories(cb) {
cb();
})
}
if(localStorage.getItem('textToAdd') !== null) {
const newTextMemories = JSON.parse(localStorage.getItem('textToAdd'));
Copy link
Collaborator

Choose a reason for hiding this comment

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

indentation

@@ -287,6 +296,21 @@ function deletePendingMemories(cb) {
cb();
Copy link
Collaborator

Choose a reason for hiding this comment

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

?? How many times does this callback get called

Copy link
Owner Author

Choose a reason for hiding this comment

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

Every time something is deleted I think! Haha - I think we discussed before and said it wasn't ideal but would be ok due to time constraints?

data: {memory_text: text, heading, tag},
success: () => clearPendingActions('textToAdd', index),
});
cb();
Copy link
Collaborator

Choose a reason for hiding this comment

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

How many times does this callback get called / this does not make any sense / this is broken

Copy link
Owner Author

Choose a reason for hiding this comment

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

😭 - it's rerendering after each update so if there are several updates, there are several transitions. Is there a better way to do it?

offlineData.push(toAdd);
const offlineDataAfterAdding = JSON.stringify(offlineData);
localStorage.setItem('data', offlineDataAfterAdding);
return offlineData;
Copy link
Collaborator

Choose a reason for hiding this comment

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

indentation

@des-des des-des assigned pbywater and unassigned des-des Aug 3, 2017
@pbywater pbywater assigned des-des and unassigned pbywater Aug 3, 2017
@des-des des-des merged commit f264cf3 into master Aug 5, 2017
@des-des des-des deleted the offline-text-node branch August 5, 2017 10:59
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