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

MOBILE-4547 blog: Support offline blog #4043

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

alfonso-salces
Copy link
Member

No description provided.

@alfonso-salces alfonso-salces force-pushed the MOBILE-4547 branch 2 times, most recently from 087b0b8 to 88c2243 Compare May 10, 2024 12:45
@NoelDeMartin NoelDeMartin requested review from NoelDeMartin and dpalou and removed request for NoelDeMartin May 14, 2024 07:14
@alfonso-salces alfonso-salces changed the title MOBILE-4557 blog: Support offline blog MOBILE-4547 blog: Support offline blog May 14, 2024
src/addons/blog/pages/edit-entry/edit-entry.ts Outdated Show resolved Hide resolved
Comment on lines 253 to 257
if (!CoreNetwork.isOnline()) {
const attachmentsId = await this.uploadOrStoreFiles(this.entry.id);

return await this.saveEntry({ attachmentsId });
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This code is not enough, we also want to save the data if the server is down. This is how the app works in all other cases. This problem also happens when creating a new entry.

Also, if the user is editing an offline entry but he's online when the Save button is pressed you will create the entry twice, because this function will send the data to the server (creating the entry) but the app will still have the offline data that will be sent later when synchronised. This can be fixed with the "forceOffline" parameter I tell you below.

If you look at this calendar code you'll see that the "storeOffline" function is called in 3 cases:

  1. When the user is offline.
  2. If the "forceOffline" parameter is true. You should use this when the user is editing an offline entry, that way you will save the data in offline even if the user is online now, and the sync process will be the one to send the entry to the server. In order for this to work properly, the index page should try to synchronize the data when opened as we do in many other places, I'll leave another comment about this.
  3. If a WS call returns an error and it's not a "WebService error" (function CoreUtils.isWebServiceError). The WS calls can return errors like the ones telling you don't have permissions to do the action, in that case we don't want to store the data in offline because the user cannot perform the action. But if the error is not a WebService error, e.g. is an error 500, or a timeout or something like this we store the data to try again later.

This is just a personal opinion, but I usually prefer putting this logic to check network, erros and so on in a service instead of in the page (like calendar does). But if you prefer to leave it in the page it's ok for now since this is the only place creating entries.

src/addons/blog/pages/index/index.ts Outdated Show resolved Hide resolved
src/addons/blog/pages/index/index.ts Outdated Show resolved Hide resolved
src/addons/blog/pages/index/index.ts Outdated Show resolved Hide resolved
src/addons/blog/services/blog-sync.ts Outdated Show resolved Hide resolved
src/addons/blog/services/blog-sync.ts Outdated Show resolved Hide resolved
src/addons/blog/services/blog-sync.ts Outdated Show resolved Hide resolved
src/addons/blog/services/blog-sync.ts Outdated Show resolved Hide resolved
src/addons/blog/services/blog-sync.ts Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants