frontend: add edit button to both the sleep and triggers pages
Parents:
4dba6a82 file(s) changed
- frontend/app/sleep/[id].tsx +11 -6
- frontend/app/triggers/[id].tsx +7 -3
frontend/app/sleep/[id].tsx
1 1
import { useState, useEffect, use } from "react";
2 2
import {
3 3
StyleSheet,
4 4
Text,
5 5
View,
▸ 14 unchanged lines
20 20
import { MaterialIcons } from "@expo/vector-icons";
21 21
import {
22 22
useSleepRecord,
23 23
useDeleteSleepRecord,
24 24
} from "@/hooks/useSleepRecord.queries";
25 -
import { formatDate } from "@/lib/utils/time";
25 +
import { formatDate, parseDateOnly } from "@/lib/utils/time";
26 26
27 27
export default function SleepDetailScreen() {
28 28
const { id } = useLocalSearchParams<{ id: string }>();
29 29
const { data: sleepRecord, isLoading, isError } = useSleepRecord(id);
30 30
const deleteSleepRecord = useDeleteSleepRecord();
▸ 3 unchanged lines
34 34
useEffect(() => {
35 35
const updateTimer = () => {
36 36
const createdAt = sleepRecord?.createdAt;
37 37
if (!createdAt) return;
38 38
39 -
const msSinceCreation = Date.now() - createdAt.getTime();
39 +
const msSinceCreation = Date.now() - new Date(createdAt).getTime();
40 40
const deletionWindowMs = 5 * 60 * 1000;
41 41
42 42
const newCanDelete = msSinceCreation < deletionWindowMs;
43 43
const newMinutesLeft = Math.max(
44 44
0,
▸ 10 unchanged lines
55 55
56 56
const interval = setInterval(updateTimer, 1000);
57 57
58 58
return () => clearInterval(interval);
59 59
}, [sleepRecord, isLoading]);
60 -
61 -
console.log("sleepRecord", sleepRecord)
62 -
console.log("isLoading", isLoading)
63 60
64 61
if (isLoading) {
65 62
return (
66 63
<View style={styles.centered}>
67 64
<ActivityIndicator size="large" color={Colors.light.tint} />
▸ 46 unchanged lines
114 111
<Text style={styles.averageLabel}>{sleepRecord.average}h</Text>
115 112
<Text style={styles.suffixLabel}>de sono</Text>
116 113
</Row>
117 114
118 115
<Text style={styles.dateLabel}>
119 -
{formatDate(new Date(sleepRecord.date))}
116 +
{formatDate(parseDateOnly(sleepRecord.date))}
120 117
</Text>
121 118
</Col>
122 119
</Row>
123 120
</Card>
124 121
▸ 10 unchanged lines
135 132
)}
136 133
137 134
{/* Delete */}
138 135
<View style={styles.section}>
139 136
<Text style={styles.sectionLabel}>GESTÃO DO REGISTRO</Text>
137 +
<Button
138 +
variant="outline"
139 +
isLoading={false}
140 +
disabled={!canDelete}
141 +
onPress={() => router.push(`/sleep/edit/${sleepRecord.id}`)}
142 +
title="Editar Registro"
143 +
/>
144 +
140 145
<Button
141 146
variant="danger"
142 147
isLoading={deleteSleepRecord.isPending}
143 148
disabled={!canDelete || deleteSleepRecord.isPending}
144 149
onPress={handleDelete}
▸ 138 unchanged lines
283 288
color: Colors.light.textSecondary,
284 289
fontStyle: "italic",
285 290
padding: 4,
286 291
},
287 292
});
frontend/app/triggers/[id].tsx
1 1
import { useState, useEffect, use } from "react";
2 2
import {
3 3
StyleSheet,
4 4
Text,
5 5
View,
▸ 51 unchanged lines
57 57
const interval = setInterval(updateTimer, 1000);
58 58
59 59
return () => clearInterval(interval);
60 60
}, [trigger, isLoading]);
61 61
62 -
console.log("trigger", trigger)
63 -
console.log("isLoading", isLoading)
64 -
65 62
if (isLoading) {
66 63
return (
67 64
<View style={styles.centered}>
68 65
<ActivityIndicator size="large" color={Colors.light.tint} />
69 66
</View>
▸ 67 unchanged lines
137 134
)}
138 135
139 136
{/* Delete */}
140 137
<View style={styles.section}>
141 138
<Text style={styles.sectionLabel}>GESTÃO DO REGISTRO</Text>
139 +
<Button
140 +
variant="outline"
141 +
isLoading={false}
142 +
disabled={!canDelete}
143 +
onPress={() => router.push(`/triggers/edit/${trigger.id}`)}
144 +
title="Editar Registro"
145 +
/>
142 146
<Button
143 147
variant="danger"
144 148
isLoading={deleteTrigger.isPending}
145 149
disabled={!canDelete || deleteTrigger.isPending}
146 150
onPress={handleDelete}
▸ 89 unchanged lines
236 240
color: Colors.light.textSecondary,
237 241
fontStyle: "italic",
238 242
padding: 4,
239 243
},
240 244
});