fix exhaustive-deps warnings for custom hooks
This commit is contained in:
parent
b615e6ccba
commit
33d5987269
@ -50,8 +50,8 @@ const ImageEditInput: FC<ImageEditInputProps> = (props: ImageEditInputProps) =>
|
||||
return './img/error.png';
|
||||
}
|
||||
},
|
||||
[value, setValid, isMounted, setMessage],
|
||||
'./img/loading.svg',
|
||||
[value],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
|
@ -28,7 +28,7 @@ const TokenRow: FC<TokenRowProps> = (props: TokenRowProps) => {
|
||||
|
||||
const guildMeta = useRecoilValue(guildMetaState(guild.id));
|
||||
|
||||
const [guildSocketConfigs] = useOneTimeAsyncAction(async () => await guild.fetchSocketConfigs(), null, [guild]);
|
||||
const [guildSocketConfigs] = useOneTimeAsyncAction(async () => await guild.fetchSocketConfigs(), [guild], null);
|
||||
const iconSrc = useRecoilValueSoftImgSrc(
|
||||
guildResourceSoftImgSrcState({
|
||||
guildId: guild.id,
|
||||
|
@ -70,7 +70,7 @@ const AddGuildOverlay: FC<AddGuildOverlayProps> = (props: AddGuildOverlayProps)
|
||||
const [avatarInputMessage, setAvatarInputMessage] = useState<string | null>(null);
|
||||
const [avatarInputValid, setAvatarInputValid] = useState<boolean>(false);
|
||||
|
||||
const [exampleAvatarBuff, exampleAvatarBuffError] = useOneTimeAsyncAction(async () => await fs.readFile(exampleAvatarPath), null, [exampleAvatarPath]);
|
||||
const [exampleAvatarBuff, exampleAvatarBuffError] = useOneTimeAsyncAction(async () => await fs.readFile(exampleAvatarPath), [exampleAvatarPath], null);
|
||||
|
||||
useEffect(() => {
|
||||
if (exampleAvatarBuff) {
|
||||
@ -103,7 +103,7 @@ const AddGuildOverlay: FC<AddGuildOverlayProps> = (props: AddGuildOverlayProps)
|
||||
|
||||
setOverlay(null);
|
||||
return { result: newGuild, errorMessage: null };
|
||||
}, [displayName, avatarBuff, displayNameInputValid, avatarInputValid, setOverlay]);
|
||||
}, [guildsManager, validationErrorMessage, expired, displayName, avatarBuff, setCurrGuildId, setOverlay, addGuildData]);
|
||||
|
||||
const errorMessage = useMemo(() => {
|
||||
if (validationErrorMessage) return validationErrorMessage;
|
||||
@ -114,11 +114,22 @@ const AddGuildOverlay: FC<AddGuildOverlayProps> = (props: AddGuildOverlayProps)
|
||||
return (
|
||||
<Overlay childRootRef={rootRef}>
|
||||
<div ref={rootRef} className="content add-guild">
|
||||
<InvitePreview name={addGuildData.name} iconSrc={addGuildData.iconSrc} url={addGuildData.url} expiresFromNow={addGuildData.expires ? moment.duration(addGuildData.expires - Date.now(), 'ms') : null} />
|
||||
<InvitePreview
|
||||
name={addGuildData.name}
|
||||
iconSrc={addGuildData.iconSrc}
|
||||
url={addGuildData.url}
|
||||
expiresFromNow={addGuildData.expires ? moment.duration(addGuildData.expires - Date.now(), 'ms') : null}
|
||||
/>
|
||||
<div className="divider" />
|
||||
<div className="personalization">
|
||||
<div className="avatar">
|
||||
<ImageEditInput maxSize={Globals.MAX_AVATAR_SIZE} value={avatarBuff} setValue={setAvatarBuff} setValid={setAvatarInputValid} setMessage={setAvatarInputMessage} />
|
||||
<ImageEditInput
|
||||
maxSize={Globals.MAX_AVATAR_SIZE}
|
||||
value={avatarBuff}
|
||||
setValue={setAvatarBuff}
|
||||
setValid={setAvatarInputValid}
|
||||
setMessage={setAvatarInputMessage}
|
||||
/>
|
||||
</div>
|
||||
<div className="display-name">
|
||||
<TextInput
|
||||
|
@ -89,7 +89,7 @@ const ChannelOverlay: FC<ChannelOverlayProps> = (props: ChannelOverlayProps) =>
|
||||
setOverlay(null);
|
||||
return { result: null, errorMessage: null };
|
||||
},
|
||||
[guild, edited, validationErrorMessage, name, flavorText, setOverlay],
|
||||
[guild, edited, channel, validationErrorMessage, name, flavorText, setOverlay],
|
||||
{ start: channel ? 'Modify Channel' : 'Create Channel' },
|
||||
);
|
||||
|
||||
|
@ -99,7 +99,7 @@ const PersonalizeOverlay: FC<PersonalizeOverlayProps> = (props: PersonalizeOverl
|
||||
setOverlay(null);
|
||||
return { result: null, errorMessage: null };
|
||||
},
|
||||
[validationErrorMessage, displayName, savedDisplayName, avatarBuff, savedAvatarBuff, setOverlay],
|
||||
[validationErrorMessage, displayName, savedDisplayName, guild, avatarBuff, savedAvatarBuff, setOverlay],
|
||||
);
|
||||
|
||||
//if (saveFailed) return 'Unable to save personalization';
|
||||
|
@ -61,8 +61,8 @@ function useShake(ms: number): [shaking: boolean, doShake: () => void] {
|
||||
// runs an Async action one time (updates when deps changes)
|
||||
export function useOneTimeAsyncAction<T, V>(
|
||||
actionFunc: () => Promise<T>,
|
||||
initialValue: V,
|
||||
deps: DependencyList,
|
||||
initialValue: V,
|
||||
): [value: T | V, error: unknown | null] {
|
||||
const isMounted = useRef(false);
|
||||
|
||||
@ -241,8 +241,8 @@ export function useDownloadButton(
|
||||
|
||||
setText(textMapping.success);
|
||||
},
|
||||
// TODO: look into this warning
|
||||
[downloadName, fetchBuff, ...fetchBuffDeps, filePath, fileBuffer],
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
[shaking, doShake, downloadName, fetchBuff, ...fetchBuffDeps, filePath, fileBuffer, textMapping.pendingFetch, textMapping.notReadyFetch, textMapping.errorFetch, textMapping.errorSave, textMapping.success],
|
||||
);
|
||||
|
||||
return [callable, text, shaking];
|
||||
|
@ -61,7 +61,7 @@ const GuildListContainer: FC = () => {
|
||||
} else {
|
||||
setOverlay(<AddGuildOverlay addGuildData={addGuildData} />);
|
||||
}
|
||||
}, []);
|
||||
}, [setOverlay]);
|
||||
|
||||
return (
|
||||
<div className="guild-list-container">
|
||||
|
@ -42,8 +42,8 @@ const AttachmentPreview: FC<AttachmentPreviewProps> = (props: AttachmentPreviewP
|
||||
return './img/file-improved.svg';
|
||||
}
|
||||
},
|
||||
'./img/loading.svg',
|
||||
[attachmentBuff],
|
||||
'./img/loading.svg',
|
||||
);
|
||||
|
||||
return (
|
||||
|
@ -30,13 +30,11 @@ 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;
|
||||
@ -62,8 +60,8 @@ export default class CombinedGuild
|
||||
const diskSocket = new PairVerifierFetchable(this.personalDBGuild, this.socketGuild, 'disk-socket');
|
||||
const ramDiskSocket = new PairVerifierFetchable(this.ramGuild, diskSocket, 'ram-disk');
|
||||
|
||||
// TODO: I think this unverify is causing the RARE ALERTs
|
||||
// do we need to unverify on connect? or just disconnect?
|
||||
// TODO: I think this unverify is causing the RARE ALERTs
|
||||
// do we need to unverify on connect? or just disconnect?
|
||||
// connect/Disconnect
|
||||
this.socketGuild.on('connect', () => {
|
||||
LOG.info(`g#${this.id} connected`);
|
||||
@ -356,22 +354,22 @@ export default class CombinedGuild
|
||||
// fetched through the triple-cache system (RAM -> Disk -> Server)
|
||||
async fetchMetadata(): Promise<GuildMetadata> {
|
||||
// xUtil.failSometimes(0.05); // for testing
|
||||
LOG.debug(`g#${this.id}: fetch metadata`);
|
||||
LOG.debug(`g#${this.id}: fetch metadata`);
|
||||
return await this.fetchable.fetchMetadata();
|
||||
}
|
||||
async fetchMembers(): Promise<Member[]> {
|
||||
// xUtil.failSometimes(0.05); // for testing
|
||||
LOG.debug(`g#${this.id}: fetch members`);
|
||||
LOG.debug(`g#${this.id}: fetch members`);
|
||||
return await this.fetchable.fetchMembers();
|
||||
}
|
||||
async fetchChannels(): Promise<Channel[]> {
|
||||
// xUtil.failSometimes(0.05); // for testing
|
||||
LOG.debug(`g#${this.id}: fetch channels`);
|
||||
LOG.debug(`g#${this.id}: fetch channels`);
|
||||
return await this.fetchable.fetchChannels();
|
||||
}
|
||||
async fetchMessagesRecent(channelId: string, number: number): Promise<Message[]> {
|
||||
// xUtil.failSometimes(0.05); // for testing
|
||||
LOG.debug(`g#${this.id}: fetch recent messages ch#${channelId.slice(0, 4)}, ${number}`);
|
||||
LOG.debug(`g#${this.id}: fetch recent messages ch#${channelId.slice(0, 4)}, ${number}`);
|
||||
const members = await this.grabRAMMembersMap();
|
||||
const channels = await this.grabRAMChannelsMap();
|
||||
const messages = await this.fetchable.fetchMessagesRecent(channelId, number);
|
||||
@ -382,7 +380,7 @@ export default class CombinedGuild
|
||||
}
|
||||
async fetchMessagesBefore(channelId: string, messageOrderId: string, number: number): Promise<Message[]> {
|
||||
// xUtil.failSometimes(0.05); // 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 channels = await this.grabRAMChannelsMap();
|
||||
const messages = await this.fetchable.fetchMessagesBefore(channelId, messageOrderId, number);
|
||||
@ -393,7 +391,7 @@ export default class CombinedGuild
|
||||
}
|
||||
async fetchMessagesAfter(channelId: string, messageOrderId: string, number: number): Promise<Message[]> {
|
||||
// xUtil.failSometimes(0.05); // for testing
|
||||
LOG.debug(`g#${this.id}: fetch messages after ch#${channelId.slice(0, 4)}, mo#${messageOrderId}, ${number}`);
|
||||
LOG.debug(`g#${this.id}: fetch messages after ch#${channelId.slice(0, 4)}, mo#${messageOrderId}, ${number}`);
|
||||
const members = await this.grabRAMMembersMap();
|
||||
const channels = await this.grabRAMChannelsMap();
|
||||
const messages = await this.fetchable.fetchMessagesAfter(channelId, messageOrderId, number);
|
||||
@ -404,12 +402,12 @@ export default class CombinedGuild
|
||||
}
|
||||
async fetchResource(resourceId: string): Promise<Resource> {
|
||||
// xUtil.failSometimes(0.05); // for testing
|
||||
LOG.debug(`g#${this.id}: fetch resource r#${resourceId.slice(0, 4)}`);
|
||||
LOG.debug(`g#${this.id}: fetch resource r#${resourceId.slice(0, 4)}`);
|
||||
return await this.fetchable.fetchResource(resourceId);
|
||||
}
|
||||
async fetchTokens(): Promise<Token[]> {
|
||||
// xUtil.failSometimes(0.05); // for testing
|
||||
LOG.debug(`g#${this.id}: fetch tokens`);
|
||||
LOG.debug(`g#${this.id}: fetch tokens`);
|
||||
const members = await this.grabRAMMembersMap();
|
||||
const tokens = await this.fetchable.fetchTokens();
|
||||
for (const token of tokens) {
|
||||
|
Loading…
Reference in New Issue
Block a user