fix html (old) mods editing #192
@ -22,7 +22,12 @@ import {
|
|||||||
ModPageLoaderResult,
|
ModPageLoaderResult,
|
||||||
SubmitModActionResult
|
SubmitModActionResult
|
||||||
} from '../types'
|
} from '../types'
|
||||||
import { initializeFormState, MOD_DRAFT_CACHE_KEY } from '../utils'
|
import {
|
||||||
|
initializeFormState,
|
||||||
|
log,
|
||||||
|
LogType,
|
||||||
|
MOD_DRAFT_CACHE_KEY
|
||||||
|
} from '../utils'
|
||||||
import { CheckboxField, InputField, InputFieldWithImageUpload } from './Inputs'
|
import { CheckboxField, InputField, InputFieldWithImageUpload } from './Inputs'
|
||||||
import { OriginalAuthor } from './OriginalAuthor'
|
import { OriginalAuthor } from './OriginalAuthor'
|
||||||
import { CategoryAutocomplete } from './CategoryAutocomplete'
|
import { CategoryAutocomplete } from './CategoryAutocomplete'
|
||||||
@ -32,6 +37,7 @@ import { MEDIA_OPTIONS } from 'controllers'
|
|||||||
import { InputError } from './Inputs/Error'
|
import { InputError } from './Inputs/Error'
|
||||||
import { ImageUpload } from './Inputs/ImageUpload'
|
import { ImageUpload } from './Inputs/ImageUpload'
|
||||||
import { useLocalCache } from 'hooks/useLocalCache'
|
import { useLocalCache } from 'hooks/useLocalCache'
|
||||||
|
import { toast } from 'react-toastify'
|
||||||
|
|
||||||
interface GameOption {
|
interface GameOption {
|
||||||
value: string
|
value: string
|
||||||
@ -59,6 +65,13 @@ export const ModForm = () => {
|
|||||||
isEditing ? initializeFormState(mod) : cache ? cache : initializeFormState()
|
isEditing ? initializeFormState(mod) : cache ? cache : initializeFormState()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Enable backwards compatibility with the mods that used html
|
||||||
|
const body = useMemo(() => {
|
||||||
|
// Replace the most problematic HTML tags (<br>)
|
||||||
|
const fixed = formState.body.replaceAll(/<br>/g, '\r\n')
|
||||||
|
return fixed
|
||||||
|
}, [formState.body])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!isEditing) {
|
if (!isEditing) {
|
||||||
const newCache = _.cloneDeep(formState)
|
const newCache = _.cloneDeep(formState)
|
||||||
@ -253,11 +266,15 @@ export const ModForm = () => {
|
|||||||
<div className='inputMain'>
|
<div className='inputMain'>
|
||||||
<Editor
|
<Editor
|
||||||
ref={editorRef}
|
ref={editorRef}
|
||||||
markdown={formState.body}
|
markdown={body}
|
||||||
placeholder="Here's what this mod is all about"
|
placeholder="Here's what this mod is all about"
|
||||||
onChange={(md) => {
|
onChange={(md) => {
|
||||||
handleInputChange('body', md)
|
handleInputChange('body', md)
|
||||||
}}
|
}}
|
||||||
|
onError={(payload) => {
|
||||||
|
toast.error('Markdown error. Fix manually in the source mode.')
|
||||||
|
log(true, LogType.Error, payload.error)
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
{typeof formErrors?.body !== 'undefined' && (
|
{typeof formErrors?.body !== 'undefined' && (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user