Skip to content

Commit

Permalink
fix: make autoTranslate more reliable in tests (#1865)
Browse files Browse the repository at this point in the history
  • Loading branch information
stepan662 authored Aug 15, 2023
1 parent 57fb4e1 commit 4ef6368
Showing 1 changed file with 8 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { useTranslationsService } from './useTranslationsService';
import { useConfig } from 'tg.globalContext/helpers';
import { useProject } from 'tg.hooks/useProject';
import { useEffect, useRef, useState } from 'react';
import {
Expand All @@ -13,7 +12,6 @@ export const useWebsocketService = (
translationService: ReturnType<typeof useTranslationsService>
) => {
const [eventBlockers, setEventBlockers] = useState(0);
const config = useConfig();
const project = useProject();
const client = useGlobalContext((c) => c.client);

Expand Down Expand Up @@ -48,17 +46,17 @@ export const useWebsocketService = (
const eventQueue = useRef([] as TranslationsModifiedData[]);

const handleQueue = () => {
eventQueue.current.forEach((e) => {
updateTranslations(e);
});
eventQueue.current = [];
if (eventBlockers <= 0) {
eventQueue.current.forEach((e) => {
updateTranslations(e);
});
eventQueue.current = [];
}
};

// process the blocked events, when the blocker is gone
useEffect(() => {
if (eventBlockers <= 0) {
handleQueue();
}
handleQueue();
}, [eventBlockers]);

const handerRef = useRef(handleQueue);
Expand All @@ -84,7 +82,7 @@ export const useWebsocketService = (
}
);
}
}, [config, project, client]);
}, [project, client]);

return {
setEventBlockers,
Expand Down

0 comments on commit 4ef6368

Please sign in to comment.