2023-01-03 19:55:46 +00:00
|
|
|
// Copyright 2020 Signal Messenger, LLC
|
2020-10-30 20:34:04 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2021-09-17 22:20:49 +00:00
|
|
|
import React, { useEffect } from 'react';
|
2020-02-12 21:30:58 +00:00
|
|
|
|
2021-09-17 22:20:49 +00:00
|
|
|
import { LeftPaneDialog } from './LeftPaneDialog';
|
2021-08-19 22:56:29 +00:00
|
|
|
import { Spinner } from './Spinner';
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { LocalizerType } from '../types/Util';
|
2021-06-09 22:28:54 +00:00
|
|
|
import { SocketStatus } from '../types/SocketStatus';
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { NetworkStateType } from '../state/ducks/network';
|
2021-10-12 23:59:08 +00:00
|
|
|
import type { WidthBreakpoint } from './_util';
|
2022-02-25 18:37:15 +00:00
|
|
|
import { clearTimeoutIfNecessary } from '../util/clearTimeoutIfNecessary';
|
2020-02-12 21:30:58 +00:00
|
|
|
|
2020-03-20 18:01:55 +00:00
|
|
|
const FIVE_SECONDS = 5 * 1000;
|
|
|
|
|
2024-03-12 19:52:02 +00:00
|
|
|
export type PropsType = Pick<
|
|
|
|
NetworkStateType,
|
|
|
|
'isOnline' | 'isOutage' | 'socketStatus'
|
|
|
|
> & {
|
2021-10-12 23:59:08 +00:00
|
|
|
containerWidthBreakpoint: WidthBreakpoint;
|
2020-02-12 21:30:58 +00:00
|
|
|
i18n: LocalizerType;
|
2020-03-20 18:01:55 +00:00
|
|
|
manualReconnect: () => void;
|
2021-01-14 18:07:05 +00:00
|
|
|
};
|
2020-02-12 21:30:58 +00:00
|
|
|
|
2022-11-18 00:45:19 +00:00
|
|
|
export function DialogNetworkStatus({
|
2021-10-12 23:59:08 +00:00
|
|
|
containerWidthBreakpoint,
|
2020-02-12 21:30:58 +00:00
|
|
|
i18n,
|
|
|
|
isOnline,
|
2024-03-12 19:52:02 +00:00
|
|
|
isOutage,
|
2020-02-12 21:30:58 +00:00
|
|
|
socketStatus,
|
2020-03-20 18:01:55 +00:00
|
|
|
manualReconnect,
|
2022-11-18 00:45:19 +00:00
|
|
|
}: PropsType): JSX.Element | null {
|
2021-09-17 22:20:49 +00:00
|
|
|
const [isConnecting, setIsConnecting] = React.useState<boolean>(
|
|
|
|
socketStatus === SocketStatus.CONNECTING
|
|
|
|
);
|
|
|
|
useEffect(() => {
|
2020-09-12 00:46:52 +00:00
|
|
|
let timeout: NodeJS.Timeout;
|
2020-03-20 18:01:55 +00:00
|
|
|
|
|
|
|
if (isConnecting) {
|
|
|
|
timeout = setTimeout(() => {
|
|
|
|
setIsConnecting(false);
|
|
|
|
}, FIVE_SECONDS);
|
|
|
|
}
|
|
|
|
|
|
|
|
return () => {
|
2022-02-25 18:37:15 +00:00
|
|
|
clearTimeoutIfNecessary(timeout);
|
2020-03-20 18:01:55 +00:00
|
|
|
};
|
2023-01-18 23:31:10 +00:00
|
|
|
}, [isConnecting, setIsConnecting]);
|
2020-09-12 00:46:52 +00:00
|
|
|
|
2020-03-20 18:01:55 +00:00
|
|
|
const reconnect = () => {
|
|
|
|
setIsConnecting(true);
|
|
|
|
manualReconnect();
|
|
|
|
};
|
|
|
|
|
2024-03-12 19:52:02 +00:00
|
|
|
if (isOutage) {
|
|
|
|
return (
|
|
|
|
<LeftPaneDialog
|
|
|
|
containerWidthBreakpoint={containerWidthBreakpoint}
|
|
|
|
type="warning"
|
|
|
|
icon="error"
|
|
|
|
subtitle={i18n('icu:DialogNetworkStatus__outage')}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-09-17 22:20:49 +00:00
|
|
|
if (isConnecting) {
|
|
|
|
const spinner = (
|
|
|
|
<div className="LeftPaneDialog__spinner-container">
|
|
|
|
<Spinner
|
|
|
|
direction="on-avatar"
|
|
|
|
moduleClassName="LeftPaneDialog__spinner"
|
|
|
|
size="22px"
|
|
|
|
svgSize="small"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<LeftPaneDialog
|
2021-10-12 23:59:08 +00:00
|
|
|
containerWidthBreakpoint={containerWidthBreakpoint}
|
2021-09-17 22:20:49 +00:00
|
|
|
type="warning"
|
|
|
|
icon={spinner}
|
2023-03-30 00:03:25 +00:00
|
|
|
title={i18n('icu:connecting')}
|
|
|
|
subtitle={i18n('icu:connectingHangOn')}
|
2021-09-17 22:20:49 +00:00
|
|
|
/>
|
|
|
|
);
|
2020-02-12 21:30:58 +00:00
|
|
|
}
|
|
|
|
|
2021-09-17 22:20:49 +00:00
|
|
|
return (
|
|
|
|
<LeftPaneDialog
|
2021-10-12 23:59:08 +00:00
|
|
|
containerWidthBreakpoint={containerWidthBreakpoint}
|
2021-09-17 22:20:49 +00:00
|
|
|
type="warning"
|
|
|
|
icon="network"
|
2023-03-30 00:03:25 +00:00
|
|
|
title={isOnline ? i18n('icu:disconnected') : i18n('icu:offline')}
|
|
|
|
subtitle={i18n('icu:checkNetworkConnection')}
|
2021-09-17 22:20:49 +00:00
|
|
|
hasAction
|
2023-03-30 00:03:25 +00:00
|
|
|
clickLabel={i18n('icu:connect')}
|
2021-09-17 22:20:49 +00:00
|
|
|
onClick={reconnect}
|
|
|
|
/>
|
|
|
|
);
|
2022-11-18 00:45:19 +00:00
|
|
|
}
|