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