Fix Media Items description autosave (#184)
This commit is contained in:
parent
9d36b8b8ca
commit
b52610d692
|
@ -162,7 +162,7 @@ export const PlayerPlaylist = (props: Props) => {
|
||||||
initialContent={mi.body}
|
initialContent={mi.body}
|
||||||
placeholder={`${t('Description')}...`}
|
placeholder={`${t('Description')}...`}
|
||||||
smallHeight={true}
|
smallHeight={true}
|
||||||
onAutoSave={(value) => handleMediaItemFieldChange('body', value)}
|
onChange={(value) => handleMediaItemFieldChange('body', value)}
|
||||||
/>
|
/>
|
||||||
<GrowingTextarea
|
<GrowingTextarea
|
||||||
allowEnterKey={true}
|
allowEnterKey={true}
|
||||||
|
|
|
@ -28,11 +28,14 @@ import { InsertLinkForm } from './InsertLinkForm'
|
||||||
import { Link } from '@tiptap/extension-link'
|
import { Link } from '@tiptap/extension-link'
|
||||||
import { UploadedFile } from '../../pages/types'
|
import { UploadedFile } from '../../pages/types'
|
||||||
import { Figure } from './extensions/Figure'
|
import { Figure } from './extensions/Figure'
|
||||||
|
import { Image } from '@tiptap/extension-image'
|
||||||
|
import { Figcaption } from './extensions/Figcaption'
|
||||||
|
import { useOutsideClickHandler } from '../../utils/useOutsideClickHandler'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
initialContent?: string
|
initialContent?: string
|
||||||
onSubmit?: (text: string) => void
|
onSubmit?: (text: string) => void
|
||||||
onAutoSave?: (text: string) => void
|
onChange?: (text: string) => void
|
||||||
placeholder: string
|
placeholder: string
|
||||||
submitButtonText?: string
|
submitButtonText?: string
|
||||||
quoteEnabled?: boolean
|
quoteEnabled?: boolean
|
||||||
|
@ -46,11 +49,18 @@ type Props = {
|
||||||
const SimplifiedEditor = (props: Props) => {
|
const SimplifiedEditor = (props: Props) => {
|
||||||
const { t } = useLocalize()
|
const { t } = useLocalize()
|
||||||
|
|
||||||
const editorElRef: {
|
const wrapperEditorElRef: {
|
||||||
current: HTMLDivElement
|
current: HTMLElement
|
||||||
} = {
|
} = {
|
||||||
current: null
|
current: null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const editorElRef: {
|
||||||
|
current: HTMLElement
|
||||||
|
} = {
|
||||||
|
current: null
|
||||||
|
}
|
||||||
|
|
||||||
const {
|
const {
|
||||||
actions: { setEditor }
|
actions: { setEditor }
|
||||||
} = useEditorContext()
|
} = useEditorContext()
|
||||||
|
@ -82,6 +92,8 @@ const SimplifiedEditor = (props: Props) => {
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
ImageFigure,
|
ImageFigure,
|
||||||
|
Image,
|
||||||
|
Figcaption,
|
||||||
Placeholder.configure({
|
Placeholder.configure({
|
||||||
emptyNodeClass: styles.emptyNode,
|
emptyNodeClass: styles.emptyNode,
|
||||||
placeholder: props.placeholder
|
placeholder: props.placeholder
|
||||||
|
@ -174,16 +186,17 @@ const SimplifiedEditor = (props: Props) => {
|
||||||
window.removeEventListener('keydown', handleKeyDown)
|
window.removeEventListener('keydown', handleKeyDown)
|
||||||
})
|
})
|
||||||
|
|
||||||
if (props.onAutoSave) {
|
if (props.onChange) {
|
||||||
createEffect(() => {
|
createEffect(() => {
|
||||||
if (isFocused()) return
|
props.onChange(html())
|
||||||
props.onAutoSave(html())
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleInsertLink = () => !editor().state.selection.empty && showModal('editorInsertLink')
|
const handleInsertLink = () => !editor().state.selection.empty && showModal('editorInsertLink')
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
|
ref={(el) => (wrapperEditorElRef.current = el)}
|
||||||
class={clsx(styles.SimplifiedEditor, {
|
class={clsx(styles.SimplifiedEditor, {
|
||||||
[styles.smallHeight]: props.smallHeight,
|
[styles.smallHeight]: props.smallHeight,
|
||||||
[styles.isFocused]: isFocused() || !isEmpty()
|
[styles.isFocused]: isFocused() || !isEmpty()
|
||||||
|
@ -257,7 +270,7 @@ const SimplifiedEditor = (props: Props) => {
|
||||||
</Popover>
|
</Popover>
|
||||||
</Show>
|
</Show>
|
||||||
</div>
|
</div>
|
||||||
<Show when={!props.onAutoSave}>
|
<Show when={!props.onChange}>
|
||||||
<div class={styles.buttons}>
|
<div class={styles.buttons}>
|
||||||
<Button value={t('Cancel')} variant="secondary" disabled={isEmpty()} onClick={handleClear} />
|
<Button value={t('Cancel')} variant="secondary" disabled={isEmpty()} onClick={handleClear} />
|
||||||
<Button
|
<Button
|
||||||
|
|
|
@ -35,6 +35,7 @@ export const SolidSwiper = (props: Props) => {
|
||||||
const { t } = useLocalize()
|
const { t } = useLocalize()
|
||||||
const [loading, setLoading] = createSignal(false)
|
const [loading, setLoading] = createSignal(false)
|
||||||
const [slideIndex, setSlideIndex] = createSignal(0)
|
const [slideIndex, setSlideIndex] = createSignal(0)
|
||||||
|
const [slideBody, setSlideBody] = createSignal<string>()
|
||||||
|
|
||||||
const mainSwipeRef: { current: SwiperRef } = { current: null }
|
const mainSwipeRef: { current: SwiperRef } = { current: null }
|
||||||
const thumbSwipeRef: { current: SwiperRef } = { current: null }
|
const thumbSwipeRef: { current: SwiperRef } = { current: null }
|
||||||
|
@ -131,6 +132,10 @@ export const SolidSwiper = (props: Props) => {
|
||||||
}, 0)
|
}, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleSaveBeforeSlideChange = () => {
|
||||||
|
handleSlideDescriptionChange(slideIndex(), 'body', slideBody())
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div class={clsx(styles.Swiper, props.editorMode ? styles.editorMode : styles.articleMode)}>
|
<div class={clsx(styles.Swiper, props.editorMode ? styles.editorMode : styles.articleMode)}>
|
||||||
<div class={styles.container}>
|
<div class={styles.container}>
|
||||||
|
@ -157,6 +162,7 @@ export const SolidSwiper = (props: Props) => {
|
||||||
thumbs-swiper={'.thumbSwiper'}
|
thumbs-swiper={'.thumbSwiper'}
|
||||||
observer={true}
|
observer={true}
|
||||||
onSlideChange={handleSlideChange}
|
onSlideChange={handleSlideChange}
|
||||||
|
onBeforeSlideChangeStart={handleSaveBeforeSlideChange}
|
||||||
space-between={20}
|
space-between={20}
|
||||||
>
|
>
|
||||||
<For each={props.images}>
|
<For each={props.images}>
|
||||||
|
@ -324,7 +330,7 @@ export const SolidSwiper = (props: Props) => {
|
||||||
initialContent={props.images[slideIndex()].body}
|
initialContent={props.images[slideIndex()].body}
|
||||||
smallHeight={true}
|
smallHeight={true}
|
||||||
placeholder={t('Enter image description')}
|
placeholder={t('Enter image description')}
|
||||||
onAutoSave={(value) => handleSlideDescriptionChange(slideIndex(), 'body', value)}
|
onChange={(value) => setSlideBody(value)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</Show>
|
</Show>
|
||||||
|
|
|
@ -35,6 +35,7 @@ declare module 'solid-js' {
|
||||||
ref?: RefObject<SwiperRef>
|
ref?: RefObject<SwiperRef>
|
||||||
children?: JSX.Element
|
children?: JSX.Element
|
||||||
onSlideChange?: () => void
|
onSlideChange?: () => void
|
||||||
|
onBeforeSlideChangeStart?: () => void
|
||||||
class?: string
|
class?: string
|
||||||
}
|
}
|
||||||
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
||||||
|
|
Loading…
Reference in New Issue
Block a user