diff --git a/vocodes/src/App.scss b/vocodes/src/App.scss index b1438f1c85..f26635d4ea 100644 --- a/vocodes/src/App.scss +++ b/vocodes/src/App.scss @@ -230,6 +230,11 @@ nav { text-align: center; } +.player-buttons { + text-align: center; + margin: auto; +} + /** RESPONSIVENESS **/ diff --git a/vocodes/src/v2/view/_icons/ArrowRightIcon.tsx b/vocodes/src/v2/view/_icons/ArrowRightIcon.tsx new file mode 100644 index 0000000000..0555b3deb8 --- /dev/null +++ b/vocodes/src/v2/view/_icons/ArrowRightIcon.tsx @@ -0,0 +1,10 @@ +import React from 'react'; +import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; +import { faArrowRight } from '@fortawesome/free-solid-svg-icons' + +export function ArrowRightIcon() { + return ( + + ); +} + diff --git a/vocodes/src/v2/view/_icons/PauseIcon.tsx b/vocodes/src/v2/view/_icons/PauseIcon.tsx new file mode 100644 index 0000000000..a84c2d0780 --- /dev/null +++ b/vocodes/src/v2/view/_icons/PauseIcon.tsx @@ -0,0 +1,10 @@ +import React from 'react'; +import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; +import { faPause } from '@fortawesome/free-solid-svg-icons' + +export function PauseIcon() { + return ( + + ); +} + diff --git a/vocodes/src/v2/view/_icons/PlayIcon.tsx b/vocodes/src/v2/view/_icons/PlayIcon.tsx new file mode 100644 index 0000000000..658dc42a9e --- /dev/null +++ b/vocodes/src/v2/view/_icons/PlayIcon.tsx @@ -0,0 +1,10 @@ +import React from 'react'; +import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; +import { faPlay } from '@fortawesome/free-solid-svg-icons' + +export function PlayIcon() { + return ( + + ); +} + diff --git a/vocodes/src/v2/view/_icons/RepeatIcon.tsx b/vocodes/src/v2/view/_icons/RepeatIcon.tsx new file mode 100644 index 0000000000..9d91c016c5 --- /dev/null +++ b/vocodes/src/v2/view/_icons/RepeatIcon.tsx @@ -0,0 +1,10 @@ +import React from 'react'; +import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; +import { faRetweet } from '@fortawesome/free-solid-svg-icons' + +export function RepeatIcon() { + return ( + + ); +} + diff --git a/vocodes/src/v2/view/tts/tts_result_view/TtsResultAudioPlayerFc.tsx b/vocodes/src/v2/view/tts/tts_result_view/TtsResultAudioPlayerFc.tsx index 328cbc215f..7064193155 100644 --- a/vocodes/src/v2/view/tts/tts_result_view/TtsResultAudioPlayerFc.tsx +++ b/vocodes/src/v2/view/tts/tts_result_view/TtsResultAudioPlayerFc.tsx @@ -1,8 +1,12 @@ -import React from 'react'; +import React, { useCallback } from 'react'; import WaveSurfer from 'wavesurfer.js'; import { useEffect, useState } from 'react'; import { BucketConfig } from '../../../../common/BucketConfig'; import { TtsResult } from '../../../api/tts/GetTtsResult'; +import { PlayIcon } from '../../_icons/PlayIcon'; +import { PauseIcon } from '../../_icons/PauseIcon'; +import { RepeatIcon } from '../../_icons/RepeatIcon'; +import { ArrowRightIcon } from '../../_icons/ArrowRightIcon'; interface Props { ttsResult: TtsResult, @@ -10,12 +14,26 @@ interface Props { function TtsResultAudioPlayerFc(props: Props) { let [isPlaying, setIsPlaying] = useState(false); + let [isRepeating, setIsRepeating] = useState(false); let [waveSurfer, setWaveSurfer] = useState(null); useEffect(() => { - setWaveSurfer(WaveSurfer.create({ - container: '#waveform' - })) + const wavesurferInstance = WaveSurfer.create({ + container: '#waveform', // Previousy I used 'this.ref.current' and React.createRef() + height: 200, + responsive: true, + waveColor: '#777', + progressColor: '#ccc', + cursorColor: '#3273dc', + cursorWidth: 2, + normalize: false, + }); + + wavesurferInstance.on('pause', () => { + setIsPlaying(false); + }) + + setWaveSurfer(wavesurferInstance); }, []) useEffect(() => { @@ -27,15 +45,48 @@ function TtsResultAudioPlayerFc(props: Props) { const togglePlayPause = () => { if (waveSurfer) { - waveSurfer.playPause() + waveSurfer.playPause(); setIsPlaying(!isPlaying) } } + const toggleIsRepeating = () => { + setIsRepeating(!isRepeating) + } + + const repeatCallback = useCallback((isRepeating) => { + if (isRepeating) { + waveSurfer!.play(); + } + }, [waveSurfer]); + + + if (waveSurfer) { + waveSurfer.on('finish', () => repeatCallback(isRepeating)); + } + + let playButtonText = <>; + if (isPlaying) { + playButtonText = <>; + } + + let repeatButtonText = isRepeating ? : ; + return (
-
- +
+
+
+
+ + + +
+
) } diff --git a/vocodes/src/v2/view/tts/tts_result_view/TtsResultViewFc.tsx b/vocodes/src/v2/view/tts/tts_result_view/TtsResultViewFc.tsx index f2851161e5..3ed71b1cdc 100644 --- a/vocodes/src/v2/view/tts/tts_result_view/TtsResultViewFc.tsx +++ b/vocodes/src/v2/view/tts/tts_result_view/TtsResultViewFc.tsx @@ -176,17 +176,15 @@ function TtsResultViewFc(props: Props) { {subtitle} - -
+ {/* Without wavesurfer, + */} -