managing better adding to quueue

This commit is contained in:
talksik
2022-01-18 03:17:52 -08:00
parent cf064f5545
commit 80b16dfdc6
2 changed files with 11 additions and 7 deletions
+1 -1
View File
@@ -2,7 +2,7 @@ import { Modal, Tooltip } from "antd";
import { Message } from "../../models/message"; import { Message } from "../../models/message";
import { FaBackward } from "react-icons/fa"; import { FaBackward } from "react-icons/fa";
export default function PowerPlayer(props: { messages: Message[] }) { export default function PowerPlayer(props: { show: boolean }) {
// two arrays: // two arrays:
// 1. all of my messages in order date desc => top // 1. all of my messages in order date desc => top
// 2. all of incoming messages in order date desc => bottom // 2. all of incoming messages in order date desc => bottom
+10 -6
View File
@@ -7,7 +7,6 @@ import { v4 as uuidv4 } from "uuid";
import AudioPlayer from "react-h5-audio-player"; import AudioPlayer from "react-h5-audio-player";
import "react-h5-audio-player/lib/styles.css"; import "react-h5-audio-player/lib/styles.css";
import CloudStorageService from "../services/cloudStorageService"; import CloudStorageService from "../services/cloudStorageService";
import PowerPlayer from "../components/Modals/PowerPlayer";
import { Message } from "../models/message"; import { Message } from "../models/message";
import { useAuth } from "./authContext"; import { useAuth } from "./authContext";
import { SendService } from "../services/sendService"; import { SendService } from "../services/sendService";
@@ -49,6 +48,8 @@ interface KeyboardContextInterface {
showModalType: ShowModalType; showModalType: ShowModalType;
handleModalType: Function; handleModalType: Function;
pastedLink: string; pastedLink: string;
handleAddAudioToQueue: Function;
} }
export enum ShowModalType { export enum ShowModalType {
@@ -130,7 +131,7 @@ export default function KeyboardContextProvider({ children }) {
// start player on the bottom // start player on the bottom
// autoplay message // autoplay message
// add to the queue // add to the queue
setAudioQueue((prevQueue) => [...prevQueue, allMessages[0].audioDataUrl]); handleAddAudioToQueue([allMessages[0].audioDataUrl]);
} }
}, [allMessages]); }, [allMessages]);
@@ -171,6 +172,8 @@ export default function KeyboardContextProvider({ children }) {
pastedLink, pastedLink,
handleModalType, handleModalType,
showModalType, showModalType,
handleAddAudioToQueue,
}; };
function muteOrUnmute() { function muteOrUnmute() {
@@ -430,7 +433,7 @@ export default function KeyboardContextProvider({ children }) {
convoChunk.reverse(); convoChunk.reverse();
// add convo chunk to the queue player // add convo chunk to the queue player
setAudioQueue((prevQueue) => [...prevQueue, ...convoChunk]); handleAddAudioToQueue(convoChunk);
} else { } else {
toast("nothing to play"); toast("nothing to play");
} }
@@ -520,13 +523,14 @@ export default function KeyboardContextProvider({ children }) {
const [playerSrc, setPlayerSrc] = useState<string>(null); const [playerSrc, setPlayerSrc] = useState<string>(null);
function handleAddAudioToQueue(urls: string[]) {
setAudioQueue((prevQueue) => [...prevQueue, ...urls]);
}
return ( return (
<KeyboardContext.Provider value={value}> <KeyboardContext.Provider value={value}>
{children} {children}
{/* mega power mode viewer */}
{/* <PowerPlayer /> */}
{/* player for audio messages */} {/* player for audio messages */}
{playerSrc && ( {playerSrc && (
<AudioPlayer <AudioPlayer