some process in the web sockets ruining the linesmap

This commit is contained in:
talksik
2022-05-07 12:22:47 -05:00
parent 2c8ca0a62b
commit 19abc4b9fa
5 changed files with 38 additions and 20 deletions
+6 -1
View File
@@ -120,7 +120,10 @@ export class LineService {
userId: string, userId: string,
newState: LineMemberState 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 updateSet = { $set: { state: newState, lastVisitDate: new Date() } };
const updateRes = await collections.lineMembers?.findOneAndUpdate( const updateRes = await collections.lineMembers?.findOneAndUpdate(
@@ -128,6 +131,8 @@ export class LineService {
updateSet updateSet
); );
console.log(updateRes);
return updateRes; return updateRes;
} }
@@ -7,6 +7,7 @@ import { FiSun } from "react-icons/fi";
import LineIcon from "../lineIcon"; import LineIcon from "../lineIcon";
import { LineMemberState } from "@nirvana/core/models/line.model"; import { LineMemberState } from "@nirvana/core/models/line.model";
import MasterLineData from "@nirvana/core/models/masterLineData.model"; import MasterLineData from "@nirvana/core/models/masterLineData.model";
import moment from "moment";
import { useGetUserDetails } from "../../../controller/index"; import { useGetUserDetails } from "../../../controller/index";
// todo: send a much more comprehensive master line object? or just add properties to the // 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) if (masterLineData.currentUserMember.lastVisitDate)
return ( return (
<span className={`text-gray-400 ml-auto text-xs font-semibold`}> <span className={`text-gray-400 ml-auto text-xs font-semibold`}>
{masterLineData.currentUserMember.lastVisitDate} {moment(masterLineData.currentUserMember.lastVisitDate).fromNow()}
</span> </span>
); );
return ( return (
<span className={`text-gray-300 ml-auto text-xs `}> <span className={`text-gray-300 ml-auto text-xs `}>
{masterLineData.currentUserMember.lastVisitDate} {moment(masterLineData.currentUserMember.lastVisitDate).fromNow()}
</span> </span>
); );
}, [masterLineData]); }, [masterLineData]);
@@ -102,7 +102,7 @@ function useSocketHandler(linesData: MasterLineData[]) {
// if user is me, make sure to show me my updated line member association // if user is me, make sure to show me my updated line member association
if ( if (
newMap[res.lineId].currentUserMember?._id.toString() === newMap[res.lineId].currentUserMember?.userId.toString() ===
res.userId res.userId
) { ) {
console.log( console.log(
@@ -195,6 +195,7 @@ function useSocketHandler(linesData: MasterLineData[]) {
useEffect(() => { useEffect(() => {
if (linesData?.length > 0) { if (linesData?.length > 0) {
console.log("going to make initial connections and create lines map"); console.log("going to make initial connections and create lines map");
console.log(linesData);
setLinesMap((prevMappings) => { setLinesMap((prevMappings) => {
// go through the lines from the persistent store // go through the lines from the persistent store
@@ -210,6 +211,8 @@ function useSocketHandler(linesData: MasterLineData[]) {
const lineId = masterLine.lineDetails._id.toString(); const lineId = masterLine.lineDetails._id.toString();
newMap[lineId] = masterLine; newMap[lineId] = masterLine;
console.log(masterLine);
handleConnectToLine(lineId); handleConnectToLine(lineId);
// tune into lines that I should be // 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? // ?just do simple synchronous axios/fetch in useEffect and manage isLoading ourselves?
const { data: basicUserLinesData } = useUserLines(); const { data: basicUserLinesData } = useUserLines();
console.log(basicUserLinesData?.data?.masterLines);
const { linesMap, ...handlers } = useSocketHandler( const { linesMap, ...handlers } = useSocketHandler(
basicUserLinesData?.data?.masterLines basicUserLinesData?.data?.masterLines
); );
@@ -350,7 +355,7 @@ export function LineDataProvider({ children }) {
} }
const value: ILineDataContext & ReturnType<typeof useSocketHandler> = { const value: ILineDataContext & ReturnType<typeof useSocketHandler> = {
linesMap, // TODO send the updated map instead of this array linesMap: {}, // TODO send the updated map instead of this array
relevantUsers: [], relevantUsers: [],
$ws, $ws,
...handlers, ...handlers,
@@ -21,7 +21,7 @@ export default function LineDetailsTerminal({
const isUserToggleTuned = useMemo( const isUserToggleTuned = useMemo(
() => selectedLine?.currentUserMember?.state === LineMemberState.TUNED, () => selectedLine?.currentUserMember?.state === LineMemberState.TUNED,
[selectedLine] [selectedLine.currentUserMember]
); );
// seeing if I am in the list of broadcasters // seeing if I am in the list of broadcasters
@@ -34,6 +34,10 @@ export default function LineDetailsTerminal({
[userDetails, selectedLine] [userDetails, selectedLine]
); );
useEffect(() => {
console.log(selectedLine?.currentUserMember);
}, [selectedLine]);
return ( return (
<> <>
<div className="flex flex-col flex-1 bg-gray-100 items-stretch justify-start relative border-l border-l-gray-100"> <div className="flex flex-col flex-1 bg-gray-100 items-stretch justify-start relative border-l border-l-gray-100">
+17 -14
View File
@@ -110,8 +110,12 @@ export default function NirvanaTerminal() {
// find the line from the data provider // find the line from the data provider
if (linesMap[selectedLineId]) { if (linesMap[selectedLineId]) {
console.log("looking for selected Line in map for details section");
const foundSelectedLine = linesMap[selectedLineId]; 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 // 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 ( if (
!foundSelectedLine.tunedInMemberIds?.includes( !foundSelectedLine.tunedInMemberIds?.includes(
@@ -181,25 +185,24 @@ export default function NirvanaTerminal() {
</div> </div>
</div> </div>
{!(allLines.length > 0 && !(toggleTunedLines.length > 0)) && (
<span className="text-gray-300 text-sm my-5 text-center">
You have no lines! <br /> Create one to connect to your team
instantly.
</span>
)}
{/* rest of the lines */} {/* rest of the lines */}
<div className={"flex flex-col"}> <div className={"flex flex-col"}>
{isLoadingInitialLines ? ( {isLoadingInitialLines ? (
<Skeleton /> <Skeleton />
) : ( ) : (
<> allLines.map((masterLineData) => (
{!allLines.length && ( <LineRow
<span className="text-gray-300 text-sm my-5 text-center"> key={`terminalListLines-${masterLineData.lineDetails._id.toString()}`}
You have no lines! <br /> Create one to connect to your team masterLineData={masterLineData}
instantly. />
</span> ))
)}
{allLines.map((masterLineData) => (
<LineRow
key={`terminalListLines-${masterLineData.lineDetails._id.toString()}`}
masterLineData={masterLineData}
/>
))}
</>
)} )}
</div> </div>
</div> </div>