Skip to content

Commit 18c9b8b

Browse files
committed
chore: migrate FileEditor to the fire-and-forget invoker
1 parent 0262383 commit 18c9b8b

2 files changed

Lines changed: 13 additions & 9 deletions

File tree

apps/webapp/src/script/components/FileFullscreenModal/FileEditor/FileEditor.tsx

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {PrimaryModal} from 'Components/Modals/PrimaryModal';
2727
import {removeCurrentModal} from 'Components/Modals/PrimaryModal/PrimaryModalState';
2828
import {CellsRepository} from 'Repositories/cells/cellsRepository';
2929
import {Config} from 'src/script/Config';
30+
import {useApplicationContext} from 'src/script/page/RootProvider';
3031
import {t} from 'Util/localizerUtil';
3132
import {TIME_IN_MILLIS} from 'Util/timeUtil';
3233

@@ -43,6 +44,7 @@ interface FileEditorProps {
4344

4445
export const FileEditor = ({id}: FileEditorProps) => {
4546
const cellsRepository = container.resolve(CellsRepository);
47+
const {fireAndForgetInvoker} = useApplicationContext();
4648
const [node, setNode] = useState<Node | null>(null);
4749
const [isRecycled, setIsRecycled] = useState(false);
4850
const [isLoading, setIsLoading] = useState(true);
@@ -74,18 +76,19 @@ export const FileEditor = ({id}: FileEditorProps) => {
7476

7577
const handleRetry = useCallback(() => {
7678
hasShownErrorModal.current = false;
77-
void (async () => {
79+
80+
fireAndForgetInvoker.fireAndForget(async (): Promise<void> => {
7881
const isSuccessful = await fetchNode();
7982
if (isSuccessful) {
8083
removeCurrentModal();
8184
}
82-
})();
83-
}, [fetchNode]);
85+
});
86+
}, [fetchNode, fireAndForgetInvoker]);
8487

8588
// Initial fetch
8689
useEffect(() => {
87-
void fetchNode();
88-
}, [id, cellsRepository, fetchNode]);
90+
fireAndForgetInvoker.fireAndForget(fetchNode);
91+
}, [fetchNode, fireAndForgetInvoker]);
8992

9093
// Auto-refresh mechanism before expiry
9194
useEffect(() => {
@@ -98,16 +101,16 @@ export const FileEditor = ({id}: FileEditorProps) => {
98101

99102
// Set timeout to refresh before expiry
100103
const timeoutId = setTimeout(() => {
101-
void fetchNode();
104+
fireAndForgetInvoker.fireAndForget(fetchNode);
102105
}, refreshInSeconds * TIME_IN_MILLIS.SECOND);
103106

104107
return () => {
105108
clearTimeout(timeoutId);
106109
};
107-
}, [node, fetchNode]);
110+
}, [fetchNode, fireAndForgetInvoker, node]);
108111

109112
useEffect(() => {
110-
if (isLoading || isRecycled || (!isError && node)) {
113+
if (isLoading || isRecycled || (!isError && node !== null)) {
111114
return;
112115
}
113116

@@ -134,7 +137,7 @@ export const FileEditor = ({id}: FileEditorProps) => {
134137
}, [handleRetry, isError, isLoading, isRecycled, node]);
135138

136139
useEffect(() => {
137-
if (!isLoading && !isError && node && !isRecycled) {
140+
if (!isLoading && !isError && node !== null && !isRecycled) {
138141
hasShownErrorModal.current = false;
139142
}
140143
}, [isError, isLoading, isRecycled, node]);

eslint.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ const config: Linter.Config[] = [
251251
'apps/webapp/src/script/components/Conversation/ConversationCells/useConversationSearch/useConversationSearchFiles.ts',
252252
'apps/webapp/src/script/components/Conversation/ConversationCells/useGetAllCellsNodes/useGetAllCellsNodes.ts',
253253
'apps/webapp/src/script/components/Conversation/ConversationCells/useRefreshCellsState/useRefreshCellsState.ts',
254+
'apps/webapp/src/script/components/FileFullscreenModal/FileEditor/FileEditor.tsx',
254255
'apps/webapp/src/script/components/InputBar/InputBar.tsx',
255256
'apps/webapp/src/script/components/InputBar/usePing/usePing.ts',
256257
'apps/webapp/src/script/components/MessagesList/Message/MessageWrapper.tsx',

0 commit comments

Comments
 (0)