some process in the web sockets ruining the linesmap
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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 (
|
||||
<span className={`text-gray-400 ml-auto text-xs font-semibold`}>
|
||||
{masterLineData.currentUserMember.lastVisitDate}
|
||||
{moment(masterLineData.currentUserMember.lastVisitDate).fromNow()}
|
||||
</span>
|
||||
);
|
||||
|
||||
return (
|
||||
<span className={`text-gray-300 ml-auto text-xs `}>
|
||||
{masterLineData.currentUserMember.lastVisitDate}
|
||||
{moment(masterLineData.currentUserMember.lastVisitDate).fromNow()}
|
||||
</span>
|
||||
);
|
||||
}, [masterLineData]);
|
||||
|
||||
@@ -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<typeof useSocketHandler> = {
|
||||
linesMap, // TODO send the updated map instead of this array
|
||||
linesMap: {}, // TODO send the updated map instead of this array
|
||||
relevantUsers: [],
|
||||
$ws,
|
||||
...handlers,
|
||||
|
||||
@@ -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 (
|
||||
<>
|
||||
<div className="flex flex-col flex-1 bg-gray-100 items-stretch justify-start relative border-l border-l-gray-100">
|
||||
|
||||
@@ -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() {
|
||||
</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 */}
|
||||
<div className={"flex flex-col"}>
|
||||
{isLoadingInitialLines ? (
|
||||
<Skeleton />
|
||||
) : (
|
||||
<>
|
||||
{!allLines.length && (
|
||||
<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>
|
||||
)}
|
||||
{allLines.map((masterLineData) => (
|
||||
<LineRow
|
||||
key={`terminalListLines-${masterLineData.lineDetails._id.toString()}`}
|
||||
masterLineData={masterLineData}
|
||||
/>
|
||||
))}
|
||||
</>
|
||||
allLines.map((masterLineData) => (
|
||||
<LineRow
|
||||
key={`terminalListLines-${masterLineData.lineDetails._id.toString()}`}
|
||||
masterLineData={masterLineData}
|
||||
/>
|
||||
))
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user