2020-10-30 20:34:04 +00:00
|
|
|
// Copyright 2020 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2020-02-12 21:30:58 +00:00
|
|
|
import * as React from 'react';
|
|
|
|
import { storiesOf } from '@storybook/react';
|
|
|
|
import { boolean, select } from '@storybook/addon-knobs';
|
|
|
|
import { action } from '@storybook/addon-actions';
|
|
|
|
|
2020-09-12 00:46:52 +00:00
|
|
|
import { NetworkStatus } from './NetworkStatus';
|
2021-06-09 22:28:54 +00:00
|
|
|
import { SocketStatus } from '../types/SocketStatus';
|
2020-09-12 00:46:52 +00:00
|
|
|
import { setup as setupI18n } from '../../js/modules/i18n';
|
|
|
|
import enMessages from '../../_locales/en/messages.json';
|
|
|
|
|
2020-02-12 21:30:58 +00:00
|
|
|
const i18n = setupI18n('en', enMessages);
|
|
|
|
|
|
|
|
const defaultProps = {
|
|
|
|
hasNetworkDialog: true,
|
|
|
|
i18n,
|
|
|
|
isOnline: true,
|
2021-06-09 22:28:54 +00:00
|
|
|
socketStatus: SocketStatus.CONNECTING,
|
2020-03-20 18:01:55 +00:00
|
|
|
manualReconnect: action('manual-reconnect'),
|
2020-02-12 21:30:58 +00:00
|
|
|
withinConnectingGracePeriod: false,
|
2021-05-06 00:09:29 +00:00
|
|
|
challengeStatus: 'idle' as const,
|
2020-02-12 21:30:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const permutations = [
|
|
|
|
{
|
|
|
|
title: 'Connecting',
|
|
|
|
props: {
|
2021-06-09 22:28:54 +00:00
|
|
|
socketStatus: SocketStatus.CONNECTING,
|
2020-02-12 21:30:58 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Closing (online)',
|
|
|
|
props: {
|
2021-06-09 22:28:54 +00:00
|
|
|
socketStatus: SocketStatus.CLOSING,
|
2020-02-12 21:30:58 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Closed (online)',
|
|
|
|
props: {
|
2021-06-09 22:28:54 +00:00
|
|
|
socketStatus: SocketStatus.CLOSED,
|
2020-02-12 21:30:58 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2020-03-20 18:01:55 +00:00
|
|
|
title: 'Offline',
|
2020-02-12 21:30:58 +00:00
|
|
|
props: {
|
|
|
|
isOnline: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
storiesOf('Components/NetworkStatus', module)
|
|
|
|
.add('Knobs Playground', () => {
|
|
|
|
const hasNetworkDialog = boolean('hasNetworkDialog', true);
|
|
|
|
const isOnline = boolean('isOnline', true);
|
|
|
|
const socketStatus = select(
|
|
|
|
'socketStatus',
|
|
|
|
{
|
2021-06-09 22:28:54 +00:00
|
|
|
CONNECTING: SocketStatus.CONNECTING,
|
|
|
|
OPEN: SocketStatus.OPEN,
|
|
|
|
CLOSING: SocketStatus.CLOSING,
|
|
|
|
CLOSED: SocketStatus.CLOSED,
|
2020-02-12 21:30:58 +00:00
|
|
|
},
|
2021-06-09 22:28:54 +00:00
|
|
|
SocketStatus.CONNECTING
|
2020-02-12 21:30:58 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<NetworkStatus
|
|
|
|
{...defaultProps}
|
|
|
|
hasNetworkDialog={hasNetworkDialog}
|
|
|
|
isOnline={isOnline}
|
|
|
|
socketStatus={socketStatus}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
})
|
|
|
|
.add('Iterations', () => {
|
|
|
|
return permutations.map(({ props, title }) => (
|
|
|
|
<>
|
|
|
|
<h3>{title}</h3>
|
|
|
|
<NetworkStatus {...defaultProps} {...props} />
|
|
|
|
</>
|
|
|
|
));
|
|
|
|
});
|