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
@@ -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,