From 7b1fede1955323a738005953dec0fcf9296a0f5f Mon Sep 17 00:00:00 2001 From: talksik Date: Tue, 18 Jan 2022 04:01:35 -0800 Subject: [PATCH] getting it to play and stuff --- components/Dashboard/TeamVoiceLine.tsx | 28 +++++- components/Modals/PowerPlayer.tsx | 133 +++++++++++++++---------- contexts/keyboardContext.tsx | 3 +- 3 files changed, 108 insertions(+), 56 deletions(-) diff --git a/components/Dashboard/TeamVoiceLine.tsx b/components/Dashboard/TeamVoiceLine.tsx index e693044..a2ba97e 100644 --- a/components/Dashboard/TeamVoiceLine.tsx +++ b/components/Dashboard/TeamVoiceLine.tsx @@ -7,9 +7,13 @@ import { toast } from "react-hot-toast"; import { TeamMemberRole, TeamMemberStatus } from "../../models/teamMember"; import { getFirestore } from "firebase/firestore"; import { Tooltip } from "antd"; -import { useKeyboardContext } from "../../contexts/keyboardContext"; +import { + ShowModalType, + useKeyboardContext, +} from "../../contexts/keyboardContext"; import UserStatusBubble, { UserPulse } from "../UserStatusBubble"; import { useAuth } from "../../contexts/authContext"; +import PowerPlayer from "../Modals/PowerPlayer"; const maxNumberOfKeyboardMappings: number = 9; @@ -20,6 +24,7 @@ export default function TeamVoiceLine() { selectTeamMember, selectedTeammate, isRecording, + handleModalType, } = useKeyboardContext(); const router = useRouter(); const { teamid } = router.query; @@ -189,6 +194,19 @@ export default function TeamVoiceLine() { }); } + const [showPowerPlayer, setShowPowerPlayer] = useState(false); + + function handleCloseModal() { + handleModalType(ShowModalType.na); + setShowPowerPlayer(false); + } + + function handleShowModal() { + handleModalType(ShowModalType.powerPlayer); // disables controls + + setShowPowerPlayer(true); + } + return (
@@ -197,7 +215,10 @@ export default function TeamVoiceLine() { - @@ -211,6 +232,9 @@ export default function TeamVoiceLine() { + + + {/* list of team members */} {renderTeamMemberList()}
diff --git a/components/Modals/PowerPlayer.tsx b/components/Modals/PowerPlayer.tsx index d0a498f..0781008 100644 --- a/components/Modals/PowerPlayer.tsx +++ b/components/Modals/PowerPlayer.tsx @@ -1,71 +1,98 @@ import { Modal, Tooltip } from "antd"; import { Message } from "../../models/message"; import { FaBackward } from "react-icons/fa"; +import { useTeamDashboardContext } from "../../contexts/teamDashboardContext"; +import { useAuth } from "../../contexts/authContext"; +import { useKeyboardContext } from "../../contexts/keyboardContext"; -export default function PowerPlayer(props: { show: boolean }) { +export default function PowerPlayer(props: { + show: boolean; + handleCloseModal: Function; +}) { + const { currUser } = useAuth(); + const { allMessages, teamUsersMap } = useTeamDashboardContext(); + const { handleAddAudioToQueue } = useKeyboardContext(); // two arrays: // 1. all of my messages in order date desc => top - // 2. all of incoming messages in order date desc => bottom + // const sentMessages = allMessages.filter(msg => msg.senderUserId == currUser.uid) + + // // 2. all of incoming messages in order date desc => bottom + // const receivedMessages = allMessages.filter(msg => msg.receiverUserId == currUser.uid) + + const messageRangeHalfToPlay = 2; + function handlePlayAudio(url: string) { + // todo play like 2 indexes lower to 2 indexes higher instead of + const indexOfMessage = 5; + + var startPlay = indexOfMessage - messageRangeHalfToPlay; + if (startPlay < 0) { + startPlay = 0; + } + + var endPlay = indexOfMessage + messageRangeHalfToPlay; + if (endPlay > allMessages.length) { + endPlay = allMessages.length; + } + + // loop through start to end and add to queue + + console.log(url); + + handleAddAudioToQueue([url]); + } return ( - -
+ + + One timeline to listen to the past 24 hours. + + + The bottom are your messages. The top are incoming messages. Click on + the bubbles to listen to conversations during that period. + + + +
{/* top incoming messages */}
- - - asdf - - + {allMessages.map((msg, i) => { + if (msg.senderUserId == currUser.uid) { + return ( + handlePlayAudio(msg.audioDataUrl)} + className="border-r-2 border-r-sky-400 translate-y-10 min-w-max hover:cursor-pointer" + > + +
+
+
+ ); + } - - - asdf - - + const sender = teamUsersMap[msg.senderUserId]; - - - asdf - - + // incoming messages + return ( + handlePlayAudio(msg.audioDataUrl)} + className="border-r-2 border-r-orange-400 min-w-max hover:cursor-pointer" + > + + K + + + ); + })}
{/* middle line */} -
- - {/* bottom outgoing messages */} -
- - -
-
-
- - - -
-
-
- - - -
-
-
-
+
); diff --git a/contexts/keyboardContext.tsx b/contexts/keyboardContext.tsx index 67a14db..560775f 100644 --- a/contexts/keyboardContext.tsx +++ b/contexts/keyboardContext.tsx @@ -55,6 +55,7 @@ interface KeyboardContextInterface { export enum ShowModalType { createLink = "link", createRoom = "room", + powerPlayer = "powerPlayer", na = "none", } @@ -361,7 +362,7 @@ export default function KeyboardContextProvider({ children }) { } // handle for when in modals, don't want any of this crap - if (showModalType == ShowModalType.createRoom) { + if (showModalType != ShowModalType.na) { return; }