diff --git a/src/Interfaces/index.ts b/src/Interfaces/index.ts index acb60b013..4cd274fd1 100644 --- a/src/Interfaces/index.ts +++ b/src/Interfaces/index.ts @@ -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 } diff --git a/src/api/InboxAPI/index.ts b/src/api/InboxAPI/index.ts index dd6f5cbbc..f5f130a9f 100644 --- a/src/api/InboxAPI/index.ts +++ b/src/api/InboxAPI/index.ts @@ -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); }); @@ -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); diff --git a/src/api/SharedWMAPI/index.ts b/src/api/SharedWMAPI/index.ts index 66a2440d6..d968939f0 100644 --- a/src/api/SharedWMAPI/index.ts +++ b/src/api/SharedWMAPI/index.ts @@ -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)); +}; diff --git a/src/components/BackupRestoreModal.tsx b/src/components/BackupRestoreModal.tsx index 58b2c30bf..5ecc9db0d 100644 --- a/src/components/BackupRestoreModal.tsx +++ b/src/components/BackupRestoreModal.tsx @@ -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({ diff --git a/src/components/GoalsComponents/DisplayChangesModal/AcceptBtn.tsx b/src/components/GoalsComponents/DisplayChangesModal/AcceptBtn.tsx index 3a923ef97..4c6ef29d4 100644 --- a/src/components/GoalsComponents/DisplayChangesModal/AcceptBtn.tsx +++ b/src/components/GoalsComponents/DisplayChangesModal/AcceptBtn.tsx @@ -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; - showChangesModal: IDisplayChangesModal; - setShowChangesModal: React.Dispatch>; + 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 ( ); }; diff --git a/src/components/GoalsComponents/DisplayChangesModal/DisplayChangesModal.tsx b/src/components/GoalsComponents/DisplayChangesModal/DisplayChangesModal.tsx index 3aa66e197..dfaf43356 100644 --- a/src/components/GoalsComponents/DisplayChangesModal/DisplayChangesModal.tsx +++ b/src/components/GoalsComponents/DisplayChangesModal/DisplayChangesModal.tsx @@ -1,143 +1,265 @@ -// /* eslint-disable consistent-return */ -// import { Checkbox, Modal } from "antd"; -// import React, { useEffect, useState } from "react"; -// import { useRecoilState, useRecoilValue } from "recoil"; +/* eslint-disable consistent-return */ +import { Checkbox, Modal } from "antd"; +import React, { useEffect, useState } from "react"; +import { useRecoilValue } from "recoil"; -// import { darkModeState } from "@src/store"; -// import { getGoal } from "@src/api/GoalsAPI"; -// import { GoalItem } from "@src/models/GoalItem"; -// import { themeState } from "@src/store/ThemeState"; -// import { typeOfChange } from "@src/models/InboxItem"; -// import { displayChangesModal } from "@src/store/GoalsState"; -// import { findGoalTagChanges } from "@src/helpers/GoalProcessor"; -// import { ITagsChanges } from "@src/Interfaces/IDisplayChangesModal"; -// import { acceptChangesOf } from "@src/helpers/InboxProcessor"; -// import Header from "./Header"; -// import AcceptBtn from "./AcceptBtn"; -// import IgnoreBtn from "./IgnoreBtn"; +import { GoalItem } from "@src/models/GoalItem"; +import { themeState } from "@src/store/ThemeState"; +import { ITagsChanges } from "@src/Interfaces/IDisplayChangesModal"; +import { darkModeState } from "@src/store"; +import { getAllContacts } from "@src/api/ContactsAPI"; +import { getGoal, updateGoal } from "@src/api/GoalsAPI"; +import { displayChangesModal } from "@src/store/GoalsState"; +import { typeOfChange, typeOfIntent } from "@src/models/InboxItem"; +import { deleteGoalChangesInID, getInboxItem } from "@src/api/InboxAPI"; +import { findGoalTagChanges, jumpToLowestChanges } from "@src/helpers/GoalProcessor"; +import { acceptSelectedSubgoals, acceptSelectedTags } from "@src/helpers/InboxProcessor"; +import SubHeader from "@src/common/SubHeader"; +import ContactItem from "@src/models/ContactItem"; -// import "./DisplayChangesModal.scss"; +import Header from "./Header"; +import AcceptBtn from "./AcceptBtn"; +import IgnoreBtn from "./IgnoreBtn"; +import "./DisplayChangesModal.scss"; -// const DisplayChangesModal = () => { -// const theme = useRecoilValue(themeState); -// const darkModeStatus = useRecoilValue(darkModeState); -// const [activeGoal, setActiveGoal] = useState(); -// const [updateList, setUpdateList] = useState({ schemaVersion: {}, prettierVersion: {} }); -// const [activeContact, setActiveContact] = useState(""); -// const [currentDisplay, setCurrentDisplay] = useState("none"); -// const [showChangesModal, setShowChangesModal] = useRecoilState(displayChangesModal); -// const [unselectedChanges, setUnselectedChanges] = useState([]); +const DisplayChangesModal = () => { + const theme = useRecoilValue(themeState); + const darkModeStatus = useRecoilValue(darkModeState); + const showChangesModal = useRecoilValue(displayChangesModal); -// const getEditChangesList = () => { -// const { prettierVersion } = updateList; -// return ( -//
-// {Object.keys(prettierVersion).map((k) => ( -//
-// { -// setUnselectedChanges([ -// ...(e.target.checked ? unselectedChanges.filter((tag) => tag !== k) : [...unselectedChanges, k]), -// ]); -// }} -// /> -//

-//  {k}:  -// {prettierVersion[k].oldVal}  -// {prettierVersion[k].newVal} -//

-//
-// ))} -//
-// ); -// }; + const [newGoals, setNewGoals] = useState<{ intent: typeOfIntent; goal: GoalItem }[]>([]); + const [activePPT, setActivePPT] = useState(-1); + const [updateList, setUpdateList] = useState({ schemaVersion: {}, prettierVersion: {} }); + const [activeGoal, setActiveGoal] = useState(); + const [participants, setParticipants] = useState([]); + const [currentDisplay, setCurrentDisplay] = useState("none"); + const [showSuggestions, setShowSuggestions] = useState(false); + const [unselectedChanges, setUnselectedChanges] = useState([]); -// const getSubgoalsList = () => -// showChangesModal?.goals.map((ele) => ( -//
-// { -// setUnselectedChanges([ -// ...(e.target.checked ? unselectedChanges.filter((id) => id !== ele.id) : [...unselectedChanges, ele.id]), -// ]); -// }} -// className="checkbox" -// /> -//  {ele.title} -//
-// )); + const getEditChangesList = () => { + const { prettierVersion } = updateList; + return ( +
+ {Object.keys(prettierVersion).map((k) => ( +
+ { + setUnselectedChanges([ + ...(e.target.checked ? unselectedChanges.filter((tag) => tag !== k) : [...unselectedChanges, k]), + ]); + }} + /> +

+  {k}:  + {prettierVersion[k].oldVal}  + {prettierVersion[k].newVal} +

+
+ ))} +
+ ); + }; -// const acceptChanges = async () => { -// if (showChangesModal) { -// await acceptChangesOf(unselectedChanges, showChangesModal, updateList, activeGoal); -// } -// setUnselectedChanges([]); -// }; -// const getChanges = () => -// currentDisplay === "archived" || currentDisplay === "deleted" ? ( -//
-// ) : currentDisplay === "modifiedGoals" ? ( -// getEditChangesList() -// ) : ( -// getSubgoalsList() -// ); -// useEffect(() => { -// const getInbox = async () => { -// if (showChangesModal) { -// const goal = await getGoal(showChangesModal.parentId); -// const rootGoal = await getGoal(goal.rootGoalId); -// if (showChangesModal.typeAtPriority === "conversionRequest") { -// setActiveContact(rootGoal.shared.contacts[0].name); -// } else { -// setActiveContact(rootGoal.collaboration.collaborators[0].name); -// } -// if (showChangesModal.typeAtPriority === "modifiedGoals") { -// const incGoal: GoalItem = { ...showChangesModal.goals[0] }; -// const currGoal = await getGoal(showChangesModal.parentId); -// setUpdateList({ ...findGoalTagChanges(currGoal, incGoal) }); -// } -// setCurrentDisplay(showChangesModal.typeAtPriority); -// setActiveGoal(goal); -// } -// }; -// getInbox(); -// }, [showChangesModal]); + const getSubgoalsList = () => ( +
+ {newGoals.map(({ goal, intent }) => ( +
+ { + setUnselectedChanges([ + ...(e.target.checked + ? unselectedChanges.filter((id) => id !== goal.id) + : [...unselectedChanges, goal.id]), + ]); + }} + className="checkbox" + /> + {goal.title} + {/* + {intent} + */} +
+ ))} +
+ ); -// return ( -// { -// setShowChangesModal(null); -// }} -// closable={false} -// footer={null} -// > -// {showChangesModal && activeGoal && ( -// <> -// {activeGoal && ( -//

-//

-//

-// )} -// {getChanges()} -// -// -// -// )} -// -// ); -// return
; -// }; + const deleteChanges = async () => { + if (!activeGoal) { + return; + } + const removeChanges = currentDisplay === "subgoals" ? newGoals.map(({ goal }) => goal.id) : [activeGoal.id]; + if (currentDisplay !== "none") { + await deleteGoalChangesInID(activeGoal.rootGoalId, participants[activePPT].relId, currentDisplay, removeChanges); + } + setCurrentDisplay("none"); + }; + const acceptChanges = async () => { + if (!activeGoal) { + return; + } + if (currentDisplay !== "none") { + await deleteChanges(); + } + if (currentDisplay === "subgoals") { + await acceptSelectedSubgoals( + newGoals.filter(({ goal }) => !unselectedChanges.includes(goal.id)).map(({ goal }) => goal), + activeGoal, + ); + setUnselectedChanges([]); + setNewGoals([]); + } else if (currentDisplay === "modifiedGoals") { + await acceptSelectedTags(unselectedChanges, updateList, activeGoal); + setUnselectedChanges([]); + setUpdateList({ schemaVersion: {}, prettierVersion: {} }); + } + setCurrentDisplay("none"); + }; -// export default DisplayChangesModal; + const getChanges = async () => { + if (showChangesModal && participants.length > 0 && activePPT >= 0) { + const { typeAtPriority, goals, parentId } = await jumpToLowestChanges( + showChangesModal.id, + participants[activePPT].relId, + ); + + if (typeAtPriority === "none") { + await updateGoal(showChangesModal.rootGoalId, { newUpdates: false }); + window.history.back(); + } + const changedGoal = await getGoal(parentId); + if (changedGoal) { + setActiveGoal({ ...changedGoal }); + if (typeAtPriority === "subgoals") { + setNewGoals(goals || []); + } else if (typeAtPriority === "modifiedGoals") { + const incGoal: GoalItem = { ...goals[0].goal }; + setUpdateList({ ...findGoalTagChanges(changedGoal, incGoal) }); + } + if (currentDisplay !== typeAtPriority) { + setCurrentDisplay(typeAtPriority); + } + } + } + }; + + useEffect(() => { + getChanges(); + }, [activePPT, currentDisplay]); + + useEffect(() => { + async function init() { + if (!showChangesModal) { + return; + } + const inbox = await getInboxItem(showChangesModal.id); + console.log("🚀 ~ file: DisplayChangesModal.tsx:190 ~ init ~ inbox:", inbox); + const ppsList = (await getAllContacts()).filter((ele) => Object.keys(inbox.changes).includes(ele.relId)); + setParticipants([...ppsList]); + setActivePPT(0); + } + init(); + }, []); + return ( + { + window.history.back(); + }} + closable={false} + footer={null} + > + {showChangesModal && ( + <> + { + setShowSuggestions(false); + }} + rightNav={() => { + setShowSuggestions(true); + }} + /> +
+ {participants.map((ele) => ( + + ))} +
+ {activeGoal && participants.length > 0 && ( +

+

+

+ )} + {/* )} */} + {(currentDisplay === "archived" || currentDisplay === "deleted") &&
} + {currentDisplay === "modifiedGoals" && getEditChangesList()} + {currentDisplay === "subgoals" && getSubgoalsList()} +
+ {activeGoal && ( + <> + + + + )} +
+ + )} + + ); + return
; +}; + +export default DisplayChangesModal; diff --git a/src/components/GoalsComponents/DisplayChangesModal/Header.tsx b/src/components/GoalsComponents/DisplayChangesModal/Header.tsx index 0c97f5e8b..e14fc414f 100644 --- a/src/components/GoalsComponents/DisplayChangesModal/Header.tsx +++ b/src/components/GoalsComponents/DisplayChangesModal/Header.tsx @@ -9,44 +9,31 @@ const Header = ({ }: { title: string; contactName: string; - currentDisplay: typeOfChange | "none" | "conversionRequest"; + currentDisplay: typeOfChange | "none"; }) => { - if (currentDisplay === "conversionRequest") { - return ( - <> - {" "} - {contactName} is also working on {title}. Do you want to collaborate? - - ); - } - switch (currentDisplay) { case "subgoals": return ( <> - {" "} - {contactName} added to {title}.
Add as well ? + {contactName} added to {title}.    Add as well ? ); case "modifiedGoals": return ( <> - {" "} - {contactName} made changes in {title}.
Make changes ?{" "} + {contactName} made changes in {title}.    Make changes ? ); case "deleted": return ( <> - {" "} - {contactName} deleted {title}.{" "} + {contactName} deleted {title}. ); case "archived": return ( <> - {" "} - {contactName} completed {title}{" "} + {contactName} completed {title}. ); default: diff --git a/src/components/GoalsComponents/DisplayChangesModal/IgnoreBtn.tsx b/src/components/GoalsComponents/DisplayChangesModal/IgnoreBtn.tsx index 7e06f56e3..5283cf5b4 100644 --- a/src/components/GoalsComponents/DisplayChangesModal/IgnoreBtn.tsx +++ b/src/components/GoalsComponents/DisplayChangesModal/IgnoreBtn.tsx @@ -4,54 +4,25 @@ import { useRecoilValue } from "recoil"; import ignore from "@assets/images/ignore.svg"; import { darkModeState } from "@src/store"; -import { GoalItem } from "@src/models/GoalItem"; -import { getTypeAtPriority } from "@src/helpers/GoalProcessor"; -import { deleteGoalChangesInID, getInboxItem, removeGoalInbox } from "@src/api/InboxAPI"; -import { IDisplayChangesModal } from "@src/Interfaces/IDisplayChangesModal"; -import { changeNewUpdatesStatus, convertSharedGoalToColab } from "@src/api/GoalsAPI"; interface IgnoreBtnProps { - goal: GoalItem; - showChangesModal: IDisplayChangesModal; - setShowChangesModal: React.Dispatch>; + deleteChanges: () => Promise; } -const IgnoreBtn = ({ showChangesModal, goal, setShowChangesModal }: IgnoreBtnProps) => { - const { typeAtPriority } = showChangesModal; - const isConversionRequest = typeAtPriority === "conversionRequest"; +const IgnoreBtn = ({ deleteChanges }: IgnoreBtnProps) => { const darkModeStatus = useRecoilValue(darkModeState); - - const handleClick = async () => { - let deleteInbox = false; - if (isConversionRequest) { - deleteInbox = true; - convertSharedGoalToColab(goal.id, false); - } else { - const removeChanges = showChangesModal.goals.map((colabGoal: GoalItem) => colabGoal.id); - if (typeAtPriority !== "none") { - await deleteGoalChangesInID(goal.rootGoalId, typeAtPriority, removeChanges); - } - } - const inbox = await getInboxItem(goal.rootGoalId); - if (deleteInbox || getTypeAtPriority(inbox.goalChanges).typeAtPriority === "none") { - await changeNewUpdatesStatus(false, goal.rootGoalId).catch((err) => console.log(err)); - removeGoalInbox(goal.rootGoalId); - } - setShowChangesModal(null); - }; return ( ); }; diff --git a/src/components/GoalsComponents/GoalConfigModal/ConfigGoal.tsx b/src/components/GoalsComponents/GoalConfigModal/ConfigGoal.tsx index c224f824f..92424073d 100644 --- a/src/components/GoalsComponents/GoalConfigModal/ConfigGoal.tsx +++ b/src/components/GoalsComponents/GoalConfigModal/ConfigGoal.tsx @@ -117,9 +117,12 @@ const ConfigGoal = ({ goal, action }: { action: "Update" | "Create"; goal: GoalI return; } const goalColor = colorPalleteList[colorIndex]; - if (state.displayPartnerMode && state.goalsHistory) { - const rootGoalId = state.goalsHistory[0].goalID; - const rootGoal = await getSharedWMGoal(rootGoalId); + if (state.displayPartnerMode) { + let rootGoal = goal; + if (state.goalsHistory && state.goalsHistory.length > 0) { + const rootGoalId = state.goalsHistory[0].goalID; + rootGoal = await getSharedWMGoal(rootGoalId); + } suggestChanges(rootGoal, getFinalTags(), title, goalColor, subGoalsHistory.length); } else { await modifyGoal(goal.id, getFinalTags(), title, goalColor, [...ancestors, goal.id]); diff --git a/src/components/GoalsComponents/MyGoal.tsx b/src/components/GoalsComponents/MyGoal.tsx index 8fa19266a..3eaf51496 100644 --- a/src/components/GoalsComponents/MyGoal.tsx +++ b/src/components/GoalsComponents/MyGoal.tsx @@ -5,14 +5,16 @@ import { useRecoilState, useRecoilValue, useSetRecoilState } from "recoil"; import pencil from "@assets/images/pencil.svg"; import { unarchiveIcon } from "@src/assets"; -import useGoalStore from "@src/hooks/useGoalStore"; import { GoalItem } from "@src/models/GoalItem"; import { unarchiveUserGoal } from "@src/api/GoalsAPI"; import { replaceUrlsWithText, summarizeUrl } from "@src/utils/patterns"; import { darkModeState, displayPartnerMode, lastAction } from "@src/store"; import { displayGoalId, displayUpdateGoal, goalsHistory, displayChangesModal } from "@src/store/GoalsState"; +import useGoalStore from "@src/hooks/useGoalStore"; +import NotificationSymbol from "@src/common/NotificationSymbol"; +import { jumpToLowestChanges, getHistoryUptoGoal } from "@src/helpers/GoalProcessor"; import GoalAvatar from "./GoalAvatar"; interface MyGoalProps { @@ -121,29 +123,13 @@ const MyGoal: React.FC = ({ goal, showActions, setShowActions }) => if (archived || (showPartnerMode && goal.parentGoalId !== "root")) { return; } - // if (goal.collaboration.newUpdates || goal.shared.conversionRequests.status) { - // handleDisplayChanges(); - // if (goal.shared.conversionRequests.status) { - // setShowChangesModal({ typeAtPriority: "conversionRequest", parentId: goal.id, goals: [] }); - // } else { - // const res = await jumpToLowestChanges(goal.rootGoalId); - // const pathToGoal = await getHistoryUptoGoal(res.parentId); - // if (pathToGoal.length > 1) { - // pathToGoal.pop(); - // setSubGoalHistory([...pathToGoal]); - // setSelectedGoalId(pathToGoal.slice(-1)[0].goalID); - // } - // setShowChangesModal(res); - // } - // } else { - navigate("/MyGoals", { - state: { - ...location.state, - from: "", - displayGoalActions: goal, - }, - }); - // } + const navState = { ...location.state, from: "" }; + if (goal.newUpdates) { + navState.displayChanges = goal; + } else { + navState.displayGoalActions = goal; + } + navigate("/MyGoals", { state: navState }); } useEffect(() => { if (showActions !== defaultTap) { @@ -195,9 +181,7 @@ const MyGoal: React.FC = ({ goal, showActions, setShowActions }) => background: `radial-gradient(50% 50% at 50% 50%, ${goal.goalColor}33 79.17%, ${goal.goalColor} 100%)`, }} > - {/* {(goal.collaboration.newUpdates || goal.shared.conversionRequests.status) && ( - - )} */} + {goal.newUpdates && }
diff --git a/src/components/GoalsComponents/MyGoalActions/MyGoalActions.tsx b/src/components/GoalsComponents/MyGoalActions/MyGoalActions.tsx index 7d139b70d..8d43e1b6d 100644 --- a/src/components/GoalsComponents/MyGoalActions/MyGoalActions.tsx +++ b/src/components/GoalsComponents/MyGoalActions/MyGoalActions.tsx @@ -18,7 +18,7 @@ import { GoalItem } from "@src/models/GoalItem"; import { themeState } from "@src/store/ThemeState"; import { goalsHistory } from "@src/store/GoalsState"; import { confirmAction } from "@src/Interfaces/IPopupModals"; -// import { convertSharedWMGoalToColab } from "@src/api/SharedWMAPI"; +import { convertSharedWMGoalToColab } from "@src/api/SharedWMAPI"; import { archiveThisGoal, removeThisGoal } from "@src/helpers/GoalActionHelper"; import ActionDiv from "./ActionDiv"; @@ -52,7 +52,7 @@ const MyGoalActions = ({ goal, open }: { open: boolean; goal: GoalItem }) => { await archiveThisGoal(goal, ancestors); setLastAction("goalArchived"); } else if (action === "colabRequest") { - // await convertSharedWMGoalToColab(goal); + await convertSharedWMGoalToColab(goal); window.history.back(); } else { return; diff --git a/src/global.scss b/src/global.scss index 288e1a3db..af328446f 100644 --- a/src/global.scss +++ b/src/global.scss @@ -238,7 +238,11 @@ h6 { border-radius: 10px; } } - +.popupModal-dark { + input { + color: white; + } +} .colorPallette { display: flex; gap: 20px; diff --git a/src/helpers/GoalLocStateHandler.tsx b/src/helpers/GoalLocStateHandler.tsx index 8b1b41030..b09957922 100644 --- a/src/helpers/GoalLocStateHandler.tsx +++ b/src/helpers/GoalLocStateHandler.tsx @@ -12,6 +12,7 @@ import { displayGoalActions, displayAddContact, displayParticipants, + displayChangesModal, } from "@src/store/GoalsState"; const GoalLocStateHandler = () => { @@ -23,6 +24,7 @@ const GoalLocStateHandler = () => { const [showUpdateGoal, setShowUpdateGoal] = useRecoilState(displayUpdateGoal); const [showShareModal, setShowShareModal] = useRecoilState(displayShareModal); const [showGoalActions, setShowGoalActions] = useRecoilState(displayGoalActions); + const [showChangesModal, setShowChangesModal] = useRecoilState(displayChangesModal); const [showParticipants, setShowParticipants] = useRecoilState(displayParticipants); const [showConfirmation, setShowConfirmation] = useRecoilState(displayConfirmation); const [showAddContactModal, setShowAddContactModal] = useRecoilState(displayAddContact); @@ -33,6 +35,11 @@ const GoalLocStateHandler = () => { setSubGoalHistory([...(locationState.goalsHistory || [])]); setSelectedGoalId(locationState.activeGoalId || "root"); } + if (showChangesModal && !locationState.displayChanges) { + setShowChangesModal(null); + } else if (locationState.displayChanges) { + setShowChangesModal(locationState.displayChanges); + } if (activePartner && !locationState.displayPartner) { setActivePartner(null); } else if (locationState.displayPartner) { diff --git a/src/helpers/GoalProcessor.ts b/src/helpers/GoalProcessor.ts index ac93bccf7..20c790a2a 100644 --- a/src/helpers/GoalProcessor.ts +++ b/src/helpers/GoalProcessor.ts @@ -4,7 +4,7 @@ import { getGoal } from "@src/api/GoalsAPI"; import { colorPalleteList } from "@src/utils"; import { GoalItem } from "@src/models/GoalItem"; import { getInboxItem } from "@src/api/InboxAPI"; -import { changesInGoal, IChangesInGoal, InboxItem, typeOfChange } from "@src/models/InboxItem"; +import { changesInGoal, IChangesInGoal, InboxItem, typeOfChange, typeOfIntent } from "@src/models/InboxItem"; import { ITagsAllowedToDisplay, ITagsChanges } from "@src/Interfaces/IDisplayChangesModal"; // export const createSentFromTags = (goal: GoalItem) => @@ -132,16 +132,17 @@ export const getTypeAtPriority = (goalChanges: IChangesInGoal) => { return { typeAtPriority }; }; -export const jumpToLowestChanges = async (id: string) => { +export const jumpToLowestChanges = async (id: string, relId: string) => { const inbox: InboxItem = await getInboxItem(id); let typeAtPriority: typeOfChange | "none" = "none"; if (inbox) { - const { goalChanges } = inbox; + const goalChanges = inbox.changes[relId]; typeAtPriority = getTypeAtPriority(goalChanges).typeAtPriority; if (typeAtPriority !== "none") { goalChanges[typeAtPriority].sort((a: { level: number }, b: { level: number }) => a.level - b.level); - let goals: GoalItem[] = []; + let goals: { intent: typeOfIntent; goal: GoalItem }[] = []; const goalAtPriority = goalChanges[typeAtPriority][0]; + console.log("🚀 ~ file: GoalProcessor.ts:145 ~ jumpToLowestChanges ~ goalAtPriority:", goalAtPriority); const parentId = "id" in goalAtPriority ? goalAtPriority.id @@ -152,18 +153,20 @@ export const jumpToLowestChanges = async (id: string) => { return { typeAtPriority, parentId, goals: [await getGoal(parentId)] }; } if (typeAtPriority === "subgoals") { - goalChanges.subgoals.forEach((ele: changesInGoal) => { - if (ele.goal.parentGoalId === parentId) goals.push(ele.goal); + goalChanges.subgoals.forEach(({ intent, goal }) => { + if (goal.parentGoalId === parentId) goals.push({ intent, goal }); }); } if (typeAtPriority === "modifiedGoals") { - let goal = createGoalObjectFromTags({}); - goalChanges.modifiedGoals.forEach((ele) => { - if (ele.goal.id === parentId) { - goal = { ...goal, ...ele.goal }; + let modifiedGoal = createGoalObjectFromTags({}); + let goalIntent; + goalChanges.modifiedGoals.forEach(({ goal, intent }) => { + if (goal.id === parentId) { + modifiedGoal = { ...modifiedGoal, ...goal }; + goalIntent = intent; } }); - goals = [goal]; + goals = [{ intent: goalIntent, goal: modifiedGoal }]; } return { @@ -191,7 +194,6 @@ export const findGoalTagChanges = (goal1: GoalItem, goal2: GoalItem) => { "beforeTime", "goalColor", "language", - "link", ]; const res: ITagsChanges = { schemaVersion: {}, prettierVersion: {} }; const goal1Tags = formatTagsToText(goal1); diff --git a/src/helpers/InboxProcessor.ts b/src/helpers/InboxProcessor.ts index 15b773456..82e10eb1a 100644 --- a/src/helpers/InboxProcessor.ts +++ b/src/helpers/InboxProcessor.ts @@ -5,11 +5,8 @@ import { getDefaultValueOfGoalChanges } from "@src/utils/defaultGenerators"; import { addGoal, addIntoSublist, - archiveUserGoal, // changeNewUpdatesStatus, getGoal, - notifyNewColabRequest, - removeGoalWithChildrens, updateGoal, } from "@src/api/GoalsAPI"; import { addGoalChangesInID, createEmptyInboxItem, getInboxItem } from "@src/api/InboxAPI"; @@ -21,11 +18,11 @@ import { removeSharedWMGoal, updateSharedWMGoal, } from "@src/api/SharedWMAPI"; -import { IDisplayChangesModal, ITagChangesSchemaVersion, ITagsChanges } from "@src/Interfaces/IDisplayChangesModal"; +import { ITagChangesSchemaVersion, ITagsChanges } from "@src/Interfaces/IDisplayChangesModal"; import { fixDateVlauesInGoalObject } from "@src/utils"; export const handleIncomingChanges = async (payload, relId) => { - if (payload.type === "sharer") { + if (payload.type === "sharer" && (await getSharedWMGoal(payload.rootGoalId))) { const incGoal = await getSharedWMGoal(payload.rootGoalId); if (!incGoal || incGoal.participants.find((ele) => ele.relId === relId && ele.following) === undefined) { console.log("Changes ignored"); @@ -61,10 +58,8 @@ export const handleIncomingChanges = async (payload, relId) => { archiveSharedWMGoal(goal).catch((err) => console.log(err, "failed to archive")), ); } - } else if (payload.type === "collaborationInvite") { - notifyNewColabRequest(payload.goal.id, payload.relId).catch(() => console.log("failed to notify about new colab")); - } else if (["collaboration", "suggestion"].includes(payload.type)) { - const { rootGoalId, changes, changeType, relId } = payload; + } else if (["sharer", "suggestion"].includes(payload.type)) { + const { rootGoalId, changes, changeType } = payload; const rootGoal = await getGoal(rootGoalId); if (rootGoal) { let inbox: InboxItem = await getInboxItem(rootGoalId); @@ -74,6 +69,10 @@ export const handleIncomingChanges = async (payload, relId) => { await createEmptyInboxItem(rootGoalId); inbox = await getInboxItem(rootGoalId); } + await Promise.all([ + updateGoal(rootGoalId, { newUpdates: true }), + await addGoalChangesInID(rootGoalId, relId, defaultChanges), + ]); // const goalItemExist = changeType === "subgoals" || changeType === "modifiedGoals"; // changes.forEach(async (ele) => { // console.log(ele) @@ -81,25 +80,16 @@ export const handleIncomingChanges = async (payload, relId) => { // }); // changeNewUpdatesStatus(true, rootGoalId).catch((err) => console.log(err)); // @ts-ignore - await addGoalChangesInID(rootGoalId, defaultChanges, relId); } } }; -export const acceptSelectedSubgoals = async ( - unselectedGoalIds: string[], - showChangesModal: IDisplayChangesModal, - parentGoal: GoalItem, -) => { +export const acceptSelectedSubgoals = async (selectedGoals: GoalItem[], parentGoal: GoalItem) => { try { const childrens: string[] = []; - showChangesModal.goals.forEach(async (colabGoal: GoalItem) => { - if (!unselectedGoalIds.includes(colabGoal.id)) { - addGoal({ - ...fixDateVlauesInGoalObject(colabGoal), - }).catch((err) => console.log(err)); - childrens.push(colabGoal.id); - } + selectedGoals.forEach(async (goal: GoalItem) => { + addGoal(fixDateVlauesInGoalObject(goal)).catch((err) => console.log(err)); + childrens.push(goal.id); }); await addIntoSublist(parentGoal.id, childrens); return "Done!!"; @@ -129,21 +119,3 @@ export const acceptSelectedTags = async (unselectedTags: string[], updateList: I due: finalChanges.due ? new Date(finalChanges.due) : null, }); }; - -export const acceptChangesOf = async ( - unselectedChanges: string[], - showChangesModal: IDisplayChangesModal, - updateList: ITagsChanges, - activeGoal: GoalItem | undefined, -) => { - const goal = showChangesModal.goals[0]; - if (showChangesModal.typeAtPriority === "subgoals" && activeGoal) { - await acceptSelectedSubgoals(unselectedChanges, showChangesModal, activeGoal); - } else if (showChangesModal.typeAtPriority === "modifiedGoals" && updateList) { - await acceptSelectedTags(unselectedChanges, updateList, goal); - } else if (showChangesModal.typeAtPriority === "deleted") { - await removeGoalWithChildrens(goal); - } else if (showChangesModal.typeAtPriority === "archived") { - await archiveUserGoal(goal); - } -}; diff --git a/src/helpers/PartnerController.ts b/src/helpers/PartnerController.ts index e0f14ff85..4cf07937f 100644 --- a/src/helpers/PartnerController.ts +++ b/src/helpers/PartnerController.ts @@ -56,7 +56,8 @@ export const suggestChanges = async ( .filter((ele: string) => ele !== "") .join(" "), goalColor, + newUpdates: false, }; const { participants, ...changes } = goal; - sendUpdate(rootGoal.participants, rootGoal.id, "modifiedGoals", [{ level, changes }]); + sendUpdate(rootGoal.participants, rootGoal.id, "modifiedGoals", [{ level, goal: changes }]); }; diff --git a/src/models/GoalItem.ts b/src/models/GoalItem.ts index 870ded652..3c95f6535 100644 --- a/src/models/GoalItem.ts +++ b/src/models/GoalItem.ts @@ -31,4 +31,5 @@ export interface GoalItem { perWeek: string | null; }; typeOfGoal: "myGoal" | "shared"; + newUpdates: boolean; } diff --git a/src/models/db.ts b/src/models/db.ts index a291f0437..9884db180 100644 --- a/src/models/db.ts +++ b/src/models/db.ts @@ -8,7 +8,7 @@ import { TaskItem } from "./TaskItem"; import { GCustomItem } from "./GCustomItem"; import { DumpboxItem } from "./DumpboxItem"; -export const dexieVersion = 15; +export const dexieVersion = 16; const currentVersion = Number(localStorage.getItem("dexieVersion") || dexieVersion); localStorage.setItem("dexieVersion", `${dexieVersion}`); @@ -108,6 +108,17 @@ export class ZinZenDB extends Dexie { delete contact.sharedGoals; }); } + if (currentVersion < 16) { + console.log("processing updates for 16th version"); + const sharedWMCollection = trans.table("sharedWMCollection"); + const goalsCollection = trans.table("goalsCollection"); + sharedWMCollection.toCollection().modify((goal: GoalItem) => { + goal.newUpdates = false; + }); + goalsCollection.toCollection().modify((goal: GoalItem) => { + goal.newUpdates = false; + }); + } }); } } diff --git a/src/override.scss b/src/override.scss index ace550deb..731a864dc 100644 --- a/src/override.scss +++ b/src/override.scss @@ -1,6 +1,11 @@ .App-light, -.popupModal { +.popupModal, +.App-dark, +.popupModal-dark { .checkbox { + .ant-checkbox { + background: transparent !important; + } .ant-radio-checked .ant-radio-inner, .ant-checkbox-checked .ant-checkbox-inner { border: 2px solid var(--Linear, var(--icon-grad-1)) !important ; @@ -17,25 +22,25 @@ } } } -.App-dark, -.popupModal-dark { - .checkbox { - .ant-radio-checked .ant-radio-inner, - .ant-checkbox-checked .ant-checkbox-inner { - border-color: var(--selection-color) !important ; - background-color: var(--selection-color) !important; - } - .ant-radio:hover .ant-radio-inner, - .ant-checkbox:hover .ant-checkbox-inner, - .ant-checkbox-checked:after { - border-color: var(--selection-color) !important; - } - .ant-radio-checked .ant-radio-inner:focus, - .ant-checkbox-checked .ant-checkbox-inner:focus { - border-color: var(--selection-color) !important; - } - } -} +// .App-dark, +// .popupModal-dark { +// .checkbox { +// .ant-radio-checked .ant-radio-inner, +// .ant-checkbox-checked .ant-checkbox-inner { +// border-color: var(--selection-color) !important ; +// background-color: var(--selection-color) !important; +// } +// .ant-radio:hover .ant-radio-inner, +// .ant-checkbox:hover .ant-checkbox-inner, +// .ant-checkbox-checked:after { +// border-color: var(--selection-color) !important; +// } +// .ant-radio-checked .ant-radio-inner:focus, +// .ant-checkbox-checked .ant-checkbox-inner:focus { +// border-color: var(--selection-color) !important; +// } +// } +// } .ant-modal-mask { background-color: rgba(87, 87, 87, 0.4) !important; @@ -85,7 +90,6 @@ /*ProgressBar*/ .progress-dark { .ant-progress-text { - color: white!important; + color: white !important; } } - diff --git a/src/pages/GoalsPage/MyGoals.tsx b/src/pages/GoalsPage/MyGoals.tsx index 3702bab81..96403e3da 100644 --- a/src/pages/GoalsPage/MyGoals.tsx +++ b/src/pages/GoalsPage/MyGoals.tsx @@ -87,6 +87,7 @@ export const MyGoals = () => { {showShareModal && } {showGoalActions && } + {showChangesModal && }
{selectedGoalId === "root" ? (
@@ -110,7 +111,6 @@ export const MyGoals = () => { ) : ( )} - {/* {showChangesModal && } */} {activeGoals?.length === 0 && ( ({ ...goal, - start: goal.start ? new Date(goal.start) : null, - due: goal.due ? new Date(goal.due) : null, + start: goal.start ? new Date(goal.start).toString() : null, + due: goal.due ? new Date(goal.due).toString() : null, }); export function inheritParentProps(newGoal: GoalItem, parentGoal: GoalItem) {