2023-07-14 13:06:21 +00:00
|
|
|
import { clsx } from 'clsx'
|
|
|
|
import styles from './AudioUploader.module.scss'
|
|
|
|
import { DropArea } from '../../_shared/DropArea'
|
|
|
|
import { useLocalize } from '../../../context/localize'
|
|
|
|
import { createEffect, createSignal, on, Show } from 'solid-js'
|
2023-07-15 21:51:38 +00:00
|
|
|
import { MediaItem, UploadedFile } from '../../../pages/types'
|
2023-07-14 13:06:21 +00:00
|
|
|
import { composeMediaItems } from '../../../utils/composeMediaItems'
|
|
|
|
import { AudioPlayer } from '../../Article/AudioPlayer'
|
|
|
|
import { Buffer } from 'buffer'
|
|
|
|
|
|
|
|
window.Buffer = Buffer
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
class?: string
|
|
|
|
audio: MediaItem[]
|
2023-07-15 21:51:38 +00:00
|
|
|
baseFields?: {
|
|
|
|
artist?: string
|
|
|
|
date?: string
|
|
|
|
genre?: string
|
|
|
|
}
|
2023-07-14 13:06:21 +00:00
|
|
|
onAudioChange: (index: number, value: MediaItem) => void
|
|
|
|
onAudioAdd: (value: MediaItem[]) => void
|
|
|
|
}
|
|
|
|
|
|
|
|
export const AudioUploader = (props: Props) => {
|
|
|
|
const { t } = useLocalize()
|
|
|
|
|
|
|
|
const handleAudioDescriptionChange = (index: number, field: string, value) => {
|
|
|
|
props.onAudioChange(index, { ...props.audio[index], [field]: value })
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div class={clsx(styles.AudioUploader, props.class)}>
|
|
|
|
<Show when={props.audio.length > 0}>
|
|
|
|
<AudioPlayer editorMode={true} media={props.audio} onAudioChange={handleAudioDescriptionChange} />
|
|
|
|
</Show>
|
|
|
|
<DropArea
|
|
|
|
isMultiply={true}
|
|
|
|
placeholder={t('Add audio')}
|
|
|
|
description={t('You can download multiple tracks at once in .mp3, .wav or .flac formats')}
|
|
|
|
fileType={'audio'}
|
2023-07-15 21:51:38 +00:00
|
|
|
onUpload={(value) => props.onAudioAdd(composeMediaItems(value, props.baseFields))}
|
2023-07-14 13:06:21 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|