Skip to content

Commit

Permalink
Merge pull request #875 from pankona/fix-duplication-in-multiple-move…
Browse files Browse the repository at this point in the history
…-in-short

Prevent duplicate API calls when the multiple movements are triggered in a short
  • Loading branch information
kachick authored Jun 21, 2023
2 parents 6b58947 + 141735c commit 2e57b95
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions hashira-web/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
import React, { useRef } from "react";
import styled from "styled-components";
import * as firebase from "./firebase";
import Header from "./Header";
Expand Down Expand Up @@ -52,10 +52,12 @@ const App: React.FC<{ user: firebase.User | null | undefined }> = ({
[user],
);

const isMoveTaskProcessing = useRef(false);

const onMoveTask = React.useCallback(
(taskId: string, direction: "left" | "right") => {
return new Promise<void>(async (resolve, reject) => {
if (!user) {
if (!user || isMoveTaskProcessing.current) {
resolve();
return;
}
Expand Down Expand Up @@ -84,11 +86,14 @@ const App: React.FC<{ user: firebase.User | null | undefined }> = ({
};

try {
isMoveTaskProcessing.current = true;
await updateTasks(tasksToMove);
await fetchTasksAndPriorities(user.uid);
resolve();
} catch (e) {
reject(e);
} finally {
isMoveTaskProcessing.current = false;
}
});
},
Expand Down

0 comments on commit 2e57b95

Please sign in to comment.