add attempt number to retry buttons

This commit is contained in:
Michael Peters 2023-01-22 16:19:17 -08:00
parent b30a3d87b7
commit f8ee502fee
2 changed files with 20 additions and 5 deletions

View File

@ -3,7 +3,7 @@ const electronConsole = electronRemote.getGlobal('console') as Console;
import Logger from '../../../../logger/logger'; import Logger from '../../../../logger/logger';
const LOG = Logger.create(__filename, electronConsole); const LOG = Logger.create(__filename, electronConsole);
import React, { FC } from 'react'; import React, { FC, useState } from 'react';
import { useAsyncSubmitButton } from '../require/react-helper'; import { useAsyncSubmitButton } from '../require/react-helper';
import Button from './button'; import Button from './button';
@ -17,13 +17,26 @@ export interface RetryProps {
const Retry: FC<RetryProps> = (props: RetryProps) => { const Retry: FC<RetryProps> = (props: RetryProps) => {
const { error, text, retryFunc } = props; const { error, text, retryFunc } = props;
const [attempts, setAttempts] = useState(0);
const [retryCallable, buttonText, buttonShaking] = useAsyncSubmitButton( const [retryCallable, buttonText, buttonShaking] = useAsyncSubmitButton(
async () => { async () => {
await retryFunc(); // error handled by effect try {
await retryFunc(); // error handled by effect
} catch (e: unknown) {
setAttempts(attempts => attempts + 1);
throw e;
}
setAttempts(0);
return { result: null, errorMessage: null }; return { result: null, errorMessage: null };
}, },
[retryFunc], [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 // TODO: shaking isn't working

View File

@ -30,11 +30,13 @@ import EnsuredFetchable from './fetchable-ensured';
import { EventEmitter } from 'tsee'; import { EventEmitter } from 'tsee';
import { AutoVerifierChangesType } from './auto-verifier'; import { AutoVerifierChangesType } from './auto-verifier';
import { IDQuery, PartialMessageListQuery } from './auto-verifier-with-args'; 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 */ /** 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 export default class CombinedGuild
extends EventEmitter<Connectable & Conflictable> extends EventEmitter<Connectable & Conflictable>
implements AsyncGuaranteedFetchable, AsyncRequestable { implements AsyncGuaranteedFetchable, AsyncRequestable
{
private readonly ramGuild: RAMGuild; private readonly ramGuild: RAMGuild;
private readonly personalDBGuild: PersonalDBGuild; private readonly personalDBGuild: PersonalDBGuild;
private readonly socketGuild: SocketGuild; private readonly socketGuild: SocketGuild;
@ -379,7 +381,7 @@ export default class CombinedGuild
return messages; return messages;
} }
async fetchMessagesBefore(channelId: string, messageOrderId: string, number: number): Promise<Message[]> { 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}`); LOG.debug(`g#${this.id}: fetch messages before ch#${channelId.slice(0, 4)}, mo#${messageOrderId}, ${number}`);
const members = await this.grabRAMMembersMap(); const members = await this.grabRAMMembersMap();
const channels = await this.grabRAMChannelsMap(); const channels = await this.grabRAMChannelsMap();