fix(mod): reset form

This commit is contained in:
enes 2025-01-08 13:59:35 +01:00
parent a278800025
commit ed3585f9c8
2 changed files with 19 additions and 25 deletions

View File

@ -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), {

View File

@ -131,16 +131,18 @@ 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: '', : [
hash: '', {
signatureKey: '', url: '',
malwareScanLink: '', hash: '',
modVersion: '', signatureKey: '',
customNote: '' malwareScanLink: '',
} modVersion: '',
] customNote: ''
}
]
}) })