mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2026-02-15 07:28:59 +00:00
40 lines
996 B
TypeScript
40 lines
996 B
TypeScript
// Copyright 2018 Signal Messenger, LLC
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
import React, { useEffect, useReducer } from 'react';
|
|
import classNames from 'classnames';
|
|
|
|
import { getIncrement, getTimerBucket } from '../../util/timer.std.js';
|
|
|
|
export type Props = Readonly<{
|
|
expirationLength: number;
|
|
expirationTimestamp?: number;
|
|
}>;
|
|
|
|
export function ExpireTimer({
|
|
expirationLength,
|
|
expirationTimestamp,
|
|
}: Props): React.JSX.Element {
|
|
const [, forceUpdate] = useReducer(() => ({}), {});
|
|
|
|
useEffect(() => {
|
|
const increment = getIncrement(expirationLength);
|
|
const updateFrequency = Math.max(increment, 500);
|
|
const interval = setInterval(forceUpdate, updateFrequency);
|
|
return () => {
|
|
clearInterval(interval);
|
|
};
|
|
}, [expirationLength]);
|
|
|
|
const bucket = getTimerBucket(expirationTimestamp, expirationLength);
|
|
|
|
return (
|
|
<div
|
|
className={classNames(
|
|
'module-expire-timer',
|
|
`module-expire-timer--${bucket}`
|
|
)}
|
|
/>
|
|
);
|
|
}
|