handling toggle tuning in and just tuning in
This commit is contained in:
@@ -144,7 +144,8 @@ export default function InitializeWs(io: any) {
|
||||
new SomeoneTunedResponse(
|
||||
req.lineId,
|
||||
userInfo.userId,
|
||||
clientUserIdsInRoom
|
||||
clientUserIdsInRoom,
|
||||
req.keepTunedIn
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -74,7 +74,8 @@ export class SomeoneTunedResponse {
|
||||
constructor(
|
||||
public lineId: string,
|
||||
public userId: string,
|
||||
public allTunedIntoUserIds: string[]
|
||||
public allTunedIntoUserIds: string[],
|
||||
public toggledIn: boolean = false // tell client if this new user toggled in or just temporary so that they can update the right LineMember assoc
|
||||
) {}
|
||||
}
|
||||
export class UntuneFromLineRequest {
|
||||
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
import React, { useContext, useState } from "react";
|
||||
import { Socket, io } from "socket.io-client";
|
||||
import { useCallback, useEffect } from "react";
|
||||
import { useGetUserDetails, useUserLines } from "./index";
|
||||
|
||||
import { LineMemberState } from "@nirvana/core/models/line.model";
|
||||
import MasterLineData from "@nirvana/core/models/masterLineData.model";
|
||||
@@ -22,7 +23,6 @@ import { User } from "@nirvana/core/models";
|
||||
import { queryClient } from "../pages/nirvanaApp";
|
||||
import toast from "react-hot-toast";
|
||||
import { useRecoilValue } from "recoil";
|
||||
import { useUserLines } from "./index";
|
||||
|
||||
let $ws: Socket;
|
||||
|
||||
@@ -30,6 +30,7 @@ function useSocketHandler(linesData: MasterLineData[]) {
|
||||
const jwtToken = useRecoilValue($jwtToken);
|
||||
|
||||
const [linesMap, setLinesMap] = useState<LineIdToMasterLine>({});
|
||||
const { data: userDetails } = useGetUserDetails();
|
||||
|
||||
/**
|
||||
* handle ws connection
|
||||
@@ -97,11 +98,27 @@ function useSocketHandler(linesData: MasterLineData[]) {
|
||||
setLinesMap((prevLinesMap) => {
|
||||
const newMap = { ...prevLinesMap };
|
||||
|
||||
// TODO: update the relevant lineMember (based on which userId is given): state and last visit date if current user is joining
|
||||
|
||||
if (newMap[res.lineId])
|
||||
if (newMap[res.lineId]) {
|
||||
newMap[res.lineId].tunedInMemberIds = res.allTunedIntoUserIds;
|
||||
|
||||
// if user is me, make sure to show me my updated line member association
|
||||
if (userDetails.user._id.toString() === res.userId) {
|
||||
console.log(
|
||||
"updated my line member state for this line | is toggle tuned in: ",
|
||||
res.toggledIn
|
||||
);
|
||||
|
||||
newMap[res.lineId].currentUserMember.lastVisitDate = new Date();
|
||||
newMap[res.lineId].currentUserMember.state = res.toggledIn
|
||||
? LineMemberState.TUNED
|
||||
: LineMemberState.INBOX;
|
||||
}
|
||||
|
||||
// TODO: update the relevant lineMember (based on which userId is given): state and last visit date if current user is joining
|
||||
// and not just if it's the current user toggling in
|
||||
// right now, we just want user to know number of folks tuned and no need to expose who is toggle tuned...that lineMember can be stale
|
||||
}
|
||||
|
||||
return newMap;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import { FiActivity, FiSettings, FiSun } from "react-icons/fi";
|
||||
import { GlobalHotKeys, KeyMap } from "react-hotkeys";
|
||||
import { useCallback, useMemo } from "react";
|
||||
import { useCallback, useEffect, useMemo } from "react";
|
||||
|
||||
import { $selectedLineId } from "../../../controller/recoil";
|
||||
import LineIcon from "../../../components/lines/lineIcon/index";
|
||||
import { LineMemberState } from "@nirvana/core/models/line.model";
|
||||
import MasterLineData from "@nirvana/core/models/masterLineData.model";
|
||||
import { Tooltip } from "antd";
|
||||
import { useGetUserDetails } from "../../../controller";
|
||||
import { useGetUserDetails } from "../../../controller/index";
|
||||
import { useLineDataProvider } from "../../../controller/lineDataProvider";
|
||||
import { useRecoilState } from "recoil";
|
||||
|
||||
@@ -17,8 +17,17 @@ export default function LineDetailsTerminal({
|
||||
selectedLine: MasterLineData;
|
||||
}) {
|
||||
const { handleTuneToLine } = useLineDataProvider();
|
||||
|
||||
const { data: userDetails } = useGetUserDetails();
|
||||
|
||||
// on mount of this, we want to temporarily tune into the line if we are not already
|
||||
useEffect(() => {
|
||||
if (
|
||||
!selectedLine.tunedInMemberIds?.includes(userDetails?.user._id.toString())
|
||||
) {
|
||||
handleTuneToLine(selectedLine.lineDetails._id.toString(), false);
|
||||
}
|
||||
}, []);
|
||||
|
||||
const isUserToggleTuned = useMemo(
|
||||
() => selectedLine?.currentUserMember?.state === LineMemberState.TUNED,
|
||||
[selectedLine]
|
||||
|
||||
Reference in New Issue
Block a user