diff --git a/src/client/webapp/elements/components/retry.tsx b/src/client/webapp/elements/components/retry.tsx index 7b544f0..8d5061c 100644 --- a/src/client/webapp/elements/components/retry.tsx +++ b/src/client/webapp/elements/components/retry.tsx @@ -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 = (props: RetryProps) => { const { error, text, retryFunc } = props; + const [attempts, setAttempts] = useState(0); + const [retryCallable, buttonText, buttonShaking] = useAsyncSubmitButton( 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 }; }, [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 diff --git a/src/client/webapp/guild-combined.ts b/src/client/webapp/guild-combined.ts index 0ea3c2f..1e6e976 100644 --- a/src/client/webapp/guild-combined.ts +++ b/src/client/webapp/guild-combined.ts @@ -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 - 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 { - // 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();