-
Notifications
You must be signed in to change notification settings - Fork 10
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
Users can now create agents (and interact with what's been cached) while offline #706
Draft
joshwingreene
wants to merge
5
commits into
develop
Choose a base branch
from
jgg-v3-manage-farms-while-offline
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+3,534
−66
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Rebase. This commit combines the following commits: feat(various): The service worker is now being set up properly. feat(various): Now caching json files as well so that the manifest.json file will be cached; Temporarily commenting out the initial LOADING... div feat(various): Now caching reponses from the backend and frontend (the bundle.js file) refactor(index): Re-added the preload div to the index file; Also, updated the generated service worker. feat(various): Installed idb; Now storing the fetched agents into indexed db so that any edits to them can be saved if the user goes offline feat(utility.js and sw.js): The types in the indexed db are now strongly typed. feat(various): Now reading the stored agents and displaying them in the DataTable when the user is offline fix(AgentListView): Now checking if indexedDB can be found before reading data from Indexed DB feat(various): Trying to implement BackgroundSync via Workbox. However, the failed POST request while the user is offline is not being replayed when the user's connection is restored. feat(various): Background sync is now functioning (after restarting my computer); Now able to open the UpdateAgentView when the user is offline feat(sw): Now handling edit agent requests when the user is offline feat(various): Now showing an offline fallback page for pages that haven't been cached; Changed the tsconfig target to ESNext for service worker purposes; Adding some additionally typing to the db utility file feat(various): Added the minifest css and js files for bootstrap into the public folder so it could be applied to the fallback page; Removed the handler that deals with edit agent requests feat(UpdateAgentView): Stopped the unable to load agent message from appearing when the user is offline but the selected agent was found in indexed db; Also, removed console logs and made AgentDetailForm code easier to understand. feat(various): Re-added the showEndlessErrorMessage notification; It is shown when the user goes offline. refactor(various): Refactored utlity.ts in order to resolve the eslint warnings; Working on getting background-sync to work again and getting the endless error message to always show feat(sw): Agents from the DataTable will now be stored into indexed db if the page is being shown to the user (no longer limited to 1 page) feat(various): Background sync is working again when creating new agents; Made it so that a endless notification appears when an agent is created while offline instead of adding the agent to the indexed db
build scripts; Added the code that I was using to try to figure out to resolve the current caching issue (separate files are being cached instead of a single bundle)
joshwingreene
requested review from
DropsOfSerenity and
fluturecode
as code owners
March 1, 2023 20:00
fluturecode
requested changes
Mar 16, 2023
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 looks good, however I noticed a few packages were added back that we are no longer using.
@testing-library/react
idb
moment
msw
react-moment
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
@DropsOfSerenity Okay. I have added everything that I felt was important. As we discussed, if you can fix the stuff related to the caching side of things, that would be great. I will take care of the pagination-related issues once you are done. If you have any questions, feel free to let me know via Slack.
Changes
offline.html
page will be shown instead.idb
package).sw.ts
file. This is the file that instructs the service worker on how to handle different requests. It will be used to generate thesw.js
file when the app is built.getRandomNumber
method out of the NetworkDetector component so that it could be used elsewheregetConnectionStatus
method to the NetworkDetector component's fileworkbox-config.js
filePurpose
An admin should be able to create Agents even without a connection.
Approach
I made use of
Workbox
and its various plugins to add the associated offline functionality to the app.The Issue
Previously, the only files and data that were initially cached in the cache called 'dynamic' were the following:
Now, the static bundle is no where to be found and it looks like all of the files in the bundle are being cached separately. Here's a screenshot:
Here's a couple of other issues:
The
offline.html
file is no longer being used when the user visits pages that haven't yet been cached yet. At the moment, it gives the standard "This site can't be reached" page.Opening an agent while online no longer works
The AgentListView won't be populated with agents while offline when there are agents in the indexed db.
Things that aren't broken
Learning
This is the video that gave me a jump start in integrating the newest version of Workbox into our boilerplate:
Workbox TypeScript - Unpacking the Workbox
These resources were very helpful as well:
workbox-background-sync
Managing fallback responses
Demo
offline.pr.-.demo.-.with.issues.mov
Testing Steps