selection auto

This commit is contained in:
Arjun Patel
2022-01-16 13:44:02 -08:00
parent ff454d10f0
commit f6fd7b4540
+8 -7
View File
@@ -82,8 +82,6 @@ export default function AudioContextProvider({ children }) {
// playing incoming messages // playing incoming messages
const { allMessages, messagesByTeamMate } = useTeamDashboardContext(); const { allMessages, messagesByTeamMate } = useTeamDashboardContext();
console.log(allMessages);
console.log(messagesByTeamMate);
useEffect(() => { useEffect(() => {
if (!allMessages.length) { if (!allMessages.length) {
@@ -96,12 +94,12 @@ export default function AudioContextProvider({ children }) {
console.log("playing message"); console.log("playing message");
console.log(allMessages[0]); console.log(allMessages[0]);
// play message
setPlayerSrc(allMessages[0].audioDataUrl);
// select the user // select the user
setSelectedTeamMember(allMessages[0].senderUserId);
// start player on the bottom // start player on the bottom
// autoplay message
setPlayerSrc(allMessages[0].audioDataUrl);
} }
}, [allMessages]); }, [allMessages]);
@@ -255,11 +253,12 @@ export default function AudioContextProvider({ children }) {
function onEndedPlaying(e) { function onEndedPlaying(e) {
toast.success("finished playing"); toast.success("finished playing");
setPlayerSrc(""); setPlayerSrc(null);
// if there are still items in the player queue, then change the src and play the subsequent messages // if there are still items in the player queue, then change the src and play the subsequent messages
// if no more messages, deselect user and hide the player // if no more messages, deselect user and hide the player
setSelectedTeamMember(null);
} }
// todo usecallback hook // todo usecallback hook
@@ -383,7 +382,7 @@ export default function AudioContextProvider({ children }) {
setSelectedTeamMember(userId); setSelectedTeamMember(userId);
} }
const [playerSrc, setPlayerSrc] = useState<string>(""); const [playerSrc, setPlayerSrc] = useState<string>(null);
return ( return (
<AudioContext.Provider value={value}> <AudioContext.Provider value={value}>
@@ -393,6 +392,7 @@ export default function AudioContextProvider({ children }) {
{/* <PowerPlayer /> */} {/* <PowerPlayer /> */}
{/* player for audio messages */} {/* player for audio messages */}
{playerSrc && (
<AudioPlayer <AudioPlayer
autoPlay autoPlay
src={playerSrc} src={playerSrc}
@@ -401,6 +401,7 @@ export default function AudioContextProvider({ children }) {
onEnded={onEndedPlaying} onEnded={onEndedPlaying}
className="w-screen flex flex-row" className="w-screen flex flex-row"
/> />
)}
</AudioContext.Provider> </AudioContext.Provider>
); );
} }