Skip to content

Commit

Permalink
Merge pull request #1552 from tijlleenders/upgrade/colab-feature
Browse files Browse the repository at this point in the history
Restored: Suggestion and Collaboration features
  • Loading branch information
tijlleenders authored Oct 14, 2023
2 parents c80a6a5 + db41bb7 commit 07435f2
Show file tree
Hide file tree
Showing 22 changed files with 427 additions and 368 deletions.
1 change: 1 addition & 0 deletions src/Interfaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ export interface ILocationState {
displayAddContact?: boolean; // whether or not to display the add contact form
displayParticipants?: string; // id of goal whose participants have to be displayed
displayPartner?: ContactItem; // to show this partner
displayChanges?: GoalItem; // to show the changes under goal
}
23 changes: 14 additions & 9 deletions src/api/InboxAPI/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { getDefaultValueOfGoalChanges } from "@src/utils/defaultGenerators";

export const createEmptyInboxItem = async (id: string) => {
db.transaction("rw", db.inboxCollection, async () => {
await db.inboxCollection.add({ id, goalChanges: getDefaultValueOfGoalChanges() });
await db.inboxCollection.add({ id, changes: {} });
}).catch((e) => {
console.log(e);
});
Expand All @@ -24,33 +24,38 @@ export const removeGoalInbox = async (id: string) => {
.catch((err) => console.log("failed to delete", err));
};

export const addGoalChangesInID = async (id: string, newChanges: IChangesInGoal) => {
export const addGoalChangesInID = async (id: string, relId: string, newChanges: IChangesInGoal) => {
db.transaction("rw", db.inboxCollection, async () => {
await db.inboxCollection
.where("id")
.equals(id)
.modify((obj: InboxItem) => {
Object.keys(newChanges).forEach((changeType: typeOfChange) => {
// @ts-ignore
obj.goalChanges[changeType] = [...obj.goalChanges[changeType], ...newChanges[changeType]];
const currentState = obj.changes[relId] || getDefaultValueOfGoalChanges();
Object.keys(currentState).forEach((changeType: typeOfChange) => {
currentState[changeType] = [...currentState[changeType], ...newChanges[changeType]];
});
obj.changes[relId] = { ...currentState };
});
}).catch((e) => {
console.log(e.stack || e);
});
};

export const deleteGoalChangesInID = async (id: string, categoryOfChange: typeOfChange, changes: string[]) => {
export const deleteGoalChangesInID = async (
id: string,
relId: string,
categoryOfChange: typeOfChange,
changes: string[],
) => {
db.transaction("rw", db.inboxCollection, async () => {
await db.inboxCollection
.where("id")
.equals(id)
.modify((obj: InboxItem) => {
const arr = [...obj.goalChanges[categoryOfChange]];
// @ts-ignore
obj.goalChanges[categoryOfChange] = arr.filter(
const goalChanges = obj.changes[relId][categoryOfChange].filter(
(ele) => !changes.includes("goal" in ele ? ele.goal.id : ele.id),
);
obj.changes[relId][categoryOfChange] = [...goalChanges];
});
}).catch((e) => {
console.log(e.stack || e);
Expand Down
30 changes: 11 additions & 19 deletions src/api/SharedWMAPI/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,22 +142,14 @@ export const transferToMyGoals = async (id: string) => {
});
};

// export const convertSharedWMGoalToColab = async (goal: GoalItem) => {
// const { relId, name } = goal.shared.contacts[0];
// collaborateWithContact(relId, goal).then((res) =>
// console.log(res.success ? "colab inv sent" : "failed to sent invite"),
// );
// addSubInPub(goal.id, relId, "collaboration").catch((err) => console.log("failed to add sub in pub", err));
// await transferToMyGoals(goal.id)
// .then(async () => {
// await removeGoalFromPartner(relId, goal);
// const collaboration = JSON.parse(JSON.stringify(goal.collaboration));
// collaboration.collaborators.push({ relId, name });
// addGoal({ ...goal, typeOfGoal: "collaboration", collaboration, shared: getDefaultValueOfShared() })
// .then(async () => {
// removeSharedWMGoal(goal.id);
// })
// .catch((err) => console.log(err));
// })
// .catch((err) => console.log(err));
// };
export const convertSharedWMGoalToColab = async (goal: GoalItem) => {
await transferToMyGoals(goal.id)
.then(async () => {
addGoal({ ...goal, typeOfGoal: "shared" })
.then(async () => {
removeSharedWMGoal(goal.id);
})
.catch((err) => console.log(err));
})
.catch((err) => console.log(err));
};
11 changes: 11 additions & 0 deletions src/components/BackupRestoreModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,17 @@ const BackupRestoreModal = () => {
delete contact.sharedGoals;
});
}
if (currentVersion < 16) {
console.log("processing updates for 16th version");
const sharedWMCollection = db.table("sharedWMCollection");
const goalsCollection = db.table("goalsCollection");
sharedWMCollection.toCollection().modify((goal: GoalItem) => {
goal.newUpdates = false;
});
goalsCollection.toCollection().modify((goal: GoalItem) => {
goal.newUpdates = false;
});
}
importSuccessfull();
} else {
setShowToast({
Expand Down
61 changes: 21 additions & 40 deletions src/components/GoalsComponents/DisplayChangesModal/AcceptBtn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,68 +10,49 @@ import { GoalItem } from "@src/models/GoalItem";
import { getTypeAtPriority } from "@src/helpers/GoalProcessor";
import { deleteGoalChangesInID, getInboxItem } from "@src/api/InboxAPI";
import { IDisplayChangesModal } from "@src/Interfaces/IDisplayChangesModal";
import { changeNewUpdatesStatus, convertSharedGoalToColab } from "@src/api/GoalsAPI";
import { typeOfChange } from "@src/models/InboxItem";

interface AcceptBtnProps {
goal: GoalItem;
acceptChanges: () => Promise<void>;
showChangesModal: IDisplayChangesModal;
setShowChangesModal: React.Dispatch<React.SetStateAction<IDisplayChangesModal | null>>;
typeAtPriority: typeOfChange | "none";
}

const AcceptBtn = ({ showChangesModal, goal, acceptChanges, setShowChangesModal }: AcceptBtnProps) => {
const { typeAtPriority } = showChangesModal;
const isConversionRequest = typeAtPriority === "conversionRequest";
const AcceptBtn = ({ typeAtPriority, goal, acceptChanges }: AcceptBtnProps) => {
const darkModeStatus = useRecoilValue(darkModeState);
const setLastAction = useSetRecoilState(lastAction);

const handleClick = async () => {
if (isConversionRequest) {
// await convertTypeOfSub(goal.rootGoalId, goal.shared.contacts[0].relId, "collaboration");
await convertSharedGoalToColab(goal.id);
setShowChangesModal(null);
} else {
await acceptChanges();
const removeChanges =
typeAtPriority === "subgoals" ? showChangesModal.goals.map((ele) => ele.id) : [showChangesModal.goals[0].id];
if (typeAtPriority !== "none") {
await deleteGoalChangesInID(goal.rootGoalId, typeAtPriority, removeChanges);
}
}
await acceptChanges();

const inbox = await getInboxItem(goal.rootGoalId);
if (getTypeAtPriority(inbox.goalChanges).typeAtPriority === "none") {
changeNewUpdatesStatus(false, goal.rootGoalId)
.then(() => {
setLastAction("goalUpdates");
})
.catch((err) => console.log(err));
}
setShowChangesModal(null);
// if (getTypeAtPriority(inbox.goalChanges).typeAtPriority === "none") {
// changeNewUpdatesStatus(false, goal.rootGoalId)
// .then(() => {
// setLastAction("goalUpdates");
// })
// .catch((err) => console.log(err));
// }
};
return (
<button
type="button"
style={{ width: "100%", padding: "8px 15px", justifyContent: "flex-start" }}
style={{ padding: "8px 15px", justifyContent: "flex-start" }}
className={`default-btn${darkModeStatus ? "-dark" : ""}`}
onClick={handleClick}
onClick={async () => {
await acceptChanges();
}}
>
<img
alt="add changes"
src={isConversionRequest ? collaborateSvg : typeAtPriority === "deleted" ? deleteIcon : plus}
src={typeAtPriority === "deleted" ? deleteIcon : plus}
width={25}
style={!darkModeStatus ? { filter: "brightness(0)" } : {}}
/>
&nbsp;
{isConversionRequest ? (
`Collaborate with ${goal.shared.contacts[0].name}`
) : (
<>
{typeAtPriority === "archived" && "Complete for me too"}
{typeAtPriority === "deleted" && "Delete for me too"}
{typeAtPriority === "subgoals" && "Add all checked"}
{typeAtPriority === "modifiedGoals" && "Make all checked changes"}
</>
)}
{typeAtPriority === "archived" && "Complete for me too"}
{typeAtPriority === "deleted" && "Delete for me too"}
{typeAtPriority === "subgoals" && "Add all checked"}
{typeAtPriority === "modifiedGoals" && "Make all checked changes"}
</button>
);
};
Expand Down
Loading

1 comment on commit 07435f2

@vercel
Copy link

@vercel vercel bot commented on 07435f2 Oct 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

zinzen – ./

zinzen-tijlleenders.vercel.app
zinzen-git-main-tijlleenders.vercel.app
zinzen.vercel.app

Please sign in to comment.