Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useState } from 'react';
import { useEffect, useRef, useState } from 'react';
import { useRecoilValue } from 'recoil';

import { FieldMetadata } from '@/object-record/record-field/types/FieldMetadata';
Expand Down Expand Up @@ -53,12 +53,12 @@ export const useRecordData = ({
callback,
viewType = ViewType.Table,
}: UseRecordDataOptions) => {
const [isDownloading, setIsDownloading] = useState(false);
const [inflight, setInflight] = useState(false);
const [pageCount, setPageCount] = useState(0);
const [progress, setProgress] = useState<ExportProgress>({
displayType: 'number',
});
const isDownloadingRef = useRef(false);
const [previousRecordCount, setPreviousRecordCount] = useState(0);

const { visibleTableColumnsSelector } = useRecordTableStates(recordIndexId);
Expand Down Expand Up @@ -119,7 +119,7 @@ export const useRecordData = ({
setInflight(false);
};

if (!isDownloading || inflight || loading) {
if (!isDownloadingRef.current || inflight || loading) {
return;
}

Expand All @@ -132,7 +132,7 @@ export const useRecordData = ({
const complete = () => {
setPageCount(0);
setPreviousRecordCount(0);
setIsDownloading(false);
isDownloadingRef.current = false;
setProgress({
displayType: 'number',
});
Expand All @@ -159,7 +159,6 @@ export const useRecordData = ({
delayMs,
fetchMoreRecordsWithPagination,
inflight,
isDownloading,
pageCount,
records,
totalCount,
Expand All @@ -171,16 +170,19 @@ export const useRecordData = ({
previousRecordCount,
hiddenKanbanFieldColumn,
viewType,
isDownloadingRef.current,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: isDownloadingRef.current should not be in the useEffect dependencies array since it's a mutable ref value

]);

return {
progress,
isDownloading,
isDownloading: isDownloadingRef.current,
getTableData: () => {
setPageCount(0);
setPreviousRecordCount(0);
setIsDownloading(true);
findManyRecords?.();
if (!isDownloadingRef.current) {
setPageCount(0);
setPreviousRecordCount(0);
isDownloadingRef.current = true;
findManyRecords?.();
}
},
};
};
Loading