Skip to content

Commit

Permalink
Differentiate user being offline and API being offline
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaw3d committed Jun 22, 2023
1 parent 87f2e73 commit b964070
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 7 deletions.
1 change: 1 addition & 0 deletions .changelog/579.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Differentiate user being offline and API being offline
6 changes: 4 additions & 2 deletions src/app/components/OfflineBanner/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import { AppError, AppErrors } from '../../../types/errors'
import { useFormattedTimestampString } from '../../hooks/useFormattedTimestamp'
import { paraTimesConfig } from '../../../config'

export const useIsApiOffline = (network: Network): boolean => {
export const useIsApiOffline = (network: Network): false | 'userOffline' | 'apiOffline' => {
const query = useGetStatus(network)
return query.isFetched && !query.isSuccess
if (query.isPaused) return 'userOffline'
if (query.isFetched && !query.isSuccess) return 'apiOffline'
return false
}

export type FreshnessInfo = {
Expand Down
10 changes: 7 additions & 3 deletions src/app/components/OfflineBanner/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@ export const NetworkOfflineBanner: FC<{ wantedNetwork?: Network }> = ({ wantedNe
const isNetworkOffline = useIsApiOffline(targetNetwork)
const networkNames = getNetworkNames(t)
const target = networkNames[targetNetwork]
return isNetworkOffline ? (
<StyledAlert severity="warning">{t('home.apiOffline', { target })}</StyledAlert>
) : null
if (isNetworkOffline === 'userOffline') {
return <StyledAlert severity="warning">{t('home.userOffline', { target })}</StyledAlert>
}
if (isNetworkOffline === 'apiOffline') {
return <StyledAlert severity="warning">{t('home.apiOffline', { target })}</StyledAlert>
}
return null
}

export const RuntimeOfflineBanner: FC = () => {
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/PageLayout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export const PageLayout: FC<PropsWithChildren<PageLayoutProps>> = ({ children, m
mb: 6,
}}
>
<Search scope={scope} variant={isTablet ? 'icon' : 'button'} disabled={isApiOffline} />
<Search scope={scope} variant={isTablet ? 'icon' : 'button'} disabled={!!isApiOffline} />
</Box>
)}
<StyledMain>{children}</StyledMain>
Expand Down
2 changes: 1 addition & 1 deletion src/app/pages/HomePage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export const HomePage: FC = () => {
</LogotypeBox>
<SearchInputContainer>
<SearchInputBox>
<Search disabled={isApiOffline} variant={searchVariant} onFocusChange={onFocusChange} />
<Search disabled={!!isApiOffline} variant={searchVariant} onFocusChange={onFocusChange} />
</SearchInputBox>
</SearchInputContainer>
<ThemeByNetwork network={network}>
Expand Down
1 change: 1 addition & 0 deletions src/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@
},
"home": {
"apiOffline": "Our {{ target }} API is offline. We’re trying to reconnect",
"userOffline": "You are offline. We’re trying to reconnect",
"runtimeOutOfDate": "We don't have fully up-to-date data about our {{ target }}. The data displayed here might be out of date.",
"runtimeOutOfDateSince": "The last update we have about our {{ target }} is from {{ lastUpdate }}. The data displayed here might be out of date.",
"blocks": "Blocks",
Expand Down

0 comments on commit b964070

Please sign in to comment.