Skip to content

Commit

Permalink
fix: Multiple loading toast if tab switched when extracting
Browse files Browse the repository at this point in the history
  • Loading branch information
remi-guan committed Dec 28, 2024
1 parent f8f4a6e commit 1a6bd94
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions app/components/playground/ExtractKeyValuePairContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ const downloadExtractedData = (formattedData: string, file?: PlaygroundFile['fil
const ExtractKeyValuePairContainer = () => {
const { apiURL, isProduction } = useProductionContext();
const { selectedFileIndex, files, updateFileAtIndex, token, userId, clientId, addFilesFormData } = usePlaygroundStore();
const [loadingToastId, setLoadingToastId] = useState<string | undefined>();

const selectedFile = useMemo(() => {
if (selectedFileIndex !== null && files.length > 0) {
Expand All @@ -84,17 +83,11 @@ const ExtractKeyValuePairContainer = () => {
if (!selectedFile) return;

if (selectedFile.keyValueExtractState === ExtractState.EXTRACTING || selectedFile.keyValueExtractState === ExtractState.UPLOADING) {
if (!loadingToastId) {
const id = toast.loading('Extracting data...');
setLoadingToastId(id);
}
toast.loading('Extracting data...', { id: 'key-value-extracting-toast' });
} else {
if (loadingToastId) {
toast.dismiss(loadingToastId);
setLoadingToastId(undefined);
}
toast.dismiss('key-value-extracting-toast');
}
}, [selectedFile?.keyValueExtractState, loadingToastId]);
}, [selectedFile?.keyValueExtractState]);

const handleSuccess = async (response: any) => {
if (!response.data) {
Expand Down

0 comments on commit 1a6bd94

Please sign in to comment.