From 19abc4b9faca8eb17363f7919df235a172c62afa Mon Sep 17 00:00:00 2001 From: talksik Date: Sat, 7 May 2022 12:22:47 -0500 Subject: [PATCH] some process in the web sockets ruining the linesmap --- packages/api/services/line.service.ts | 7 ++++- .../components/lines/lineRow.tsx/index.tsx | 5 +-- .../src/controller/lineDataProvider.tsx | 9 ++++-- .../src/pages/terminal/details/index.tsx | 6 +++- packages/desktop/src/pages/terminal/index.tsx | 31 ++++++++++--------- 5 files changed, 38 insertions(+), 20 deletions(-) diff --git a/packages/api/services/line.service.ts b/packages/api/services/line.service.ts index 7266a5b..1069733 100644 --- a/packages/api/services/line.service.ts +++ b/packages/api/services/line.service.ts @@ -120,7 +120,10 @@ export class LineService { userId: string, newState: LineMemberState ) { - const query = { lineId, userId: new ObjectId(userId) }; + const query = { + lineId: new ObjectId(lineId), + userId: new ObjectId(userId), + }; const updateSet = { $set: { state: newState, lastVisitDate: new Date() } }; const updateRes = await collections.lineMembers?.findOneAndUpdate( @@ -128,6 +131,8 @@ export class LineService { updateSet ); + console.log(updateRes); + return updateRes; } diff --git a/packages/desktop/src/components/lines/lineRow.tsx/index.tsx b/packages/desktop/src/components/lines/lineRow.tsx/index.tsx index 6c21519..85f6db5 100644 --- a/packages/desktop/src/components/lines/lineRow.tsx/index.tsx +++ b/packages/desktop/src/components/lines/lineRow.tsx/index.tsx @@ -7,6 +7,7 @@ import { FiSun } from "react-icons/fi"; import LineIcon from "../lineIcon"; import { LineMemberState } from "@nirvana/core/models/line.model"; import MasterLineData from "@nirvana/core/models/masterLineData.model"; +import moment from "moment"; import { useGetUserDetails } from "../../../controller/index"; // todo: send a much more comprehensive master line object? or just add properties to the @@ -78,13 +79,13 @@ export default function LineRow({ if (masterLineData.currentUserMember.lastVisitDate) return ( - {masterLineData.currentUserMember.lastVisitDate} + {moment(masterLineData.currentUserMember.lastVisitDate).fromNow()} ); return ( - {masterLineData.currentUserMember.lastVisitDate} + {moment(masterLineData.currentUserMember.lastVisitDate).fromNow()} ); }, [masterLineData]); diff --git a/packages/desktop/src/controller/lineDataProvider.tsx b/packages/desktop/src/controller/lineDataProvider.tsx index 92e573b..e26d63a 100644 --- a/packages/desktop/src/controller/lineDataProvider.tsx +++ b/packages/desktop/src/controller/lineDataProvider.tsx @@ -102,7 +102,7 @@ function useSocketHandler(linesData: MasterLineData[]) { // if user is me, make sure to show me my updated line member association if ( - newMap[res.lineId].currentUserMember?._id.toString() === + newMap[res.lineId].currentUserMember?.userId.toString() === res.userId ) { console.log( @@ -195,6 +195,7 @@ function useSocketHandler(linesData: MasterLineData[]) { useEffect(() => { if (linesData?.length > 0) { console.log("going to make initial connections and create lines map"); + console.log(linesData); setLinesMap((prevMappings) => { // go through the lines from the persistent store @@ -210,6 +211,8 @@ function useSocketHandler(linesData: MasterLineData[]) { const lineId = masterLine.lineDetails._id.toString(); newMap[lineId] = masterLine; + console.log(masterLine); + handleConnectToLine(lineId); // tune into lines that I should be @@ -341,6 +344,8 @@ export function LineDataProvider({ children }) { // ?just do simple synchronous axios/fetch in useEffect and manage isLoading ourselves? const { data: basicUserLinesData } = useUserLines(); + console.log(basicUserLinesData?.data?.masterLines); + const { linesMap, ...handlers } = useSocketHandler( basicUserLinesData?.data?.masterLines ); @@ -350,7 +355,7 @@ export function LineDataProvider({ children }) { } const value: ILineDataContext & ReturnType = { - linesMap, // TODO send the updated map instead of this array + linesMap: {}, // TODO send the updated map instead of this array relevantUsers: [], $ws, ...handlers, diff --git a/packages/desktop/src/pages/terminal/details/index.tsx b/packages/desktop/src/pages/terminal/details/index.tsx index 9d5cfeb..b165b42 100644 --- a/packages/desktop/src/pages/terminal/details/index.tsx +++ b/packages/desktop/src/pages/terminal/details/index.tsx @@ -21,7 +21,7 @@ export default function LineDetailsTerminal({ const isUserToggleTuned = useMemo( () => selectedLine?.currentUserMember?.state === LineMemberState.TUNED, - [selectedLine] + [selectedLine.currentUserMember] ); // seeing if I am in the list of broadcasters @@ -34,6 +34,10 @@ export default function LineDetailsTerminal({ [userDetails, selectedLine] ); + useEffect(() => { + console.log(selectedLine?.currentUserMember); + }, [selectedLine]); + return ( <>
diff --git a/packages/desktop/src/pages/terminal/index.tsx b/packages/desktop/src/pages/terminal/index.tsx index dc736f4..20df6e0 100644 --- a/packages/desktop/src/pages/terminal/index.tsx +++ b/packages/desktop/src/pages/terminal/index.tsx @@ -110,8 +110,12 @@ export default function NirvanaTerminal() { // find the line from the data provider if (linesMap[selectedLineId]) { + console.log("looking for selected Line in map for details section"); + const foundSelectedLine = linesMap[selectedLineId]; + console.log(foundSelectedLine); + // on mount of this, we want to temporarily tune into the line if we are not already tuned in...which would happen if we toggle tuned in if ( !foundSelectedLine.tunedInMemberIds?.includes( @@ -181,25 +185,24 @@ export default function NirvanaTerminal() {
+ {!(allLines.length > 0 && !(toggleTunedLines.length > 0)) && ( + + You have no lines!
Create one to connect to your team + instantly. +
+ )} + {/* rest of the lines */}
{isLoadingInitialLines ? ( ) : ( - <> - {!allLines.length && ( - - You have no lines!
Create one to connect to your team - instantly. -
- )} - {allLines.map((masterLineData) => ( - - ))} - + allLines.map((masterLineData) => ( + + )) )}