2020-10-30 20:34:04 +00:00
|
|
|
// Copyright 2019-2020 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2019-05-31 22:42:01 +00:00
|
|
|
import React from 'react';
|
|
|
|
import { isNumber } from 'lodash';
|
|
|
|
|
|
|
|
import { Countdown } from '../Countdown';
|
|
|
|
import { Spinner } from '../Spinner';
|
|
|
|
|
|
|
|
export type STATE_ENUM = 'idle' | 'countdown' | 'loading';
|
|
|
|
|
2020-08-26 20:31:41 +00:00
|
|
|
export type Props = {
|
2019-05-31 22:42:01 +00:00
|
|
|
state: STATE_ENUM;
|
|
|
|
duration?: number;
|
|
|
|
expiresAt?: number;
|
|
|
|
onComplete?: () => unknown;
|
|
|
|
};
|
|
|
|
|
|
|
|
const FAKE_DURATION = 1000;
|
|
|
|
|
|
|
|
export class TimelineLoadingRow extends React.PureComponent<Props> {
|
2020-09-14 19:51:27 +00:00
|
|
|
public renderContents(): JSX.Element {
|
2019-05-31 22:42:01 +00:00
|
|
|
const { state, duration, expiresAt, onComplete } = this.props;
|
|
|
|
|
|
|
|
if (state === 'idle') {
|
|
|
|
const fakeExpiresAt = Date.now() - FAKE_DURATION;
|
|
|
|
|
|
|
|
return <Countdown duration={FAKE_DURATION} expiresAt={fakeExpiresAt} />;
|
2020-09-14 19:51:27 +00:00
|
|
|
}
|
|
|
|
if (state === 'countdown' && isNumber(duration) && isNumber(expiresAt)) {
|
2019-05-31 22:42:01 +00:00
|
|
|
return (
|
|
|
|
<Countdown
|
|
|
|
duration={duration}
|
|
|
|
expiresAt={expiresAt}
|
|
|
|
onComplete={onComplete}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return <Spinner size="24" svgSize="small" direction="on-background" />;
|
|
|
|
}
|
|
|
|
|
2020-09-14 19:51:27 +00:00
|
|
|
public render(): JSX.Element {
|
2019-05-31 22:42:01 +00:00
|
|
|
return (
|
|
|
|
<div className="module-timeline-loading-row">{this.renderContents()}</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|