diff --git a/src/app/components/generator/FileCreation.tsx b/src/app/components/generator/FileCreation.tsx index d7e57caf..83252fd2 100644 --- a/src/app/components/generator/FileCreation.tsx +++ b/src/app/components/generator/FileCreation.tsx @@ -16,8 +16,18 @@ export function FileCreation({ model, id, method, onClose }: Props) { const { locale } = useLocale() const { projects, project, updateFile } = useProject() const [fileId, setFileId] = useState(id === 'pack_mcmeta' ? 'pack' : '') + const [error, setError] = useState() + + const changeFileId = (str: string) => { + setError(undefined) + setFileId(str) + } const doSave = () => { + if (!fileId.match(/^([a-z0-9_.-]+:)?[a-z0-9/_.-]+$/)) { + setError('Invalid resource location') + return + } Analytics.saveProjectFile(id, projects.length, project.files.length, method as any) updateFile(id, undefined, { type: id, id: fileId, data: DataModel.unwrapLists(model.data) }) onClose() @@ -25,7 +35,8 @@ export function FileCreation({ model, id, method, onClose }: Props) { return

{locale('project.save_current_file')}

- + + {error !== undefined && {error}}
} diff --git a/src/app/components/generator/FileRenaming.tsx b/src/app/components/generator/FileRenaming.tsx index 2292333f..20269483 100644 --- a/src/app/components/generator/FileRenaming.tsx +++ b/src/app/components/generator/FileRenaming.tsx @@ -14,8 +14,18 @@ export function FileRenaming({ id, name, onClose }: Props) { const { locale } = useLocale() const { projects, project, updateFile } = useProject() const [fileId, setFileId] = useState(name) + const [error, setError] = useState() + + const changeFileId = (str: string) => { + setError(undefined) + setFileId(str) + } const doSave = () => { + if (!fileId.match(/^([a-z0-9_.-]+:)?[a-z0-9/_.-]+$/)) { + setError('Invalid resource location') + return + } Analytics.renameProjectFile(id, projects.length, project.files.length, 'menu') updateFile(id, name, { type: id, id: fileId }) onClose() @@ -23,7 +33,8 @@ export function FileRenaming({ id, name, onClose }: Props) { return

{locale('project.rename_file')}

- + + {error !== undefined && {error}}
} diff --git a/src/styles/global.css b/src/styles/global.css index 6f519b17..3de5a5c5 100644 --- a/src/styles/global.css +++ b/src/styles/global.css @@ -1417,6 +1417,11 @@ main.has-project { pointer-events: all; } +.modal span.invalid { + color: var(--invalid-text); + font-size: 16px; +} + [data-modals] .tree { pointer-events: none; }