Repository navigation
Expand file tree
/
Copy pathpatch_profile.py
More file actions
executable file
·54 lines (47 loc) · 2.16 KB
/
Copy pathpatch_profile.py
File metadata and controls
executable file
·54 lines (47 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import re
with open('frontend/src/pages/Profile.jsx', 'r') as f:
content = f.read()
func = """
const [isRecalculating, setIsRecalculating] = useState(false);
const handleRecalculateCommutes = async () => {
setIsRecalculating(true);
try {
const res = await fetch(`${import.meta.env.VITE_API_URL || 'http://localhost:8000'}/api/profile/recalculate-commutes`, {
method: 'POST'
});
if (res.ok) {
alert("Commute recalculation started in the background!");
} else {
alert("Failed to start commute recalculation.");
}
} catch(e) {
console.error(e);
alert("Error starting recalculation.");
}
setIsRecalculating(false);
};
"""
if 'const [isRecalculating' not in content:
content = content.replace("const [loading, setLoading] = useState(true);", "const [loading, setLoading] = useState(true);\n" + func)
btn = """
</InputGroup>
</div>
<div style={{ marginTop: '1.5rem', display: 'flex', justifyContent: 'flex-start' }}>
<button
onClick={handleRecalculateCommutes}
disabled={isRecalculating || loading}
className="btn-secondary"
style={{ display: 'flex', alignItems: 'center', gap: '8px' }}
>
<span className="material-symbols-outlined" style={{ fontSize: '18px' }}>
{isRecalculating ? 'sync' : 'directions_car'}
</span>
{isRecalculating ? 'Recalculating...' : 'Recalculate All Commutes'}
</button>
</div>
</section>
"""
content = content.replace(" </InputGroup>\n </div>\n </section>", btn)
with open('frontend/src/pages/Profile.jsx', 'w') as f:
f.write(content)
print("done")