2022-02-02 08:41:30 +00:00
|
|
|
import type { OdFileObject } from '../../types'
|
2022-01-06 08:34:16 +00:00
|
|
|
import { FC, useState } from 'react'
|
2022-01-16 12:19:52 +00:00
|
|
|
|
2021-06-24 13:54:59 +00:00
|
|
|
import ReactPlayer from 'react-player'
|
2021-06-24 21:32:22 +00:00
|
|
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
|
2021-06-24 13:54:59 +00:00
|
|
|
|
2021-12-29 07:23:47 +00:00
|
|
|
import DownloadButtonGroup from '../DownloadBtnGtoup'
|
2022-01-06 08:34:16 +00:00
|
|
|
import { DownloadBtnContainer, PreviewContainer } from './Containers'
|
2021-06-25 14:15:00 +00:00
|
|
|
|
2021-06-25 12:44:14 +00:00
|
|
|
enum PlayerState {
|
|
|
|
Loading,
|
|
|
|
Ready,
|
|
|
|
Playing,
|
|
|
|
Paused,
|
|
|
|
}
|
|
|
|
|
2022-01-16 12:19:52 +00:00
|
|
|
const AudioPreview: FC<{ file: OdFileObject }> = ({ file }) => {
|
2021-06-25 12:44:14 +00:00
|
|
|
const [playerStatus, setPlayerStatus] = useState(PlayerState.Loading)
|
|
|
|
|
2021-06-24 13:54:59 +00:00
|
|
|
return (
|
2021-06-25 14:15:00 +00:00
|
|
|
<>
|
2022-01-06 08:34:16 +00:00
|
|
|
<PreviewContainer>
|
2021-09-04 14:15:09 +00:00
|
|
|
<div className="md:flex-row md:space-x-4 flex flex-col space-y-4">
|
2021-12-18 01:43:24 +00:00
|
|
|
<div className="dark:bg-gray-700 aspect-square flex items-center justify-center w-full md:w-40 transition-all duration-75 bg-gray-100 rounded">
|
2021-06-25 14:15:00 +00:00
|
|
|
{playerStatus === PlayerState.Loading ? (
|
|
|
|
<div>
|
|
|
|
<svg
|
2021-09-04 14:15:09 +00:00
|
|
|
className="animate-spin w-5 h-5"
|
2021-06-25 14:15:00 +00:00
|
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
|
|
fill="none"
|
|
|
|
viewBox="0 0 24 24"
|
|
|
|
>
|
|
|
|
<circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4"></circle>
|
|
|
|
<path
|
|
|
|
className="opacity-75"
|
|
|
|
fill="currentColor"
|
|
|
|
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
|
|
|
|
></path>
|
|
|
|
</svg>
|
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<FontAwesomeIcon
|
|
|
|
className={`h-5 w-5 ${playerStatus === PlayerState.Playing ? 'animate-spin' : ''}`}
|
|
|
|
icon="music"
|
|
|
|
size="2x"
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
<div className="flex flex-col w-full space-y-2">
|
|
|
|
<div>{file.name}</div>
|
2021-09-04 14:15:09 +00:00
|
|
|
<div className="pb-4 text-sm text-gray-500">
|
2021-06-25 14:15:00 +00:00
|
|
|
Last modified:{' '}
|
|
|
|
{new Date(file.lastModifiedDateTime).toLocaleString(undefined, {
|
|
|
|
dateStyle: 'short',
|
|
|
|
timeStyle: 'short',
|
|
|
|
})}
|
2021-06-25 12:44:14 +00:00
|
|
|
</div>
|
2021-06-25 14:15:00 +00:00
|
|
|
<ReactPlayer
|
|
|
|
url={file['@microsoft.graph.downloadUrl']}
|
|
|
|
controls
|
|
|
|
width="100%"
|
|
|
|
height="48px"
|
|
|
|
config={{ file: { forceAudio: true } }}
|
|
|
|
onReady={() => {
|
|
|
|
setPlayerStatus(PlayerState.Ready)
|
|
|
|
}}
|
|
|
|
onPlay={() => {
|
|
|
|
setPlayerStatus(PlayerState.Playing)
|
|
|
|
}}
|
|
|
|
onPause={() => {
|
|
|
|
setPlayerStatus(PlayerState.Paused)
|
|
|
|
}}
|
|
|
|
onError={() => setPlayerStatus(PlayerState.Paused)}
|
|
|
|
onEnded={() => setPlayerStatus(PlayerState.Paused)}
|
2021-06-25 12:44:14 +00:00
|
|
|
/>
|
2021-06-24 21:32:22 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-01-06 08:34:16 +00:00
|
|
|
</PreviewContainer>
|
2021-12-29 07:52:18 +00:00
|
|
|
|
2022-01-06 08:34:16 +00:00
|
|
|
<DownloadBtnContainer>
|
2021-12-29 07:23:47 +00:00
|
|
|
<DownloadButtonGroup downloadUrl={file['@microsoft.graph.downloadUrl']} />
|
2022-01-06 08:34:16 +00:00
|
|
|
</DownloadBtnContainer>
|
2021-06-25 14:15:00 +00:00
|
|
|
</>
|
2021-06-24 13:54:59 +00:00
|
|
|
)
|
|
|
|
}
|
2021-12-17 15:16:18 +00:00
|
|
|
|
|
|
|
export default AudioPreview
|