Skip to content

Commit

Permalink
Hacky workaround for double firing of pull request
Browse files Browse the repository at this point in the history
  • Loading branch information
jennydaman committed Oct 9, 2024
1 parent 9e4a713 commit 37f0839
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/components/Pacs/PacsController.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,8 @@ const PacsController: React.FC<PacsControllerProps> = ({
const onRetrieve = React.useCallback(
(service: string, query: PACSqueryCore) => {
expandStudiesFor(service, query);
// N.B.: immer bug here
// https://github.com/immerjs/use-immer/issues/139
setPullRequests((draft) => {
// indicate that the user requests for something to be retrieved.
draft.push({
Expand Down Expand Up @@ -594,10 +596,19 @@ const PacsController: React.FC<PacsControllerProps> = ({
updatePullRequestState(service, query, { state: RequestState.REQUESTED }),
});

// FIXME idk why the effect is firing twice...
const badWorkaroundToPreventDuplicatePull = React.useRef<
Set<PacsPullRequestState>
>(new Set());

React.useEffect(() => {
pullRequests
.filter(shouldSendPullRequest)
.forEach((pr) => pullFromPacs.mutate(pr));
.filter((pr) => !badWorkaroundToPreventDuplicatePull.current.has(pr))
.forEach((pr) => {
badWorkaroundToPreventDuplicatePull.current.add(pr);
pullFromPacs.mutate(pr);
});
}, [pullRequests, shouldSendPullRequest]);

// ========================================
Expand Down

0 comments on commit 37f0839

Please sign in to comment.