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

View File

@ -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: ''
}
]
})