Skip to content

Commit

Permalink
docs: custom status message
Browse files Browse the repository at this point in the history
  • Loading branch information
KaiVandivier committed Dec 11, 2023
1 parent 3015a9a commit 93351bb
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
46 changes: 46 additions & 0 deletions docs/advanced/offline/CustomOnlineStatusMessage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Custom Connection Status Message

By default, the header bar shows either an "Online" or "Offline" message based on whether the app can connect to the DHIS2 server. If it's useful for an app to share other relevant info in that badge, for example "3 changes saved locally", then it's possible to set a custom message there:

![Custom online status message](custom-online-status-message.png)

## Hooks

```ts
import {
useSetOnlineStatusMessage,
useOnlineStatusMessageValue,
useOnlineStatusMessage,
} from '@dhis2/app-runtime'
```

### `useSetOnlineStatusMessage`

It's most likely that you'll only use `useSetOnlineStatusMessage()`, a hook that returns a `setState` function. It can set the value in the Header Bar without causing a rerender for itself.

`setOnlineStatusMessage()` accepts a `ReactNode`-type object, so icons or other components can be added to the badge, but don't go crazy. A simple string is also a valid `ReactNode`:

```ts
const setOnlineStatusMessage: (message: ReactNode) => void =
useSetOnlineStatusMessage()
```

### `useOnlineStatusMessageValue`

This hook returns just the value:

```ts
const onlineStatusMessage: ReactNode = useOnlineStatusMessageValue()
```

### `useOnlineStatusMessage`

This hook returns both the value and the `set` function:

```ts
const { onlineMessage, setOnlineStatusMessage } = useOnlineStatusMessage()
```

## Example

You can see an example in use in the [Aggregate Data Entry app](https://github.com/dhis2/aggregate-data-entry-app/blob/dadd61392ea010a8017a19a25eaf76f885d9eea7/src/data-workspace/use-handle-headerbar-status.js)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions docs/advanced/offline/useDhis2ConnectionStatus.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ This hook is used to detect whether or not the app can connect to the DHIS2 serv

It's designed to detect server connection because checking just the internet connection can lead to problems on DHIS2 instances that are implemented offline, where features or actions might be blocked because the device is offline, even though the app can connect to the DHIS2 server just fine. In these cases, what matters is whether or not the app can connect to the DHIS2 server.

This what the DHIS2 Header Bar uses to show an "Online" or "Offline" badge.

```ts
import { useDhis2ConnectionStatus } from '@dhis2/app-runtime'

Expand Down

0 comments on commit 93351bb

Please sign in to comment.