17 lines
1.4 KiB
Python
Executable file
17 lines
1.4 KiB
Python
Executable file
import re
|
|
|
|
with open('c:/ScriptoriumAI/scriptoriumai-ui/src/pages/EditorSimplified.tsx', 'r', encoding='utf-8') as f:
|
|
text = f.read()
|
|
|
|
if 'ConflictResolutionModal' not in text:
|
|
text = text.replace("import { OverleafLogin } from '../components/OverleafLogin'", "import { OverleafLogin } from '../components/OverleafLogin'\nimport { ConflictResolutionModal } from '../components/ConflictResolutionModal'")
|
|
|
|
# Add state
|
|
text = text.replace("const [saveIndicator, setSaveIndicator] = useState<'saved' | 'saving' | 'error'>('saved')", "const [saveIndicator, setSaveIndicator] = useState<'saved' | 'saving' | 'error'>('saved')\n const [showConflictModal, setShowConflictModal] = useState(false)\n const [conflictMessage, setConflictMessage] = useState<string | undefined>(undefined)")
|
|
|
|
text = re.sub(r'(if \(!ok\) \{[^{]*?if \(res\.status === 409 \|\| res\.status === 412\) \{[^{]*?// Conflict)', r'\1\n setShowConflictModal(true)\n setSaveIndicator(\'error\')', text)
|
|
|
|
text = re.sub(r'(</Fragment>|<Fragment>\s*)$', r' <ConflictResolutionModal isOpen={showConflictModal} message={conflictMessage} onReloadRemote={() => { setShowConflictModal(false); if (projectId && activeFileId) { fetchFile(projectId, activeFileId) } }} onClose={() => setShowConflictModal(false)} />\n\1', text)
|
|
|
|
with open('c:/ScriptoriumAI/scriptoriumai-ui/src/pages/EditorSimplified.tsx', 'w', encoding='utf-8') as f:
|
|
f.write(text)
|