fix(mod): reset form
This commit is contained in:
parent
a278800025
commit
ed3585f9c8
@ -154,20 +154,12 @@ export const ModForm = () => {
|
|||||||
// Cancel if not confirmed
|
// Cancel if not confirmed
|
||||||
if (!confirm) return
|
if (!confirm) return
|
||||||
|
|
||||||
// Editing
|
// Reset fields to the initial or original existing data
|
||||||
if (mod) {
|
const newState = initializeFormState(mod)
|
||||||
const initial = initializeFormState(mod)
|
|
||||||
|
|
||||||
// Reset editor
|
// Reset editor
|
||||||
editorRef.current?.setMarkdown(initial.body)
|
editorRef.current?.setMarkdown(newState.body)
|
||||||
|
setFormState(newState)
|
||||||
// Reset fields to the original existing data
|
|
||||||
setFormState(initial)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// New - set form state to the initial (clear form state)
|
|
||||||
setFormState(initializeFormState())
|
|
||||||
}
|
}
|
||||||
const handlePublish = () => {
|
const handlePublish = () => {
|
||||||
submit(JSON.stringify(formState), {
|
submit(JSON.stringify(formState), {
|
||||||
|
@ -131,9 +131,11 @@ export const initializeFormState = (
|
|||||||
originalAuthor: existingModData?.originalAuthor || undefined,
|
originalAuthor: existingModData?.originalAuthor || undefined,
|
||||||
screenshotsUrls: existingModData?.screenshotsUrls || [''],
|
screenshotsUrls: existingModData?.screenshotsUrls || [''],
|
||||||
tags: existingModData?.tags.join(',') || '',
|
tags: existingModData?.tags.join(',') || '',
|
||||||
lTags: existingModData?.lTags || [],
|
lTags: existingModData ? [...existingModData.lTags] : [],
|
||||||
LTags: existingModData?.LTags || [],
|
LTags: existingModData ? [...existingModData.LTags] : [],
|
||||||
downloadUrls: existingModData?.downloadUrls || [
|
downloadUrls: existingModData
|
||||||
|
? [...existingModData.downloadUrls.map((url) => ({ ...url }))]
|
||||||
|
: [
|
||||||
{
|
{
|
||||||
url: '',
|
url: '',
|
||||||
hash: '',
|
hash: '',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user