openpetswithchatandmcp/website/update_editor_conflict_fix2.py
OpenPets Dev 65ac83849e Add 'website/' from commit '966aea480ffe1c340553aa878def30131d2af827'
git-subtree-dir: website
git-subtree-mainline: 8d3849caea
git-subtree-split: 966aea480f
2026-06-17 20:48:39 +00:00

18 lines
1.8 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()
text = text.replace("const [isSaving, setIsSaving] = useState(false)", "const [isSaving, setIsSaving] = useState(false)\n const [showConflictModal, setShowConflictModal] = useState(false)\n const [conflictMessage, setConflictMessage] = useState<string | undefined>(undefined)")
# For saving conflict error handling - there isn't handleSave with 409 right now probably... let's see how save is done
# We'll just hook standard error to display conflict if it has "409"
text = re.sub(r'(} catch \(e: any\) {)', r'} catch (e: any) {\n if (e.message && e.message.includes("409")) {\n setConflictMessage(e.message)\n setShowConflictModal(true)\n }', text)
text = re.sub(r'(\}\s+const handleCompile)', r' const handleReloadRemote = useCallback(() => {\n setShowConflictModal(false)\n handleLoadProject()\n }, [handleLoadProject])\n\n\1', 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)
# It seems there is no Fragment at end. Let's find the main element end.
text = text.replace('{/* Render conditionally */}', '<ConflictResolutionModal isOpen={showConflictModal} message={conflictMessage} onReloadRemote={() => { setShowConflictModal(false); }} onClose={() => setShowConflictModal(false)} />\n {/* Render conditionally */}')
with open('c:/ScriptoriumAI/scriptoriumai-ui/src/pages/EditorSimplified.tsx', 'w', encoding='utf-8') as f:
f.write(text)