Repository navigation
Expand file tree
/
Copy pathupdate_sorting.py
More file actions
50 lines (37 loc) · 1.86 KB
/
Copy pathupdate_sorting.py
File metadata and controls
50 lines (37 loc) · 1.86 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
import re
# Update App.tsx
with open('src/App.tsx', 'r') as f:
content = f.read()
content = content.replace("import { cn, truncateForFirestore } from './lib/utils';", "import { cn, truncateForFirestore, getMillis } from './lib/utils';")
sorting_old = """ // Sort on client side to avoid needing a composite index
loadedSessions.sort((a, b) => {
const timeA = a.createdAt?.toMillis ? a.createdAt.toMillis() : 0;
const timeB = b.createdAt?.toMillis ? b.createdAt.toMillis() : 0;
return timeB - timeA;
});"""
sorting_new = """ // Sort on client side to avoid needing a composite index
loadedSessions.sort((a, b) => {
const timeA = getMillis(a.createdAt);
const timeB = getMillis(b.createdAt);
return timeB - timeA;
});"""
content = content.replace(sorting_old, sorting_new)
with open('src/App.tsx', 'w') as f:
f.write(content)
# Update HistoryDashboard.tsx
with open('src/components/HistoryDashboard.tsx', 'r') as f:
content = f.read()
content = content.replace("import { formatDistanceToNow } from 'date-fns';", "import { formatDistanceToNow } from 'date-fns';\nimport { getMillis } from '../lib/utils';")
sorting_old2 = """ {historySessions.sort((a, b) => {
const timeA = a.createdAt?.toMillis ? a.createdAt.toMillis() : 0;
const timeB = b.createdAt?.toMillis ? b.createdAt.toMillis() : 0;
return timeB - timeA;
}).map(session => ("""
sorting_new2 = """ {historySessions.sort((a, b) => {
const timeA = getMillis(a.createdAt);
const timeB = getMillis(b.createdAt);
return timeB - timeA;
}).map(session => ("""
content = content.replace(sorting_old2, sorting_new2)
with open('src/components/HistoryDashboard.tsx', 'w') as f:
f.write(content)