add attempt number to retry buttons
This commit is contained in:
parent
b30a3d87b7
commit
f8ee502fee
@ -3,7 +3,7 @@ const electronConsole = electronRemote.getGlobal('console') as Console;
|
||||
import Logger from '../../../../logger/logger';
|
||||
const LOG = Logger.create(__filename, electronConsole);
|
||||
|
||||
import React, { FC } from 'react';
|
||||
import React, { FC, useState } from 'react';
|
||||
import { useAsyncSubmitButton } from '../require/react-helper';
|
||||
import Button from './button';
|
||||
|
||||
@ -17,13 +17,26 @@ export interface RetryProps {
|
||||
const Retry: FC<RetryProps> = (props: RetryProps) => {
|
||||
const { error, text, retryFunc } = props;
|
||||
|
||||
const [attempts, setAttempts] = useState(0);
|
||||
|
||||
const [retryCallable, buttonText, buttonShaking] = useAsyncSubmitButton(
|
||||
async () => {
|
||||
try {
|
||||
await retryFunc(); // error handled by effect
|
||||
} catch (e: unknown) {
|
||||
setAttempts(attempts => attempts + 1);
|
||||
throw e;
|
||||
}
|
||||
setAttempts(0);
|
||||
return { result: null, errorMessage: null };
|
||||
},
|
||||
[retryFunc],
|
||||
{ start: 'Try Again', pending: 'Fetching...', done: 'Try Again', error: 'Try Again' },
|
||||
{
|
||||
start: `Try Again ${attempts ? `#${attempts + 1}` : ''}`,
|
||||
pending: 'Fetching...',
|
||||
done: `Try Again ${attempts ? `#${attempts + 1}` : ''}`,
|
||||
error: `Try Again ${attempts ? `#${attempts + 1}` : ''}`,
|
||||
},
|
||||
);
|
||||
|
||||
// TODO: shaking isn't working
|
||||
|
@ -30,11 +30,13 @@ import EnsuredFetchable from './fetchable-ensured';
|
||||
import { EventEmitter } from 'tsee';
|
||||
import { AutoVerifierChangesType } from './auto-verifier';
|
||||
import { IDQuery, PartialMessageListQuery } from './auto-verifier-with-args';
|
||||
import Util from './util';
|
||||
|
||||
/** the general guild class. This handles connecting a RAM, PersonalDB, and Socket guild together using fetchable-pair-verifiers and some manual caching to nicely update messages */
|
||||
export default class CombinedGuild
|
||||
extends EventEmitter<Connectable & Conflictable>
|
||||
implements AsyncGuaranteedFetchable, AsyncRequestable {
|
||||
implements AsyncGuaranteedFetchable, AsyncRequestable
|
||||
{
|
||||
private readonly ramGuild: RAMGuild;
|
||||
private readonly personalDBGuild: PersonalDBGuild;
|
||||
private readonly socketGuild: SocketGuild;
|
||||
@ -379,7 +381,7 @@ export default class CombinedGuild
|
||||
return messages;
|
||||
}
|
||||
async fetchMessagesBefore(channelId: string, messageOrderId: string, number: number): Promise<Message[]> {
|
||||
// xUtil.failSometimes(0.05); // for testing
|
||||
Util.failSometimes(0.75); // for testing
|
||||
LOG.debug(`g#${this.id}: fetch messages before ch#${channelId.slice(0, 4)}, mo#${messageOrderId}, ${number}`);
|
||||
const members = await this.grabRAMMembersMap();
|
||||
const channels = await this.grabRAMChannelsMap();
|
||||
|
Loading…
Reference in New Issue
Block a user