2022-01-26 23:05:26 +00:00
|
|
|
// Copyright 2022 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import classNames from 'classnames';
|
|
|
|
import type { CSSProperties, ReactElement } from 'react';
|
2022-01-28 18:31:20 +00:00
|
|
|
import React, { useEffect, useState } from 'react';
|
2022-01-26 23:05:26 +00:00
|
|
|
import type { LocalizerType } from '../../types/Util';
|
|
|
|
import { TimelineDateHeader } from './TimelineDateHeader';
|
|
|
|
import { Spinner } from '../Spinner';
|
|
|
|
|
|
|
|
export const TimelineFloatingHeader = ({
|
|
|
|
i18n,
|
|
|
|
isLoading,
|
|
|
|
style,
|
|
|
|
timestamp,
|
|
|
|
visible,
|
|
|
|
}: Readonly<{
|
|
|
|
i18n: LocalizerType;
|
|
|
|
isLoading: boolean;
|
|
|
|
style?: CSSProperties;
|
|
|
|
timestamp: number;
|
|
|
|
visible: boolean;
|
2022-01-28 18:31:20 +00:00
|
|
|
}>): ReactElement => {
|
|
|
|
const [hasRendered, setHasRendered] = useState(false);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
setHasRendered(true);
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
return (
|
2022-01-26 23:05:26 +00:00
|
|
|
<div
|
|
|
|
className={classNames(
|
2022-01-28 18:31:20 +00:00
|
|
|
'TimelineFloatingHeader',
|
|
|
|
`TimelineFloatingHeader--${
|
|
|
|
visible && hasRendered ? 'visible' : 'hidden'
|
2022-01-26 23:05:26 +00:00
|
|
|
}`
|
|
|
|
)}
|
2022-01-28 18:31:20 +00:00
|
|
|
style={style}
|
2022-01-26 23:05:26 +00:00
|
|
|
>
|
2022-01-28 18:31:20 +00:00
|
|
|
<TimelineDateHeader floating i18n={i18n} timestamp={timestamp} />
|
|
|
|
<div
|
|
|
|
className={classNames(
|
|
|
|
'TimelineFloatingHeader__spinner-container',
|
|
|
|
`TimelineFloatingHeader__spinner-container--${
|
|
|
|
isLoading ? 'visible' : 'hidden'
|
|
|
|
}`
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
<Spinner direction="on-background" size="20px" svgSize="small" />
|
|
|
|
</div>
|
2022-01-26 23:05:26 +00:00
|
|
|
</div>
|
2022-01-28 18:31:20 +00:00
|
|
|
);
|
|
|
|
};
|