mirror of
https://github.com/lux-tel/session-desktop.git
synced 2026-10-30 20:33:24 +00:00
28 lines
1007 B
TypeScript
28 lines
1007 B
TypeScript
import useAsyncFn from 'react-use/lib/useAsyncFn';
|
|
import { WithMessageId } from '../../../../session/types/with';
|
|
import { useMessageDirection, useMessageStatus } from '../../../../state/selectors';
|
|
import { ItemWithDataTestId } from '../MenuItemWithDataTestId';
|
|
import { Data } from '../../../../data/data';
|
|
import { tr } from '../../../../localization/localeTools';
|
|
|
|
export const RetryItem = ({ messageId }: WithMessageId) => {
|
|
const direction = useMessageDirection(messageId);
|
|
|
|
const status = useMessageStatus(messageId);
|
|
const isOutgoing = direction === 'outgoing';
|
|
|
|
const showRetry = status === 'error' && isOutgoing;
|
|
|
|
const [, doResend] = useAsyncFn(async () => {
|
|
const found = await Data.getMessageById(messageId);
|
|
if (found) {
|
|
await found.retrySend();
|
|
}
|
|
}, [messageId]);
|
|
|
|
return showRetry ? (
|
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
<ItemWithDataTestId onClick={() => doResend()}>{tr('resend')}</ItemWithDataTestId>
|
|
) : null;
|
|
};
|