import { useState } from 'preact/hooks' import { Analytics } from '../../Analytics.js' import { useLocale, useProject } from '../../contexts/index.js' import { Btn } from '../Btn.js' import { TextInput } from '../forms/index.js' import { Modal } from '../Modal.js' interface Props { id: string, name: string, onClose: () => void, } 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() } return

{locale('project.rename_file')}

{error !== undefined && {error}}
}