-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #284 from l3vels/feat/voice-on-message
Feat/voice on message
- Loading branch information
Showing
8 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
apps/ui/src/components/PlayAudioButton/PlayAudioButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { useEffect, useRef, useState } from 'react' | ||
|
||
import Button from '@l3-lib/ui-core/dist/Button' | ||
import Play from '@l3-lib/ui-core/dist/icons/PlayOutline' | ||
import Pause from '@l3-lib/ui-core/dist/icons/Pause' | ||
import styled from 'styled-components' | ||
import { t } from 'i18next' | ||
|
||
const PlayAudioButton = ({ audioUrl }: { audioUrl: string }) => { | ||
const audioRef = useRef(null as any) | ||
|
||
const playAudio = () => { | ||
if (audioRef.current) { | ||
audioRef.current.play() | ||
} | ||
} | ||
|
||
const pauseAudio = () => { | ||
if (audioRef.current) { | ||
audioRef.current.pause() | ||
} | ||
} | ||
|
||
const [isPlaying, setIsPlaying] = useState(false) | ||
|
||
useEffect(() => { | ||
if (audioRef.current) { | ||
audioRef.current.onplaying = () => { | ||
setIsPlaying(true) | ||
} | ||
audioRef.current.onpause = () => { | ||
setIsPlaying(false) | ||
} | ||
} | ||
}, []) | ||
|
||
return ( | ||
<StyledRoot> | ||
<> | ||
{isPlaying ? ( | ||
<Button onClick={pauseAudio} size={Button.sizes.XS} kind={Button.kinds.PRIMARY}> | ||
<StyledButtonTextWrapper> | ||
<span>{`${t('pause-voice')}`}</span> <Pause size={20} /> | ||
</StyledButtonTextWrapper> | ||
</Button> | ||
) : ( | ||
<Button onClick={playAudio} size={Button.sizes.XS} kind={Button.kinds.PRIMARY}> | ||
<StyledButtonTextWrapper> | ||
<span>{`${t('play-voice')}`}</span> <Play size={15} /> | ||
</StyledButtonTextWrapper> | ||
</Button> | ||
)} | ||
</> | ||
{/* eslint-disable-next-line jsx-a11y/media-has-caption */} | ||
<StyledAudio ref={audioRef} controls={false}> | ||
<source src={audioUrl} type='audio/mpeg' /> | ||
Your browser does not support the audio element. | ||
</StyledAudio> | ||
</StyledRoot> | ||
) | ||
} | ||
|
||
export default PlayAudioButton | ||
|
||
const StyledRoot = styled.div` | ||
min-height: 24px; | ||
max-height: 24px; | ||
overflow: hidden; | ||
` | ||
|
||
const StyledButtonTextWrapper = styled.div` | ||
min-width: 60px; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
` | ||
const StyledAudio = styled.audio` | ||
display: none; | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './PlayAudioButton' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters