Hotfix/player hotfixies (#122)

* proxy audio
* optionalParams in composeMediaItems
This commit is contained in:
Ilya Y 2023-07-16 00:51:38 +03:00 committed by GitHub
parent d7184ddc9e
commit 17e9d7d8ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 53 additions and 31 deletions

View File

@ -55,6 +55,7 @@
object-fit: cover; object-fit: cover;
width: 100%; width: 100%;
height: 100%; height: 100%;
display: block;
} }
.expand { .expand {

View File

@ -3,7 +3,7 @@ import { PlayerHeader } from './PlayerHeader'
import { PlayerPlaylist } from './PlayerPlaylist' import { PlayerPlaylist } from './PlayerPlaylist'
import styles from './AudioPlayer.module.scss' import styles from './AudioPlayer.module.scss'
import { MediaItem } from '../../../pages/types' import { MediaItem } from '../../../pages/types'
import { audioProxy } from '../../../utils/imageProxy' import { imageProxy } from '../../../utils/imageProxy'
export type Audio = { export type Audio = {
pic?: string pic?: string
@ -23,7 +23,7 @@ type Props = {
const prepareMedia = (media: Audio[]) => const prepareMedia = (media: Audio[]) =>
media.map((item, index) => ({ media.map((item, index) => ({
...item, ...item,
url: audioProxy(item.url), url: imageProxy(item.url),
index: index, index: index,
isCurrent: false, isCurrent: false,
isPlaying: false isPlaying: false

View File

@ -3,7 +3,7 @@ import styles from './AudioUploader.module.scss'
import { DropArea } from '../../_shared/DropArea' import { DropArea } from '../../_shared/DropArea'
import { useLocalize } from '../../../context/localize' import { useLocalize } from '../../../context/localize'
import { createEffect, createSignal, on, Show } from 'solid-js' import { createEffect, createSignal, on, Show } from 'solid-js'
import { MediaItem } from '../../../pages/types' import { MediaItem, UploadedFile } from '../../../pages/types'
import { composeMediaItems } from '../../../utils/composeMediaItems' import { composeMediaItems } from '../../../utils/composeMediaItems'
import { AudioPlayer } from '../../Article/AudioPlayer' import { AudioPlayer } from '../../Article/AudioPlayer'
import { Buffer } from 'buffer' import { Buffer } from 'buffer'
@ -13,6 +13,11 @@ window.Buffer = Buffer
type Props = { type Props = {
class?: string class?: string
audio: MediaItem[] audio: MediaItem[]
baseFields?: {
artist?: string
date?: string
genre?: string
}
onAudioChange: (index: number, value: MediaItem) => void onAudioChange: (index: number, value: MediaItem) => void
onAudioAdd: (value: MediaItem[]) => void onAudioAdd: (value: MediaItem[]) => void
} }
@ -34,7 +39,7 @@ export const AudioUploader = (props: Props) => {
placeholder={t('Add audio')} placeholder={t('Add audio')}
description={t('You can download multiple tracks at once in .mp3, .wav or .flac formats')} description={t('You can download multiple tracks at once in .mp3, .wav or .flac formats')}
fileType={'audio'} fileType={'audio'}
onUpload={(value) => props.onAudioAdd(composeMediaItems(value))} onUpload={(value) => props.onAudioAdd(composeMediaItems(value, props.baseFields))}
/> />
</div> </div>
) )

View File

@ -1,4 +1,4 @@
import { Accessor, createMemo, createSignal, For, onCleanup, onMount, Show } from 'solid-js' import { Accessor, createEffect, createMemo, createSignal, For, onCleanup, onMount, Show } from 'solid-js'
import { useLocalize } from '../../context/localize' import { useLocalize } from '../../context/localize'
import { clsx } from 'clsx' import { clsx } from 'clsx'
import { Title } from '@solidjs/meta' import { Title } from '@solidjs/meta'
@ -147,9 +147,19 @@ export const EditView = (props: Props) => {
setForm('media', JSON.stringify(updated)) setForm('media', JSON.stringify(updated))
} }
const [baseAudioFields, setBaseAudioFields] = createSignal({
artist: '',
date: '',
genre: ''
})
const handleBaseFieldsChange = (key, value) => { const handleBaseFieldsChange = (key, value) => {
const updated = mediaItems().map((media) => ({ ...media, [key]: value })) if (mediaItems().length > 0) {
setForm('media', JSON.stringify(updated)) const updated = mediaItems().map((media) => ({ ...media, [key]: value }))
setForm('media', JSON.stringify(updated))
} else {
setBaseAudioFields({ ...baseAudioFields(), [key]: value })
}
} }
const articleTitle = () => { const articleTitle = () => {
@ -260,29 +270,31 @@ export const EditView = (props: Props) => {
/> />
</Show> </Show>
</div> </div>
<Show <Show when={props.shout.layout === 'audio'}>
when={form.coverImageUrl} <Show
fallback={ when={form.coverImageUrl}
<DropArea fallback={
isSquare={true} <DropArea
placeholder={t('Add cover')} isSquare={true}
description={ placeholder={t('Add cover')}
<> description={
{t('min. 1400×1400 pix')} <>
<br /> {t('min. 1400×1400 pix')}
{t('jpg, .png, max. 10 mb.')} <br />
</> {t('jpg, .png, max. 10 mb.')}
} </>
isMultiply={false} }
fileType={'image'} isMultiply={false}
onUpload={(val) => setForm('coverImageUrl', val[0].url)} fileType={'image'}
onUpload={(val) => setForm('coverImageUrl', val[0].url)}
/>
}
>
<div
class={styles.cover}
style={{ 'background-image': `url(${imageProxy(form.coverImageUrl)})` }}
/> />
} </Show>
>
<div
class={styles.cover}
style={{ 'background-image': `url(${imageProxy(form.coverImageUrl)})` }}
/>
</Show> </Show>
</div> </div>
@ -326,6 +338,7 @@ export const EditView = (props: Props) => {
<Show when={props.shout.layout === 'audio'}> <Show when={props.shout.layout === 'audio'}>
<AudioUploader <AudioUploader
audio={mediaItems()} audio={mediaItems()}
baseFields={baseAudioFields()}
onAudioAdd={(value) => handleAddMedia(value)} onAudioAdd={(value) => handleAddMedia(value)}
onAudioChange={handleMediaChange} onAudioChange={handleMediaChange}
/> />

View File

@ -1,10 +1,13 @@
export const composeMediaItems = (value) => { import { UploadedFile } from '../pages/types'
export const composeMediaItems = (value: UploadedFile[], optionalParams = {}) => {
return value.map((fileData) => { return value.map((fileData) => {
return { return {
url: fileData.url, url: fileData.url,
source: '', source: '',
title: fileData.originalFilename, title: fileData.originalFilename,
body: '' body: '',
...optionalParams
} }
}) })
} }