Skip to content

Commit

Permalink
fix: sharedwm goal disappear when moved to non shared goal
Browse files Browse the repository at this point in the history
  • Loading branch information
vinaybadgujar102 committed Nov 9, 2024
1 parent 669bd46 commit 9f3fd12
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/helpers/InboxProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
addIntoSublist,
// changeNewUpdatesStatus,
getGoal,
getGoalById,
updateGoal,
} from "@src/api/GoalsAPI";
import { addGoalChangesInID, createEmptyInboxItem, getInboxItem } from "@src/api/InboxAPI";
Expand Down Expand Up @@ -65,9 +66,20 @@ const updateSharedWMGoalAndDescendants = async (movedGoal: GoalItem) => {
}
};

const handleMoveOperation = async (movedGoal: GoalItem, goalToMove: GoalItem) => {
await updateSharedWMParentSublist(goalToMove.parentGoalId, movedGoal.parentGoalId, goalToMove.id);
await updateSharedWMGoalAndDescendants(movedGoal);
const handleMoveOperation = async (movedGoal: GoalItem, correspondingSharedWMGoal: GoalItem) => {
const isNewParentAvailable = await getSharedWMGoal(movedGoal.parentGoalId);
const updatedGoal = {
...movedGoal,
parentGoalId: !isNewParentAvailable ? "root" : movedGoal.parentGoalId,
rootGoalId: !isNewParentAvailable ? "root" : movedGoal.rootGoalId,
};

await updateSharedWMParentSublist(
correspondingSharedWMGoal.parentGoalId,
updatedGoal.parentGoalId,
correspondingSharedWMGoal.id,
);
await updateSharedWMGoalAndDescendants(updatedGoal);
};

const addChangesToRootGoal = async (goalId: string, relId: string, changes: ChangesByType) => {
Expand Down Expand Up @@ -177,14 +189,14 @@ export const handleIncomingChanges = async (payload: Payload, relId: string) =>
...payload.changes.map((ele: changesInGoal) => ({ ...ele, goal: fixDateVlauesInGoalObject(ele.goal) })),
];
const movedGoal = changes[0].goal;
const goalToMove = await getSharedWMGoal(movedGoal.id);
const correspondingSharedWMGoal = await getSharedWMGoal(movedGoal.id);

if (!goalToMove) {
if (!correspondingSharedWMGoal) {
console.log("Goal to move not found");
return;
}

await handleMoveOperation(movedGoal, goalToMove);
await handleMoveOperation(movedGoal, correspondingSharedWMGoal);
}
} else if (["sharer", "suggestion"].includes(payload.type)) {
const { changes, changeType, rootGoalId } = payload;
Expand Down

0 comments on commit 9f3fd12

Please sign in to comment.