feat(exercises): update inline media functionality and version bump to 0.8.63
Deploy Development / deploy (push) Successful in 34s
Test Suite / pytest-backend (push) Successful in 24s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 7s
Test Suite / playwright-tests (push) Successful in 30s
Deploy Development / deploy (push) Successful in 34s
Test Suite / pytest-backend (push) Successful in 24s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 7s
Test Suite / playwright-tests (push) Successful in 30s
- Incremented application version to 0.8.63 and updated changelog with new features. - Enhanced inline media handling in the Rich Text Editor, including support for captions. - Introduced new CSS styles for improved media display and layout in the editor. - Replaced `ExerciseMediaEmbed` with `ExerciseAttachmentMediaStrip` for better media management in exercise content.
This commit is contained in:
1 parent
311a106d93
commit
337f29401b
13 files changed
+887
-429
No files matched your search
@@ -1,13 +1,15 @@
|
||||
/**
|
||||
* Modal: Medium aus Archiv verknüpfen oder neue Datei hochladen, dann Inline-Platzhalter §11 einfügen.
|
||||
*/
|
||||
import React, { useEffect, useState, useCallback } from 'react'
|
||||
import React, { useEffect, useState, useCallback, useMemo } from 'react'
|
||||
import api from '../utils/api'
|
||||
import { resolveMediaAssetFileUrl } from '../utils/exerciseMediaUrl'
|
||||
import {
|
||||
INLINE_MEDIA_SIZES,
|
||||
DEFAULT_INLINE_MEDIA_SIZE,
|
||||
sanitizeInlineMediaSize,
|
||||
} from '../constants/inlineExerciseMedia'
|
||||
import { sanitizeInlineMediaCaption } from '../utils/inlineMediaCaption'
|
||||
|
||||
/** MIME/Dateiname → Übungs-media_type */
|
||||
function inferExerciseMediaType(file) {
|
||||
@@ -28,14 +30,16 @@ function inferExerciseMediaType(file) {
|
||||
* open: boolean,
|
||||
* onClose: () => void,
|
||||
* exerciseId: number,
|
||||
* linkedExerciseMedia?: object[],
|
||||
* onMediaListChanged: () => Promise<void>,
|
||||
* onInserted: (exerciseMediaId: number, displaySize: string) => void,
|
||||
* onInserted: (exerciseMediaId: number, displaySize: string, caption?: string) => void,
|
||||
* }} props
|
||||
*/
|
||||
export default function ExerciseInlineFileMediaModal({
|
||||
open,
|
||||
onClose,
|
||||
exerciseId,
|
||||
linkedExerciseMedia = [],
|
||||
onMediaListChanged,
|
||||
onInserted,
|
||||
}) {
|
||||
@@ -49,6 +53,16 @@ export default function ExerciseInlineFileMediaModal({
|
||||
const [uploadFile, setUploadFile] = useState(null)
|
||||
const [uploadTitle, setUploadTitle] = useState('')
|
||||
const [displaySize, setDisplaySize] = useState(DEFAULT_INLINE_MEDIA_SIZE)
|
||||
const [uploadInputKey, setUploadInputKey] = useState(0)
|
||||
|
||||
const assetToExerciseMedia = useMemo(() => {
|
||||
const m = new Map()
|
||||
for (const row of linkedExerciseMedia || []) {
|
||||
const aid = row?.media_asset_id
|
||||
if (aid != null) m.set(Number(aid), row)
|
||||
}
|
||||
return m
|
||||
}, [linkedExerciseMedia])
|
||||
|
||||
const loadAssets = useCallback(async () => {
|
||||
setLoading(true)
|
||||
@@ -74,6 +88,7 @@ export default function ExerciseInlineFileMediaModal({
|
||||
setSelectedAssetId(null)
|
||||
setUploadFile(null)
|
||||
setUploadTitle('')
|
||||
setUploadInputKey((k) => k + 1)
|
||||
setDisplaySize(DEFAULT_INLINE_MEDIA_SIZE)
|
||||
setErr(null)
|
||||
const t = setTimeout(loadAssets, 280)
|
||||
@@ -92,6 +107,17 @@ export default function ExerciseInlineFileMediaModal({
|
||||
return
|
||||
}
|
||||
const size = sanitizeInlineMediaSize(displaySize)
|
||||
const assetMeta = items.find((x) => x.id === selectedAssetId)
|
||||
const capFromExisting = (row) =>
|
||||
sanitizeInlineMediaCaption(row?.original_filename || row?.title || assetMeta?.original_filename || '')
|
||||
|
||||
const existing = assetToExerciseMedia.get(Number(selectedAssetId))
|
||||
if (existing?.id != null) {
|
||||
onInserted(Number(existing.id), size, capFromExisting(existing))
|
||||
onClose()
|
||||
return
|
||||
}
|
||||
|
||||
setBusy(true)
|
||||
setErr(null)
|
||||
try {
|
||||
@@ -107,12 +133,15 @@ export default function ExerciseInlineFileMediaModal({
|
||||
throw new Error('Antwort ohne exercise_media-ID')
|
||||
}
|
||||
await onMediaListChanged()
|
||||
onInserted(Number(mid), size)
|
||||
onInserted(
|
||||
Number(mid),
|
||||
size,
|
||||
sanitizeInlineMediaCaption(assetMeta?.original_filename || ''),
|
||||
)
|
||||
onClose()
|
||||
} catch (e) {
|
||||
const msg = e.message || String(e)
|
||||
setErr(msg)
|
||||
alert(msg)
|
||||
} finally {
|
||||
setBusy(false)
|
||||
}
|
||||
@@ -141,9 +170,13 @@ export default function ExerciseInlineFileMediaModal({
|
||||
throw new Error('Antwort ohne exercise_media-ID')
|
||||
}
|
||||
await onMediaListChanged()
|
||||
onInserted(Number(mid), size)
|
||||
const cap = sanitizeInlineMediaCaption(
|
||||
uploadTitle.trim() || uploadFile.name || '',
|
||||
)
|
||||
onInserted(Number(mid), size, cap)
|
||||
setUploadFile(null)
|
||||
setUploadTitle('')
|
||||
setUploadInputKey((k) => k + 1)
|
||||
onClose()
|
||||
} catch (e) {
|
||||
if (e.code === 'MEDIA_ASSET_IN_TRASH' && e.payload?.media_asset_id != null) {
|
||||
@@ -159,6 +192,8 @@ export default function ExerciseInlineFileMediaModal({
|
||||
}
|
||||
}
|
||||
|
||||
const selectedLinked = selectedAssetId != null && assetToExerciseMedia.has(Number(selectedAssetId))
|
||||
|
||||
if (!open) return null
|
||||
|
||||
return (
|
||||
@@ -208,6 +243,9 @@ export default function ExerciseInlineFileMediaModal({
|
||||
</div>
|
||||
|
||||
<div style={{ overflowY: 'auto', flex: 1, padding: '12px 14px' }}>
|
||||
{err && !loading ? (
|
||||
<p style={{ color: 'var(--danger)', marginTop: '0', marginBottom: '12px', fontSize: '0.9rem' }}>{err}</p>
|
||||
) : null}
|
||||
{tab === 'library' && (
|
||||
<>
|
||||
<label className="form-label">Suche in der Bibliothek</label>
|
||||
@@ -219,14 +257,15 @@ export default function ExerciseInlineFileMediaModal({
|
||||
disabled={busy}
|
||||
/>
|
||||
{loading ? <p style={{ color: 'var(--text3)', marginTop: '12px' }}>Laden…</p> : null}
|
||||
{err && tab === 'library' && !loading ? (
|
||||
<p style={{ color: 'var(--danger)', marginTop: '10px', fontSize: '0.9rem' }}>{err}</p>
|
||||
) : null}
|
||||
<div className="rte-inline-asset-grid" style={{ marginTop: '14px' }}>
|
||||
{items.map((it) => {
|
||||
const id = it.id
|
||||
const selected = selectedAssetId === id
|
||||
const label = it.original_filename || it.copyright_notice || `Archiv #${id}`
|
||||
const linked = assetToExerciseMedia.has(Number(id))
|
||||
const src = resolveMediaAssetFileUrl(id)
|
||||
const isImg = (it.mime_type || '').startsWith('image/')
|
||||
const isVid = (it.mime_type || '').startsWith('video/')
|
||||
return (
|
||||
<button
|
||||
key={id}
|
||||
@@ -235,6 +274,18 @@ export default function ExerciseInlineFileMediaModal({
|
||||
onClick={() => setSelectedAssetId(id)}
|
||||
disabled={busy}
|
||||
>
|
||||
<div className="rte-inline-asset-tile__thumb" aria-hidden>
|
||||
{isImg && src ? (
|
||||
<img alt="" src={src} className="rte-inline-asset-tile__thumb-img" />
|
||||
) : isVid ? (
|
||||
<span className="rte-inline-asset-tile__thumb-fallback">▶ Video</span>
|
||||
) : (
|
||||
<span className="rte-inline-asset-tile__thumb-fallback">PDF / Datei</span>
|
||||
)}
|
||||
</div>
|
||||
{linked ? (
|
||||
<span className="rte-inline-asset-tile__badge">Bereits verknüpft</span>
|
||||
) : null}
|
||||
<span className="rte-inline-asset-tile__meta">
|
||||
{(it.mime_type || '').split('/')[0] || 'datei'}
|
||||
</span>
|
||||
@@ -252,20 +303,26 @@ export default function ExerciseInlineFileMediaModal({
|
||||
{tab === 'upload' && (
|
||||
<>
|
||||
<label className="form-label">Datei</label>
|
||||
<input
|
||||
type="file"
|
||||
accept="image/*,video/*,application/pdf"
|
||||
className="form-input"
|
||||
disabled={busy}
|
||||
onChange={(e) => {
|
||||
const f = e.target.files?.[0] || null
|
||||
setUploadFile(f)
|
||||
e.target.value = ''
|
||||
}}
|
||||
/>
|
||||
{uploadFile ? (
|
||||
<p style={{ fontSize: '13px', color: 'var(--text2)', marginTop: '8px' }}>{uploadFile.name}</p>
|
||||
) : null}
|
||||
<div className="rte-inline-file-row">
|
||||
<input
|
||||
key={uploadInputKey}
|
||||
id="rte-inline-file-upload-input"
|
||||
type="file"
|
||||
accept="image/*,video/*,application/pdf"
|
||||
className="rte-inline-file-input-hidden"
|
||||
disabled={busy}
|
||||
onChange={(e) => {
|
||||
const f = e.target.files?.[0] || null
|
||||
setUploadFile(f)
|
||||
}}
|
||||
/>
|
||||
<label htmlFor="rte-inline-file-upload-input" className="btn btn-secondary rte-inline-file-pick-btn">
|
||||
Datei auswählen
|
||||
</label>
|
||||
<span className="rte-inline-file-name" title={uploadFile?.name || ''}>
|
||||
{uploadFile ? uploadFile.name : 'Keine Datei ausgewählt'}
|
||||
</span>
|
||||
</div>
|
||||
<label className="form-label" style={{ marginTop: '12px' }}>
|
||||
Titel (optional)
|
||||
</label>
|
||||
@@ -293,8 +350,13 @@ export default function ExerciseInlineFileMediaModal({
|
||||
</select>
|
||||
</div>
|
||||
{tab === 'library' ? (
|
||||
<button type="button" className="btn btn-primary btn-full" disabled={busy || !selectedAssetId} onClick={handleLinkSelected}>
|
||||
{busy ? 'Verknüpfen…' : 'Verknüpfen & in Text einfügen'}
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-primary btn-full"
|
||||
disabled={busy || !selectedAssetId}
|
||||
onClick={handleLinkSelected}
|
||||
>
|
||||
{busy ? 'Bitte warten…' : selectedLinked ? 'In Text einfügen (bereits verknüpft)' : 'Verknüpfen & in Text einfügen'}
|
||||
</button>
|
||||
) : (
|
||||
<button type="button" className="btn btn-primary btn-full" disabled={busy || !uploadFile} onClick={handleUploadAndInsert}>
|
||||
|
||||
Reference in new issue
Block a user