from pathlib import Path p = Path(r"C:\Users\dream\CCAI-Demo-Canvas-Upgrades\phd-advisor-frontend\src\components\Sidebar.js") c = p.read_text(encoding="utf-8") avatar_old = ( '
\n' ' \n' '
' ) avatar_new = ( ' onAvatarChange && setShowAvatarPicker(true)}\n' ' style={{\n' " cursor: onAvatarChange ? 'pointer' : undefined,\n" ' backgroundColor: currentAvatar?.bg || undefined,\n' ' color: currentAvatar?.color || undefined,\n' ' }}\n' " title={onAvatarChange ? 'Change avatar' : undefined}\n" ' >\n' ' \n' ' ' ) avatar_new = avatar_new.replace("\n' ' \n' ' \n' ' \n' ' )}' ) menu_new = ( ' {showUserMenu && (\n' '
\n' ' \n' ' \n' ' \n' ' \n' ' \n' '
\n' ' )}' ) if avatar_old not in c: raise SystemExit("avatar block not found") c = c.replace(avatar_old, avatar_new, 1) if menu_old not in c: raise SystemExit("menu block not found") c = c.replace(menu_old, menu_new, 1) picker = """ {showAvatarPicker && ( { onAvatarChange?.(id); setShowAvatarPicker(false); }} onClose={() => setShowAvatarPicker(false)} /> )} """ if "UserAvatarPicker" not in c.split("export default")[0].split("return (")[-1]: c = c.replace( " {isMobileOpen && (", picker + "\n {isMobileOpen && (", 1, ) p.write_text(c, encoding="utf-8") print("Sidebar patched")