diff --git a/src/Interfaces/Sharing.ts b/src/Interfaces/Sharing.ts new file mode 100644 index 000000000..f2bc586e4 --- /dev/null +++ b/src/Interfaces/Sharing.ts @@ -0,0 +1,9 @@ +export interface ICollaboration { + newUpdates: boolean; + collaborators: { relId: string; name: string }[]; +} + +export interface IShared { + conversionRequests: { status: boolean; senders: string[] }; + contacts: { relId: string; name: string }[]; +} diff --git a/src/api/ContactsAPI/index.ts b/src/api/ContactsAPI/index.ts index b14ce66c5..99237e730 100644 --- a/src/api/ContactsAPI/index.ts +++ b/src/api/ContactsAPI/index.ts @@ -9,6 +9,10 @@ export const getAllContacts = async () => { return allContacts; }; +export const getPartnersCount = async () => { + return db.contactsCollection.count(); +}; + export const addContact = async (contactName: string, relId: string, accepted = false) => { const name = `${contactName.charAt(0).toUpperCase() + contactName.slice(1)}`; const currentDate = new Date(); @@ -16,8 +20,6 @@ export const addContact = async (contactName: string, relId: string, accepted = id: uuidv4(), name, relId, - sharedGoals: [], - collaborativeGoals: [], createdAt: currentDate, accepted, }; diff --git a/src/api/PartnerAPI/index.ts b/src/api/PartnerAPI/index.ts deleted file mode 100644 index 4596e623b..000000000 --- a/src/api/PartnerAPI/index.ts +++ /dev/null @@ -1,51 +0,0 @@ -/* eslint-disable no-param-reassign */ -import { db } from "@models"; -import { GoalItem } from "@src/models/GoalItem"; -import { PartnerItem } from "@src/models/PartnerItem"; - -export const getPartnerByRelId = async (relId: string) => { - const partner: PartnerItem[] = await db.partnersCollection.where("relId").equals(relId).toArray(); - return partner.length > 0 ? partner[0] : null; -}; - -export const getPartnersCount = async () => { - return db.partnersCollection.count(); -}; - -export const createPartner = async (relId: string, name: string) => { - db.transaction("rw", db.partnersCollection, async () => { - await db.partnersCollection.add({ - relId, - name, - goals: [], - }); - }).catch((e) => { - console.log(e.stack || e); - }); -}; - -export const addGoalToPartner = async (relId: string, goal: GoalItem) => { - db.transaction("rw", db.partnersCollection, async () => { - await db.partnersCollection - .where("relId") - .equals(relId) - .modify((obj: PartnerItem) => { - obj.goals.push(goal); - }); - }).catch((e) => { - console.log(e.stack || e); - }); -}; - -export const removeGoalFromPartner = async (relId: string, goal: GoalItem) => { - db.transaction("rw", db.partnersCollection, async () => { - await db.partnersCollection - .where("relId") - .equals(relId) - .modify((obj: PartnerItem) => { - obj.goals = [...obj.goals.filter((pg) => pg.id !== goal.id)]; - }); - }).catch((e) => { - console.log(e.stack || e); - }); -}; diff --git a/src/api/SharedWMAPI/index.ts b/src/api/SharedWMAPI/index.ts index 1f87fcb55..18cbcb61c 100644 --- a/src/api/SharedWMAPI/index.ts +++ b/src/api/SharedWMAPI/index.ts @@ -67,6 +67,16 @@ export const getActiveSharedWMGoals = async () => { return activeGoals; }; +export const getRootGoalsOfPartner = async (relId: string) => { + return ( + await db.sharedWMCollection + .where("parentGoalId") + .equals("root") + .and((x) => x.participants[0].relId === relId) + .sortBy("createdAt") + ).reverse(); +}; + export const updateSharedWMGoal = async (id: string, changes: object) => { db.transaction("rw", db.sharedWMCollection, async () => { await db.sharedWMCollection.update(id, changes).then((updated) => updated); diff --git a/src/components/BottomNavbar/BottomNavbar.tsx b/src/components/BottomNavbar/BottomNavbar.tsx index ff795b810..6c69e3988 100644 --- a/src/components/BottomNavbar/BottomNavbar.tsx +++ b/src/components/BottomNavbar/BottomNavbar.tsx @@ -119,7 +119,7 @@ const BottomNavbar = ({ title }: { title: string }) => { title={themeSelection ? "ArrowIcon" : "JournalIcon"} /> {themeSelection ?

Next

:

{t("Journal")}

} - {title !== "myTime" && title !== "Inbox" && title !== "Focus" && } + {title !== "myTime" && title !== "Focus" && } diff --git a/src/components/GoalsComponents/GoalAvatar.tsx b/src/components/GoalsComponents/GoalAvatar.tsx index bb8c26b3a..7e59d7a99 100644 --- a/src/components/GoalsComponents/GoalAvatar.tsx +++ b/src/components/GoalsComponents/GoalAvatar.tsx @@ -1,13 +1,10 @@ +import React from "react"; import Icon from "@src/common/Icon"; import { GoalItem } from "@src/models/GoalItem"; -import { openInbox } from "@src/store"; import { getSvgForGoalPps } from "@src/utils"; -import { Tooltip } from "antd"; -import React from "react"; import { useLocation, useNavigate } from "react-router-dom"; -import { useRecoilValue } from "recoil"; -const Avatar = ({ goal }: { goal: GoalItem }) => { +const GoalAvatar = ({ goal }: { goal: GoalItem }) => { const location = useLocation(); const navigate = useNavigate(); const { participants, goalColor } = goal; @@ -37,26 +34,4 @@ const Avatar = ({ goal }: { goal: GoalItem }) => { ); }; -const GoalAvatar = ({ goal }: { goal: GoalItem }) => { - const isInboxOpen = useRecoilValue(openInbox); - - return isInboxOpen ? ( - -
- -
-
- ) : ( - - ); -}; - export default GoalAvatar; diff --git a/src/components/GoalsComponents/GoalSublist/GoalSublist.tsx b/src/components/GoalsComponents/GoalSublist/GoalSublist.tsx index 25811ccf1..3d0afe05c 100644 --- a/src/components/GoalsComponents/GoalSublist/GoalSublist.tsx +++ b/src/components/GoalsComponents/GoalSublist/GoalSublist.tsx @@ -5,7 +5,7 @@ import { GoalItem } from "@src/models/GoalItem"; import { getChildrenGoals, getGoal } from "@src/api/GoalsAPI"; import { createGoalObjectFromTags } from "@src/helpers/GoalProcessor"; import { getSharedWMChildrenGoals, getSharedWMGoal } from "@src/api/SharedWMAPI"; -import { displayPartnerMode, lastAction, openInbox } from "@src/store"; +import { displayPartnerMode, lastAction } from "@src/store"; import { displayAddGoal, displayChangesModal, @@ -24,7 +24,6 @@ import ArchivedAccordion from "../ArchivedAccordion"; export const GoalSublist = () => { const action = useRecoilValue(lastAction); const goalID = useRecoilValue(displayGoalId); - const isInboxOpen = useRecoilValue(openInbox); const showAddGoal = useRecoilValue(displayAddGoal); const showUpdateGoal = useRecoilValue(displayUpdateGoal); const showChangesModal = useRecoilValue(displayChangesModal); @@ -41,17 +40,13 @@ export const GoalSublist = () => { }; useEffect(() => { - (isInboxOpen || showPartnerMode ? getSharedWMGoal(goalID) : getGoal(goalID)).then((parent) => - setParentGoal(parent), - ); + (showPartnerMode ? getSharedWMGoal(goalID) : getGoal(goalID)).then((parent) => setParentGoal(parent)); }, [goalID]); useEffect(() => { - (isInboxOpen || showPartnerMode ? getSharedWMChildrenGoals(goalID) : getChildrenGoals(goalID)).then( - (fetchedGoals) => { - handleChildrenGoals(fetchedGoals); - }, - ); + (showPartnerMode ? getSharedWMChildrenGoals(goalID) : getChildrenGoals(goalID)).then((fetchedGoals) => { + handleChildrenGoals(fetchedGoals); + }); }, [action, parentGoal, showAddGoal, showSuggestionModal, showChangesModal, showUpdateGoal]); return ( diff --git a/src/components/GoalsComponents/MyGoal.tsx b/src/components/GoalsComponents/MyGoal.tsx index ae3d2e9e7..1acf0c539 100644 --- a/src/components/GoalsComponents/MyGoal.tsx +++ b/src/components/GoalsComponents/MyGoal.tsx @@ -7,10 +7,9 @@ import pencil from "@assets/images/pencil.svg"; import { unarchiveIcon } from "@src/assets"; import { GoalItem } from "@src/models/GoalItem"; -import { getSvgForGoalPps } from "@src/utils"; import { unarchiveUserGoal } from "@src/api/GoalsAPI"; import { replaceUrlsWithText, summarizeUrl } from "@src/utils/patterns"; -import { darkModeState, displayPartnerMode, lastAction, openInbox } from "@src/store"; +import { darkModeState, displayPartnerMode, lastAction } from "@src/store"; import { displayGoalId, displayUpdateGoal, goalsHistory, displayChangesModal } from "@src/store/GoalsState"; import useGoalStore from "@src/hooks/useGoalStore"; @@ -82,7 +81,6 @@ const MyGoal: React.FC = ({ goal, showActions, setShowActions }) => // const sharedWithContact = goal.shared.contacts.length > 0 ? goal.shared.contacts[0].name : null; // const collabWithContact = // goal.collaboration.collaborators.length > 0 ? goal.collaboration.collaborators[0].name : null; - const participantsSvg = getSvgForGoalPps(goal.participants.length); const navigate = useNavigate(); const location = useLocation(); const { handleUpdateGoal } = useGoalStore(); @@ -91,7 +89,6 @@ const MyGoal: React.FC = ({ goal, showActions, setShowActions }) => const [selectedGoalId, setSelectedGoalId] = useRecoilState(displayGoalId); const [showChangesModal, setShowChangesModal] = useRecoilState(displayChangesModal); const [subGoalHistory, setSubGoalHistory] = useRecoilState(goalsHistory); - const isInboxOpen = useRecoilValue(openInbox); const showPartnerMode = useRecoilValue(displayPartnerMode); const setLastAction = useSetRecoilState(lastAction); @@ -162,7 +159,7 @@ const MyGoal: React.FC = ({ goal, showActions, setShowActions }) => }, [location]); const isActionVisible = () => { - return !archived && !isInboxOpen && !showPartnerMode && showActions.open === goal.id && showActions.click > 0; + return !archived && !showPartnerMode && showActions.open === goal.id && showActions.click > 0; }; return ( @@ -268,7 +265,7 @@ const MyGoal: React.FC = ({ goal, showActions, setShowActions }) => )} - {goal.participants.length > 0 && } + {!showPartnerMode && goal.participants.length > 0 && } {archived && (
- {((isSharedGoal && goal.parentGoalId === "root") || !isSharedGoal) && ( + {((isPartnerGoal && goal.parentGoalId === "root") || !isPartnerGoal) && (
{ e.stopPropagation(); - if (!isSharedGoal) { + if (!isPartnerGoal) { if (goal.typeOfGoal !== "myGoal" && goal.parentGoalId !== "root") { setShowToast({ message: "Sorry, you are not allowed to share", @@ -127,12 +123,12 @@ const MyGoalActions = ({ goal, open }: { open: boolean; goal: GoalItem }) => { }} >
)} - {!isSharedGoal && ( + {!isPartnerGoal && (
{ diff --git a/src/components/GoalsComponents/ShareGoalModal/AddContactModal.tsx b/src/components/GoalsComponents/ShareGoalModal/AddContactModal.tsx index d0e5b6ebf..491d73e34 100644 --- a/src/components/GoalsComponents/ShareGoalModal/AddContactModal.tsx +++ b/src/components/GoalsComponents/ShareGoalModal/AddContactModal.tsx @@ -32,7 +32,7 @@ const AddContactModal: React.FC = ({ showAddContactModal, const res = await initRelationship(); if (res.success && res.response.relId && res.response.relId.length > 0) { const { relId } = res.response; - await Promise.all([addContact(newContact?.contactName, relId), createPartner(relId, newContact.contactName)]); + await addContact(newContact?.contactName, relId); setNewContact({ ...newContact, relId }); const defaultPartner = localStorage.getItem("defaultPartner"); if (!defaultPartner) { @@ -70,8 +70,9 @@ const AddContactModal: React.FC = ({ showAddContactModal, setNewContact(null); handleCloseAddContact(); }} - className={`addContact-modal popupModal${darkModeStatus ? "-dark" : ""} ${darkModeStatus ? "dark" : "light" - }-theme${theme[darkModeStatus ? "dark" : "light"]}`} + className={`addContact-modal popupModal${darkModeStatus ? "-dark" : ""} ${ + darkModeStatus ? "dark" : "light" + }-theme${theme[darkModeStatus ? "dark" : "light"]}`} >

Add a contact name

= ({ title, debounceSearch }) => { const navigate = useNavigate(); const setShowToast = useSetRecoilState(displayToast); - const showInbox = useRecoilValue(displayInbox); const darkModeStatus = useRecoilValue(darkModeState); const subGoalHistory = useRecoilValue(goalsHistory); - const [isInboxOpen, setIsInboxOpen] = useRecoilState(openInbox); const [showPartnerMode, setShowPartnerMode] = useRecoilState(displayPartnerMode); const [displaySearch, setDisplaySearch] = useRecoilState(searchActive); @@ -56,9 +53,6 @@ const Header: React.FC = ({ title, debounceSearch }) => { }; const handlePopState = () => { const locationState = location.state || {}; - if (isInboxOpen || "isInboxOpen" in locationState) { - setIsInboxOpen(locationState?.isInboxOpen || false); - } if (displaySearch || locationState?.displaySearch) { setDisplaySearch(locationState?.displaySearch || false); } else if (showPartnerMode || locationState?.displayPartnerMode) { @@ -89,12 +83,12 @@ const Header: React.FC = ({ title, debounceSearch }) => {
{ - if (["myGoals", "Inbox"].includes(title)) { + if (title === "myGoals") { window.history.go(-subGoalHistory.length); } }} > - {isInboxOpen ? "Inbox" : t(title)} + {t(title)}
@@ -103,12 +97,7 @@ const Header: React.FC = ({ title, debounceSearch }) => { ) : !isNighttime && darkModeStatus ? ( ) : null} - {["myGoals", "Inbox"].includes(title) && !isInboxOpen && ( - - )} - {["myGoals", "Inbox"].includes(title) && showInbox && ( - - )} + {title === "myGoals" && }
diff --git a/src/components/Header/HeaderBtn.tsx b/src/components/Header/HeaderBtn.tsx index d2a52074b..a4f172b5a 100644 --- a/src/components/Header/HeaderBtn.tsx +++ b/src/components/Header/HeaderBtn.tsx @@ -1,13 +1,12 @@ import React from "react"; -import { openInbox, displayToast, darkModeState } from "@src/store"; +import { displayToast, darkModeState } from "@src/store"; import { useLocation, useNavigate } from "react-router-dom"; -import { useRecoilValue, useSetRecoilState, useRecoilState } from "recoil"; +import { useSetRecoilState, useRecoilState } from "recoil"; import Settings from "./Settings"; const HeaderBtn = ({ path, alt }: { path: string; alt: string }) => { const { state } = useLocation(); const navigate = useNavigate(); - const isInboxOpen = useRecoilValue(openInbox); const setShowToast = useSetRecoilState(displayToast); const [darkModeStatus, setDarkModeStatus] = useRecoilState(darkModeState); @@ -16,19 +15,6 @@ const HeaderBtn = ({ path, alt }: { path: string; alt: string }) => { setShowToast({ open: true, message: "Coming soon...", extra: "" }); } else if (alt === "zinzen search") { navigate("/MyGoals", { state: { ...state, displaySearch: true } }); - } else if (alt === "zinzen inbox") { - if (isInboxOpen) { - window.history.go(-((state?.goalsHistory?.length || 0) + 1)); - } else { - const newState = { ...state }; - if (newState.goalsHistory) { - delete newState.goalsHistory; - } - if (newState.activeGoalId) { - delete newState.activeGoalId; - } - navigate("/MyGoals", { state: { ...newState, goalsHistory: [], isInboxOpen: true } }); - } } else if (alt === "light mode") { localStorage.setItem("darkMode", darkModeStatus ? "off" : "on"); setDarkModeStatus(!darkModeStatus); diff --git a/src/components/ParticipantsNavbar.tsx b/src/components/ParticipantsNavbar.tsx index cb69b37e0..9991ad172 100644 --- a/src/components/ParticipantsNavbar.tsx +++ b/src/components/ParticipantsNavbar.tsx @@ -8,8 +8,8 @@ const ParticipantsNavbar = ({ setActivePartner, }: { list: ContactItem[]; - setActivePartner: React.Dispatch>; - activePartner: string; + activePartner: ContactItem; + setActivePartner: React.Dispatch>; }) => { return ( @@ -18,9 +18,9 @@ const ParticipantsNavbar = ({ key={contact.relId} type="button" onClick={() => { - setActivePartner(contact.relId); + setActivePartner(contact); }} - className={`bottom-nav-item ${activePartner === contact.relId ? "active" : ""}`} + className={`bottom-nav-item ${activePartner.relId === contact.relId ? "active" : ""}`} >

{contact.name}

diff --git a/src/helpers/GoalActionHelper.tsx b/src/helpers/GoalActionHelper.tsx index cf07541f8..1e473ee2a 100644 --- a/src/helpers/GoalActionHelper.tsx +++ b/src/helpers/GoalActionHelper.tsx @@ -1,31 +1,21 @@ import { GoalItem } from "@src/models/GoalItem"; import archiveSound from "@assets/archive.mp3"; import pageCrumplingSound from "@assets/page-crumpling-sound.mp3"; -import { archiveSharedWMGoal } from "@src/api/SharedWMAPI"; -import { moveToPartner, deleteSharedGoal, deleteGoal, archiveGoal } from "./GoalController"; +import { deleteSharedGoal, deleteGoal, archiveGoal } from "./GoalController"; const pageCrumple = new Audio(pageCrumplingSound); const doneSound = new Audio(archiveSound); -export const removeThisGoal = async ( - goal: GoalItem, - ancestors: string[], - isInboxOpen: boolean, - showPartnerMode: boolean, -) => { +export const removeThisGoal = async (goal: GoalItem, ancestors: string[], showPartnerMode: boolean) => { await pageCrumple.play(); - if (isInboxOpen) { - await moveToPartner(goal); - } else if (showPartnerMode) { + if (showPartnerMode) { await deleteSharedGoal(goal); } else { await deleteGoal(goal, ancestors); } }; -export const archiveThisGoal = async (goal: GoalItem, ancestors: string[], isInboxOpen: boolean) => { +export const archiveThisGoal = async (goal: GoalItem, ancestors: string[]) => { await doneSound.play(); - if (isInboxOpen) { - await archiveSharedWMGoal(goal); - } else await archiveGoal(goal, ancestors); + await archiveGoal(goal, ancestors); }; diff --git a/src/helpers/GoalController.ts b/src/helpers/GoalController.ts index c414b7e65..e658ea718 100644 --- a/src/helpers/GoalController.ts +++ b/src/helpers/GoalController.ts @@ -118,14 +118,3 @@ export const deleteSharedGoal = async (goal: GoalItem) => { }); } }; - -export const moveToPartner = async (goal: GoalItem) => { - const relId = localStorage.getItem("partner"); - if (!relId) { - return false; - } - await Promise.all([addGoalToPartner(relId, goal), removeSharedWMGoal(goal.id)]).catch((err) => { - console.log("Failed to move the goal into partner", err); - }); - return true; -}; diff --git a/src/helpers/GoalLocStateHandler.tsx b/src/helpers/GoalLocStateHandler.tsx index 27f07bd9b..1673c660c 100644 --- a/src/helpers/GoalLocStateHandler.tsx +++ b/src/helpers/GoalLocStateHandler.tsx @@ -2,8 +2,7 @@ import { useEffect } from "react"; import { useLocation } from "react-router-dom"; import { useRecoilState, useSetRecoilState } from "recoil"; import { ILocationState } from "@src/Interfaces"; -import { getActiveSharedWMGoals } from "@src/api/SharedWMAPI"; -import { displayInbox, displayConfirmation } from "@src/store"; +import { displayConfirmation } from "@src/store"; import { displayAddGoal, displayGoalId, @@ -17,8 +16,6 @@ import { const GoalLocStateHandler = () => { const location = useLocation(); - const [showInbox, setShowInbox] = useRecoilState(displayInbox); - const setSelectedGoalId = useSetRecoilState(displayGoalId); const [showAddGoal, setShowAddGoal] = useRecoilState(displayAddGoal); const [subGoalHistory, setSubGoalHistory] = useRecoilState(goalsHistory); @@ -31,15 +28,6 @@ const GoalLocStateHandler = () => { const handleLocationChange = () => { const locationState: ILocationState = location.state || {}; - getActiveSharedWMGoals().then((items) => { - if (items && items.length > 0) { - if (!showInbox) { - setShowInbox(true); - } - } else if (showInbox) { - setShowInbox(false); - } - }); if (subGoalHistory.length > 0 || ("goalsHistory" in locationState && "activeGoalId" in locationState)) { setSubGoalHistory([...(locationState.goalsHistory || [])]); setSelectedGoalId(locationState.activeGoalId || "root"); diff --git a/src/helpers/InboxProcessor.ts b/src/helpers/InboxProcessor.ts index 671c8f4fb..da28f4b4a 100644 --- a/src/helpers/InboxProcessor.ts +++ b/src/helpers/InboxProcessor.ts @@ -26,8 +26,8 @@ import { fixDateVlauesInGoalObject } from "@src/utils"; export const handleIncomingChanges = async (payload, relId) => { if (payload.type === "sharer") { - const goal = await getGoal(payload.rootGoalId); - if (!goal || goal.participants.find((ele) => ele.relId === relId && ele.following) === undefined) { + const incGoal = await getGoal(payload.rootGoalId); + if (!incGoal || incGoal.participants.find((ele) => ele.relId === relId && ele.following) === undefined) { return; } if (payload.changeType === "subgoals") { diff --git a/src/helpers/PartnerController.ts b/src/helpers/PartnerController.ts index d43cbcdaf..ef537c55a 100644 --- a/src/helpers/PartnerController.ts +++ b/src/helpers/PartnerController.ts @@ -48,7 +48,6 @@ export const suggestNewGoal = async ( newGoal.createdAt = `${new Date()}`; newGoal = inheritParentProps(newGoal, parentGoal); const subscribers = extractSubs(rootGoal); - console.log("🚀 ~ file: PartnerController.ts:55 ~ subscribers:", subscribers); await Promise.all(sendUpdate(subscribers, rootGoal.id, "subgoals", [{ level, goal: newGoal }])); }; diff --git a/src/hooks/useApp.tsx b/src/hooks/useApp.tsx index 143ab3d20..09b25fee3 100644 --- a/src/hooks/useApp.tsx +++ b/src/hooks/useApp.tsx @@ -44,7 +44,12 @@ function useApp() { if (ele.type === "shareMessage") { const { goalWithChildrens }: { goalWithChildrens: GoalItem[] } = ele; const rootGoal = goalWithChildrens[0]; - rootGoal.participants.push({ name: contactItem.name, relId, type: "sharer" }); + rootGoal.participants.push({ + name: contactItem.name, + relId, + type: "sharer", + following: false, + }); addSharedWMGoal(rootGoal) .then(() => { goalWithChildrens.slice(1).forEach((goal) => { @@ -53,7 +58,7 @@ function useApp() { }) .catch((err) => console.log(`Failed to add root goal ${rootGoal.title}`, err)); } else if (ele.type === "sharer") { - handleIncomingChanges(ele).then(() => setLastAction("goalNewUpdates")); + handleIncomingChanges(ele, relId).then(() => setLastAction("goalNewUpdates")); } // else if (["suggestion", "shared", "collaboration", "collaborationInvite"].includes(ele.type)) { // let typeOfSub = ele.rootGoalId ? await findTypeOfSub(ele.rootGoalId) : "none"; diff --git a/src/hooks/useGoalStore.tsx b/src/hooks/useGoalStore.tsx index e5b6434c5..8d88a7400 100644 --- a/src/hooks/useGoalStore.tsx +++ b/src/hooks/useGoalStore.tsx @@ -77,11 +77,6 @@ const useGoalStore = () => { const handleDisplayChanges = () => { navigate("/MyGoals", { state: location.state }); }; - - const handleOpenInbox = () => { - navigate("/MyGoals", { state: { ...location.state, displayInbox: true } }); - }; - const handleGoalActions = (id: string) => { navigate("/MyGoals", { state: { ...location.state, showGoalActions: id } }); }; @@ -89,7 +84,6 @@ const useGoalStore = () => { return { handleAddGoal, handleShareGoal, - handleOpenInbox, handleUpdateGoal, handleGoalActions, handleConfirmation, diff --git a/src/models/ContactItem.ts b/src/models/ContactItem.ts index afc6415ac..4eea0c8ea 100644 --- a/src/models/ContactItem.ts +++ b/src/models/ContactItem.ts @@ -1,13 +1,6 @@ -// @ts-nocheck - -import { GoalItem } from "./GoalItem"; - -/* eslint-disable */ export default interface ContactItem { id: string; name: string; - collaborativeGoals: { id: string; goal: GoalItem }[]; - sharedGoals: { id: string; goal: GoalItem }[]; relId: string; accepted: boolean; createdAt: Date; diff --git a/src/models/PartnerItem.ts b/src/models/PartnerItem.ts deleted file mode 100644 index 6b65379cf..000000000 --- a/src/models/PartnerItem.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { GoalItem } from "./GoalItem"; - -export interface PartnerItem { - id?: number; - relId: string; - name: string; - goals: GoalItem[]; -} diff --git a/src/models/db.ts b/src/models/db.ts index 2f38401b4..5742224ff 100644 --- a/src/models/db.ts +++ b/src/models/db.ts @@ -7,11 +7,10 @@ import { InboxItem } from "./InboxItem"; import { TaskItem } from "./TaskItem"; import { GCustomItem } from "./GCustomItem"; import { DumpboxItem } from "./DumpboxItem"; -import { PartnerItem } from "./PartnerItem"; -export const dexieVersion = 13; +export const dexieVersion = 14; -const currentVersion = localStorage.getItem("dexieVersion") || dexieVersion; +const currentVersion = Number(localStorage.getItem("dexieVersion") || dexieVersion); localStorage.setItem("dexieVersion", `${dexieVersion}`); export class ZinZenDB extends Dexie { @@ -31,8 +30,6 @@ export class ZinZenDB extends Dexie { dumpboxCollection!: Table; - partnersCollection!: Table; - constructor() { super("ZinZenDB"); this.version(dexieVersion) @@ -42,7 +39,7 @@ export class ZinZenDB extends Dexie { "id, title, duration, sublist, habit, on, start, due, afterTime, beforeTime, createdAt, parentGoalId, archived, goalColor, language, link, rootGoalId, timeBudget, typeOfGoal", sharedWMCollection: "id, title, duration, sublist, repeat, start, due, afterTime, beforeTime, createdAt, parentGoalId, archived, goalColor, language, link, rootGoalId, timeBudget, typeOfGoal", - contactsCollection: "id, name, collaborativeGoals, sharedGoals, relId, accepted, createdAt", + contactsCollection: "id, name, relId, accepted, createdAt", outboxCollection: null, inboxCollection: "id, goalChanges", pubSubCollection: "id, subscribers", @@ -51,14 +48,14 @@ export class ZinZenDB extends Dexie { "id, goalId, title, hoursSpent, completedTodayIds, lastCompleted, lastForget, blockedSlots, forgotToday, completedToday", customizationCollection: "++id, goalId, posIndex", dumpboxCollection: "id, key, value", - partnersCollection: "++id, relId, name, goals", + partnersCollection: null, }) .upgrade((trans) => { console.log("🚀 ~ file: db.ts:63 ~ ZinZenDB ~ .upgrade ~ this.verno:", currentVersion); if (currentVersion < 9) { console.log("processing updates for 9th version"); const goalsCollection = trans.table("goalsCollection"); - goalsCollection.toCollection().modify((goal: GoalItem) => { + goalsCollection.toCollection().modify((goal) => { if (goal.on === "weekends") { goal.on = ["Sat", "Sun"]; } else { @@ -88,7 +85,7 @@ export class ZinZenDB extends Dexie { sharedWMCollection.clear(); const goalsCollection = trans.table("goalsCollection"); - goalsCollection.toCollection().modify((goal: GoalItem) => { + goalsCollection.toCollection().modify((goal) => { delete goal.shared; delete goal.collaboration; goal.participants = []; @@ -105,6 +102,13 @@ export class ZinZenDB extends Dexie { goal.participants = goal.participants.map((ele) => ({ ...ele, following: false })); }); } + if (currentVersion < 14) { + const contactsCollection = trans.table("contactsCollection"); + contactsCollection.toCollection().modify((contact) => { + delete contact.collaborativeGoals; + delete contact.sharedGoals; + }); + } }); } } diff --git a/src/pages/GoalsPage/GoalsPage.tsx b/src/pages/GoalsPage/GoalsPage.tsx index 0481dbef7..95e54dc07 100644 --- a/src/pages/GoalsPage/GoalsPage.tsx +++ b/src/pages/GoalsPage/GoalsPage.tsx @@ -1,9 +1,7 @@ import { useRecoilValue } from "recoil"; import React, { useEffect, useState } from "react"; -import { PartnerItem } from "@src/models/PartnerItem"; import { getAllContacts } from "@src/api/ContactsAPI"; -import { getPartnerByRelId } from "@src/api/PartnerAPI"; import { displayPartnerMode } from "@src/store"; import { displayParticipants } from "@src/store/GoalsState"; @@ -20,34 +18,25 @@ const GoalsPage = () => { const showPartnerMode = useRecoilValue(displayPartnerMode); const showParticipants = useRecoilValue(displayParticipants); - const [activePartner, setActivePartner] = useState(""); - const [partner, setPartner] = useState(null); + const [activePartner, setActivePartner] = useState(null); const [partnersList, setPartnersList] = useState([]); - const getPartnerDetails = async () => { - let activeRelId; - if (partnersList.length > 0) { - activeRelId = partnersList[0].relId; - } else { + useEffect(() => { + const switchMode = async () => { const list = await getAllContacts(); - activeRelId = list[0].relId; + setActivePartner(list[0]); setPartnersList([...list]); - } - setActivePartner(activeRelId); - setPartner(await getPartnerByRelId(activeRelId)); - }; - - useEffect(() => { - getPartnerDetails(); - }, [showPartnerMode, activePartner]); + }; + switchMode(); + }, [showPartnerMode]); return ( <> {showParticipants && } - {showPartnerMode && partner ? ( + {showPartnerMode && activePartner ? ( <> - + ) : ( diff --git a/src/pages/GoalsPage/MyGoals.tsx b/src/pages/GoalsPage/MyGoals.tsx index 3fb4078df..3702bab81 100644 --- a/src/pages/GoalsPage/MyGoals.tsx +++ b/src/pages/GoalsPage/MyGoals.tsx @@ -18,9 +18,8 @@ import { import { GoalItem } from "@src/models/GoalItem"; import { GoalSublist } from "@components/GoalsComponents/GoalSublist/GoalSublist"; import { getActiveGoals } from "@api/GoalsAPI"; -import { getActiveSharedWMGoals } from "@src/api/SharedWMAPI"; import { createGoalObjectFromTags } from "@src/helpers/GoalProcessor"; -import { darkModeState, lastAction, openInbox, searchActive } from "@src/store"; +import { darkModeState, lastAction, searchActive } from "@src/store"; import AppLayout from "@src/layouts/AppLayout"; import GoalsList from "@components/GoalsComponents/GoalsList"; @@ -36,7 +35,6 @@ export const MyGoals = () => { const [archivedGoals, setArchivedGoals] = useState([]); const [showActions, setShowActions] = useState({ open: "root", click: 1 }); - const isInboxOpen = useRecoilValue(openInbox); const showAddGoal = useRecoilValue(displayAddGoal); const displaySearch = useRecoilValue(searchActive); const selectedGoalId = useRecoilValue(displayGoalId); @@ -54,11 +52,11 @@ export const MyGoals = () => { setArchivedGoals([...goals.filter((goal) => goal.archived === "true" && goal.typeOfGoal === "myGoal")]); }; const refreshActiveGoals = async () => { - const goals: GoalItem[] = isInboxOpen ? await getActiveSharedWMGoals() : await getActiveGoals("true"); + const goals: GoalItem[] = await getActiveGoals("true"); handleUserGoals(goals); }; const search = async (text: string) => { - const goals: GoalItem[] = isInboxOpen ? await getActiveSharedWMGoals() : await getActiveGoals("true"); + const goals: GoalItem[] = await getActiveGoals("true"); handleUserGoals(goals.filter((goal) => goal.title.toUpperCase().includes(text.toUpperCase()))); }; const debounceSearch = (event: ChangeEvent) => { @@ -78,15 +76,7 @@ export const MyGoals = () => { }, [action]); useEffect(() => { refreshActiveGoals(); - }, [ - showShareModal, - isInboxOpen, - showAddGoal, - showChangesModal, - showUpdateGoal, - showSuggestionModal, - showChangesModal, - ]); + }, [showShareModal, showAddGoal, showChangesModal, showUpdateGoal, showSuggestionModal, showChangesModal]); useEffect(() => { if (selectedGoalId === "root") { refreshActiveGoals(); diff --git a/src/pages/GoalsPage/PartnerGoals.tsx b/src/pages/GoalsPage/PartnerGoals.tsx index c4517fc2f..c3019206d 100644 --- a/src/pages/GoalsPage/PartnerGoals.tsx +++ b/src/pages/GoalsPage/PartnerGoals.tsx @@ -7,7 +7,6 @@ import ZinZenTextLight from "@assets/images/LogoTextLight.svg"; import ZinZenTextDark from "@assets/images/LogoTextDark.svg"; import { GoalItem } from "@src/models/GoalItem"; -import { PartnerItem } from "@src/models/PartnerItem"; import { GoalSublist } from "@components/GoalsComponents/GoalSublist/GoalSublist"; import { displayGoalActions, displayGoalId } from "@src/store/GoalsState"; import { darkModeState, lastAction, searchActive } from "@src/store"; @@ -17,11 +16,13 @@ import GoalLocStateHandler from "@src/helpers/GoalLocStateHandler"; import AppLayout from "@src/layouts/AppLayout"; import GoalsList from "@components/GoalsComponents/GoalsList"; import MyGoalActions from "@components/GoalsComponents/MyGoalActions/MyGoalActions"; +import ContactItem from "@src/models/ContactItem"; +import { getRootGoalsOfPartner } from "@src/api/SharedWMAPI"; -const PartnerGoals = ({ partner, refreshGoals }: { partner: PartnerItem; refreshGoals: () => Promise }) => { +const PartnerGoals = ({ partner }: { partner: ContactItem }) => { let debounceTimeout: ReturnType; - const { goals: partnerGoals, name } = partner; - const partnerName = name.charAt(0).toUpperCase() + name.slice(0, 4); + const { name, relId } = partner; + const partnerName = name.charAt(0).toUpperCase() + name.slice(1, 4); const [activeGoals, setActiveGoals] = useState([]); const [archivedGoals, setArchivedGoals] = useState([]); @@ -38,12 +39,17 @@ const PartnerGoals = ({ partner, refreshGoals }: { partner: PartnerItem; refresh setActiveGoals([...goals.filter((goal) => goal.archived === "false")]); setArchivedGoals([...goals.filter((goal) => goal.archived === "true" && goal.typeOfGoal === "myGoal")]); }; + const refreshActiveGoals = async () => { - handleUserGoals(partnerGoals); + const rootGoals = await getRootGoalsOfPartner(relId); + handleUserGoals(rootGoals); }; + const search = async (text: string) => { - handleUserGoals(partnerGoals.filter((goal) => goal.title.toUpperCase().includes(text.toUpperCase()))); + const rootGoals = await getRootGoalsOfPartner(relId); + handleUserGoals(rootGoals.filter((goal) => goal.title.toUpperCase().includes(text.toUpperCase()))); }; + const debounceSearch = (event: ChangeEvent) => { if (debounceTimeout) { clearTimeout(debounceTimeout); @@ -56,7 +62,7 @@ const PartnerGoals = ({ partner, refreshGoals }: { partner: PartnerItem; refresh useEffect(() => { if (action !== "none") { setLastAction("none"); - refreshGoals(); + refreshActiveGoals(); } }, [action]); @@ -64,11 +70,8 @@ const PartnerGoals = ({ partner, refreshGoals }: { partner: PartnerItem; refresh if (selectedGoalId === "root") { refreshActiveGoals(); } - }, [selectedGoalId, displaySearch]); + }, [selectedGoalId, partner, displaySearch]); - useEffect(() => { - handleUserGoals(partnerGoals); - }, [partnerGoals]); return ( diff --git a/src/pages/InvitePage/InvitePage.tsx b/src/pages/InvitePage/InvitePage.tsx index 595e152bd..10be5e864 100644 --- a/src/pages/InvitePage/InvitePage.tsx +++ b/src/pages/InvitePage/InvitePage.tsx @@ -6,7 +6,6 @@ import { darkModeState, displayToast } from "@src/store"; import { addContact } from "@src/api/ContactsAPI"; import { acceptRelationship } from "@src/services/contact.service"; import OnboardingLayout from "@src/layouts/OnboardingLayout"; -import { createPartner } from "@src/api/PartnerAPI"; const InvitePage = () => { const navigate = useNavigate(); @@ -25,7 +24,7 @@ const InvitePage = () => { const res = await acceptRelationship(); if (res.success && res.response?.relId) { const { relId } = res.response; - await Promise.all([addContact(newContactName, relId, true), createPartner(relId, newContactName)]); + await addContact(newContactName, relId, true); setNewContactName(""); } navigate("/"); diff --git a/src/store/index.ts b/src/store/index.ts index 62b9b851d..f4a3b2cbd 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -1,6 +1,5 @@ import { atom } from "recoil"; import { confirmActionState } from "@src/Interfaces/IPopupModals"; -import { PartnerItem } from "@src/models/PartnerItem"; import { darkModeState } from "./DarkModeState"; import { languageSelectionState } from "./LanguageSelectionState";