Skip to content

Commit 6213ad5

Browse files
authored
Merge pull request #180 from NMFS-RADFish/178-update-app-container
178 - Update application container documentation
2 parents 53c6cbc + b66a867 commit 6213ad5

File tree

1 file changed

+53
-23
lines changed

1 file changed

+53
-23
lines changed

docs/design-system/custom-components/application-container.md

Lines changed: 53 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,74 @@ sidebar_position: 1
44

55
# Application Container
66

7-
The `Application` container handles network status changes and displays appropriate toast notifications. It has **built-in** functionality that automatically handles these changes.
7+
The Application container handles core application-wide functionality, including service worker integration, custom storage management, and network status detection. It provides a centralized way to manage these features within your app.
88

99
## Features
1010

11-
- **Built-in Offline/Online Notifications**: The `Application` component monitors the network status. It shows toast messages when the app goes offline or comes back online.
12-
- **Custom Hooks**: It leverages the `useToasts` and `useOfflineStatus` hooks from within `@nmfs-radfish/react-radfish` package.
11+
1. **Service Worker for Offline Caching**
1312

14-
## How It Works
13+
The Application container supports service worker integration, enabling offline capabilities by caching static assets and handling API requests when the network is unavailable.
1514

16-
### Built-in Offline/Online Notifications
15+
2. **Pluggable Storage**
1716

18-
The `Application` component has **built-in** functionality to check the application's network status. It displays toast notifications when the state changes:
17+
Pass in IndexedDB or LocalStorage storage methods.
1918

20-
- **When the application goes offline**: A warning toast is displayed with the message `"Application is offline"`.
21-
- **When the application comes back online**: An info toast is displayed with the message `"Application is online"`.
19+
3. **Offline/Online Detection**
2220

23-
This feature is provided **out of the box** and requires no additional setup from your side.
21+
Automatically detects network changes and displays toast notifications:
2422

25-
### Example Usage
23+
- Offline: Shows a warning toast with "Application is offline".
24+
- Online: Shows an informational toast with "Application is online".
2625

27-
To use the `Application` component, wrap it around your app in the entry file (e.g. `index.js` or `index.jsx`):
26+
## Usage
27+
28+
### Setting up Application instance
29+
30+
To use the `Application` container, instantiate it with your desired configuration:
2831

2932
```jsx
30-
import { Application } from "@nmfs-radfish/react-radfish";
33+
import { Application } from "@nmfs-radfish/radfish";
34+
35+
const myApp = new Application({
36+
serviceWorker: {
37+
url:
38+
import.meta.env.MODE === "development"
39+
? "/mockServiceWorker.js"
40+
: "/service-worker.js",
41+
},
42+
storage: store, // Use IndexedDBMethod or LocalStorageMethod for offline storage
43+
});
44+
```
45+
46+
### Using `<Application>`
47+
48+
Once instantiated, the `Application` instance should be passed to the `<Application>` component.
3149

32-
function App () {
33-
return (
34-
<Application>
35-
{ /* Your application code */ }
36-
</Application>
37-
);
38-
}
50+
```jsx
51+
import { Application } from "@nmfs-radfish/react-radfish";
3952

40-
export default App;
53+
<Application application={myApp} />;
4154
```
4255

43-
<!-- ### Extending Functionality with Hooks
56+
## Distinguishing `Application` from `@nmfs-radfish/radfish` vs. `@nmfs-radfish/react-radfish`
57+
58+
### `@nmfs-radfish/radfish` (Core)
59+
60+
- Provides the underlying **non-UI logic**, such as the `Application` class for managing:
61+
- **Offline support**
62+
- **Service workers**
63+
- **Storage (IndexedDB, LocalStorage)**
64+
65+
### `@nmfs-radfish/react-radfish` (React Integration)
66+
67+
- Offers **React components and hooks** that make it easy to integrate `Application` container into a React app.
68+
- Provides:
69+
- `<Application>` component for wrapping your app with offline support.
70+
- Hooks like `useOfflineStatus` for checking network connectivity.
71+
- `useOfflineStorage` for managing offline storage state within React components.
72+
- This package is **React-specific** and simplifies working with the `Application` container in a React project.
4473

45-
While the `Application` component provides **out-of-the-box** functionality for network status notifications, you can also use RADFish's custom hooks—`useToasts` and `useOfflineStatus`—independently for more control over toast messages and offline status in other parts of your application.
74+
#### In Other Words:
4675

47-
For more information on how to use these hooks, refer to the [RADFish Custom Hooks Documentation](link-to-hooks-documentation). -->
76+
- **`@nmfs-radfish/radfish`** = the **engine** (all the logic).
77+
- **`@nmfs-radfish/react-radfish`** = the **React car** that sits on top of the engine, making it easy to drive your offline-ready web app in React.

0 commit comments

Comments
 (0)