-
Notifications
You must be signed in to change notification settings - Fork 0
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
Conversation
const heading = splitData[0].split('=')[1]; | ||
const text = splitData[1].split('=')[1]; | ||
const tag = splitData[2].split('=')[1]; | ||
const id = getRandomInt(10000, 999999); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Use uuid or something similar for client side id generation.
- 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..
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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]; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ie heading = $('sel').value
There was a problem hiding this comment.
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 :(
src/client/helpers/helpers.js
Outdated
@@ -287,6 +296,21 @@ function deletePendingMemories(cb) { | |||
cb(); | |||
}) | |||
} | |||
if(localStorage.getItem('textToAdd') !== null) { | |||
const newTextMemories = JSON.parse(localStorage.getItem('textToAdd')); |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
src/client/helpers/helpers.js
Outdated
data: {memory_text: text, heading, tag}, | ||
success: () => clearPendingActions('textToAdd', index), | ||
}); | ||
cb(); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
src/client/helpers/helpers.js
Outdated
offlineData.push(toAdd); | ||
const offlineDataAfterAdding = JSON.stringify(offlineData); | ||
localStorage.setItem('data', offlineDataAfterAdding); | ||
return offlineData; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indentation
Relates to #163