Skip to content

Commit b6a4e41

Browse files
committed
fix: update createdAt field handling and add AI instruction in scan screen
1 parent f9bf8d0 commit b6a4e41

6 files changed

Lines changed: 22 additions & 14 deletions

File tree

app/(tabs)/scan.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,8 @@ export default function ScanScreen() {
330330
},
331331
],
332332
contaminants: [],
333+
aiInstruction:
334+
"Rasio karbon terlalu tinggi, tambahkan bahan hijau seperti sisa sayur atau rumput.",
333335
}),
334336
},
335337
});

app/progress-detail.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ const DetailProgressScreen = () => {
327327
record.description = update.activity.description;
328328
record.isActive = true;
329329
record.timeLabel = update.activity.time;
330-
record._raw.created_at = Date.now();
330+
record.createdAt = Date.now();
331331
});
332332
});
333333

@@ -405,7 +405,7 @@ const DetailProgressScreen = () => {
405405
record.description = activityDesc;
406406
record.isActive = true;
407407
record.timeLabel = "Baru saja";
408-
record._raw.created_at = Date.now();
408+
record.createdAt = Date.now();
409409
});
410410
});
411411

app/result.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ export default function ResultScreen() {
427427
.create((record: any) => {
428428
record.fullName = "Pengguna Offline";
429429
record.totalCompostKg = 0;
430-
record.createdAt = new Date().toISOString();
430+
record.createdAt = Date.now();
431431
});
432432
profileId = profile.id;
433433
}
@@ -437,7 +437,7 @@ export default function ResultScreen() {
437437
.create((record: any) => {
438438
record.userId = profileId;
439439
record.title = allItems[0] ?? "Hasil Scan";
440-
record.status = "Tersimpan";
440+
record.status = "Aktif";
441441
record.imageUri = result.imageUri;
442442
record.ratio = result.estimatedRatio || "-";
443443
record.progress = 10;
@@ -459,8 +459,8 @@ export default function ResultScreen() {
459459
record.carbonItems = result.carbonItems;
460460
record.nitrogenItems = result.nitrogenItems;
461461
record.estimatedRatio = result.estimatedRatio;
462-
record.aiInstruction = result.aiInstruction;
463-
record.createdAt = new Date().toISOString();
462+
record.aiInstruction = result.aiInstruction ?? "";
463+
record.createdAt = Date.now();
464464
});
465465

466466
await database
@@ -472,11 +472,17 @@ export default function ResultScreen() {
472472
"Hasil analisis ditambahkan dari halaman result.";
473473
record.isActive = true;
474474
record.timeLabel = new Date().toLocaleString("id-ID");
475-
record.createdAt = new Date().toISOString();
475+
record.createdAt = Date.now();
476476
});
477477
});
478478

479-
Alert.alert("Berhasil", "Progress berhasil disimpan.");
479+
Alert.alert("Berhasil", "Progress berhasil disimpan.", [
480+
{
481+
text: "Lihat Progress",
482+
onPress: () => router.replace("/(tabs)/progress"),
483+
},
484+
{ text: "OK", style: "cancel" },
485+
]);
480486
} catch (error) {
481487
const message =
482488
error instanceof Error ? error.message : "Terjadi kesalahan";

database/models/CompostActivity.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Model } from "@nozbe/watermelondb";
2-
import { field, relation, readonly, date } from "@nozbe/watermelondb/decorators";
2+
import { field, relation, date } from "@nozbe/watermelondb/decorators";
33

44
export class CompostActivity extends Model {
55
static table = "compost_activities";
@@ -9,7 +9,7 @@ export class CompostActivity extends Model {
99
@field("description") description!: string;
1010
@field("is_active") isActive!: boolean;
1111
@field("time_label") timeLabel!: string;
12-
@readonly @date("created_at") createdAt!: number;
12+
@date("created_at") createdAt!: number;
1313

1414
@relation("compost_batches", "batch_id") batch!: any;
1515
}

database/models/Profile.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { Model } from "@nozbe/watermelondb";
2-
import { field, readonly, date } from "@nozbe/watermelondb/decorators";
2+
import { field, date } from "@nozbe/watermelondb/decorators";
33

44
export class Profile extends Model {
55
static table = "profiles";
66

77
@field("full_name") fullName!: string;
88
@field("total_compost_kg") totalCompostKg!: number;
9-
@readonly @date("created_at") createdAt!: number;
9+
@date("created_at") createdAt!: number;
1010
}

database/models/Scan.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Model } from "@nozbe/watermelondb";
2-
import { field, json, relation, readonly, date } from "@nozbe/watermelondb/decorators";
2+
import { field, json, relation, date } from "@nozbe/watermelondb/decorators";
33

44
const sanitizeArray = (value: unknown) => (Array.isArray(value) ? value : []);
55

@@ -13,7 +13,7 @@ export class Scan extends Model {
1313
@json("nitrogen_items", sanitizeArray) nitrogenItems!: string[];
1414
@field("estimated_ratio") estimatedRatio!: string;
1515
@field("ai_instruction") aiInstruction!: string;
16-
@readonly @date("created_at") createdAt!: number;
16+
@date("created_at") createdAt!: number;
1717

1818
@relation("compost_batches", "batch_id") batch!: any;
1919
}

0 commit comments

Comments
 (0)