Compare commits
2 Commits
c02b61163d
...
c19cc7e00a
| Author | SHA1 | Date | |
|---|---|---|---|
| c19cc7e00a | |||
|
|
4d821646cf |
@@ -1,12 +1,32 @@
|
|||||||
import { Tabs } from "expo-router";
|
import { Tabs, useSegments } from "expo-router";
|
||||||
|
|
||||||
import { HapticTab } from "@/components/haptic-tab";
|
import { HapticTab } from "@/components/haptic-tab";
|
||||||
import { IconSymbol } from "@/components/ui/icon-symbol";
|
import { IconSymbol } from "@/components/ui/icon-symbol";
|
||||||
import { Colors } from "@/constants/theme";
|
import { Colors } from "@/constants/theme";
|
||||||
import { useColorScheme } from "@/hooks/use-color-scheme";
|
import { useColorScheme } from "@/hooks/use-color-scheme";
|
||||||
|
import { startEvents, stopEvents } from "@/services/device_events";
|
||||||
|
import { useEffect, useRef } from "react";
|
||||||
|
|
||||||
export default function TabLayout() {
|
export default function TabLayout() {
|
||||||
const colorScheme = useColorScheme();
|
const colorScheme = useColorScheme();
|
||||||
|
const segments = useSegments();
|
||||||
|
const prev = useRef<string | null>(null);
|
||||||
|
const currentSegment = segments[1] ?? segments[segments.length - 1] ?? null; // tuỳ cấu trúc của bạn
|
||||||
|
useEffect(() => {
|
||||||
|
if (prev.current !== currentSegment) {
|
||||||
|
// console.log("Tab changed ->", { from: prev.current, to: currentSegment });
|
||||||
|
// TODO: xử lý khi chuyển tab ở đây
|
||||||
|
if (prev.current === "(tabs)" && currentSegment !== "(tabs)") {
|
||||||
|
stopEvents();
|
||||||
|
// console.log("Stop events");
|
||||||
|
} else if (prev.current !== "(tabs)" && currentSegment === "(tabs)") {
|
||||||
|
// we came back into the tabs group — restart polling
|
||||||
|
startEvents();
|
||||||
|
// console.log("start events");
|
||||||
|
}
|
||||||
|
prev.current = currentSegment;
|
||||||
|
}
|
||||||
|
}, [currentSegment]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Tabs
|
<Tabs
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ export default function Warning() {
|
|||||||
<SafeAreaView style={{ flex: 1 }}>
|
<SafeAreaView style={{ flex: 1 }}>
|
||||||
<View style={styles.container}>
|
<View style={styles.container}>
|
||||||
<CreateOrUpdateHaulModal
|
<CreateOrUpdateHaulModal
|
||||||
haulData={null}
|
fishingLog={fishingLogData}
|
||||||
isVisible={isShowModal}
|
isVisible={isShowModal}
|
||||||
onClose={function (): void {
|
onClose={function (): void {
|
||||||
setIsShowModal(false);
|
setIsShowModal(false);
|
||||||
@@ -54,105 +54,118 @@ const styles = StyleSheet.create({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const fishingInfoDatas: Model.FishingLogInfo[] = [
|
const fishingLogData:Model.FishingLog = {
|
||||||
{
|
fishing_log_id: "124b2701-a5d6-4eb0-ba3b-6789473c14a9",
|
||||||
fish_species_id: 10,
|
trip_id: "d84caab6-ebb0-4cf7-abf9-31e5617d23b9",
|
||||||
fish_name: "Cá quỷ biển (Barracuda)",
|
start_at: "2025-11-07T10:50:01.693193764Z",
|
||||||
catch_number: 820,
|
end_at: "2025-11-07T10:50:31.693027729Z",
|
||||||
catch_unit: "kg",
|
start_lat: 11.59141,
|
||||||
fish_size: 29,
|
start_lon: 109.0489,
|
||||||
fish_rarity: 1,
|
haul_lat: 11.590274,
|
||||||
fish_condition: "Bị thương",
|
haul_lon: 109.049284,
|
||||||
gear_usage: "",
|
status: 1,
|
||||||
},
|
weather_description: "Stormy",
|
||||||
{
|
info: [
|
||||||
fish_species_id: 1,
|
{
|
||||||
fish_name: "Cá thu",
|
fish_species_id: 8,
|
||||||
catch_number: 1293,
|
fish_name: "Cá hồng phớn",
|
||||||
catch_unit: "kg",
|
catch_number: 1309,
|
||||||
fish_size: 37,
|
catch_unit: "kg",
|
||||||
fish_rarity: 1,
|
fish_size: 173,
|
||||||
fish_condition: "Bị thương",
|
fish_rarity: 3,
|
||||||
gear_usage: "",
|
fish_condition: "Còn sống",
|
||||||
},
|
gear_usage: "Câu vàng",
|
||||||
{
|
},
|
||||||
fish_species_id: 13,
|
{
|
||||||
fish_name: "Cá song đỏ",
|
fish_species_id: 18,
|
||||||
catch_number: 1738,
|
fish_name: "Cá đuối quạt",
|
||||||
catch_unit: "kg",
|
catch_number: 731,
|
||||||
fish_size: 28,
|
catch_unit: "kg",
|
||||||
fish_rarity: 2,
|
fish_size: 16,
|
||||||
fish_condition: "Còn sống",
|
fish_rarity: 4,
|
||||||
gear_usage: "",
|
fish_condition: "Chết",
|
||||||
},
|
gear_usage: "Bẫy lưới",
|
||||||
{
|
},
|
||||||
fish_species_id: 17,
|
{
|
||||||
fish_name: "Cá nược",
|
fish_species_id: 7,
|
||||||
catch_number: 690,
|
fish_name: "Cá bơn vàng",
|
||||||
catch_unit: "kg",
|
catch_number: 1224,
|
||||||
fish_size: 63,
|
catch_unit: "kg",
|
||||||
fish_rarity: 1,
|
fish_size: 12,
|
||||||
fish_condition: "Chết",
|
fish_rarity: 1,
|
||||||
gear_usage: "",
|
fish_condition: "Chết",
|
||||||
},
|
gear_usage: "",
|
||||||
{
|
},
|
||||||
fish_species_id: 19,
|
{
|
||||||
fish_name: "Cá hổ Thái Lan",
|
fish_species_id: 16,
|
||||||
catch_number: 825,
|
fish_name: "Cá rồng biển",
|
||||||
catch_unit: "kg",
|
catch_number: 838,
|
||||||
fish_size: 55,
|
catch_unit: "kg",
|
||||||
fish_rarity: 4,
|
fish_size: 164,
|
||||||
fish_condition: "Chết",
|
fish_rarity: 3,
|
||||||
gear_usage: "Câu tay",
|
fish_condition: "Chết",
|
||||||
},
|
gear_usage: "Lưới rê",
|
||||||
{
|
},
|
||||||
fish_species_id: 8,
|
{
|
||||||
fish_name: "Cá hồng phớn",
|
fish_species_id: 9,
|
||||||
catch_number: 1409,
|
fish_name: "Cá hổ Napoleon",
|
||||||
catch_unit: "kg",
|
catch_number: 1410,
|
||||||
fish_size: 172,
|
catch_unit: "kg",
|
||||||
fish_rarity: 3,
|
fish_size: 104,
|
||||||
fish_condition: "Chết",
|
fish_rarity: 4,
|
||||||
gear_usage: "Bẫy lưới",
|
fish_condition: "Bị thương",
|
||||||
},
|
gear_usage: "Câu vàng",
|
||||||
{
|
},
|
||||||
fish_species_id: 16,
|
{
|
||||||
fish_name: "Cá rồng biển",
|
fish_species_id: 3,
|
||||||
catch_number: 1426,
|
fish_name: "Cá chim trắng",
|
||||||
catch_unit: "kg",
|
catch_number: 1184,
|
||||||
fish_size: 105,
|
catch_unit: "kg",
|
||||||
fish_rarity: 3,
|
fish_size: 104,
|
||||||
fish_condition: "Chết",
|
fish_rarity: 2,
|
||||||
gear_usage: "Lưới rê",
|
fish_condition: "Còn sống",
|
||||||
},
|
gear_usage: "",
|
||||||
{
|
},
|
||||||
fish_species_id: 3,
|
{
|
||||||
fish_name: "Cá chim trắng",
|
fish_species_id: 5,
|
||||||
catch_number: 176,
|
fish_name: "Cá mú đỏ",
|
||||||
catch_unit: "kg",
|
catch_number: 987,
|
||||||
fish_size: 83,
|
catch_unit: "kg",
|
||||||
fish_rarity: 2,
|
fish_size: 171,
|
||||||
fish_condition: "Chết",
|
fish_rarity: 2,
|
||||||
gear_usage: "",
|
fish_condition: "Bị thương",
|
||||||
},
|
gear_usage: "",
|
||||||
{
|
},
|
||||||
fish_species_id: 14,
|
{
|
||||||
fish_name: "Cá mú cườm",
|
fish_species_id: 13,
|
||||||
catch_number: 724,
|
fish_name: "Cá song đỏ",
|
||||||
catch_unit: "kg",
|
catch_number: 1676,
|
||||||
fish_size: 36,
|
catch_unit: "kg",
|
||||||
fish_rarity: 2,
|
fish_size: 99,
|
||||||
fish_condition: "Chết",
|
fish_rarity: 2,
|
||||||
gear_usage: "",
|
fish_condition: "Bị thương",
|
||||||
},
|
gear_usage: "",
|
||||||
{
|
},
|
||||||
fish_species_id: 18,
|
{
|
||||||
fish_name: "Cá đuối quạt",
|
fish_species_id: 11,
|
||||||
catch_number: 1712,
|
fish_name: "Cá ngừ đại dương",
|
||||||
catch_unit: "kg",
|
catch_number: 462,
|
||||||
fish_size: 105,
|
catch_unit: "kg",
|
||||||
fish_rarity: 4,
|
fish_size: 11,
|
||||||
fish_condition: "Còn sống",
|
fish_rarity: 1,
|
||||||
gear_usage: "Câu vàng",
|
fish_condition: "Bị thương",
|
||||||
},
|
gear_usage: "",
|
||||||
];
|
},
|
||||||
|
{
|
||||||
|
fish_species_id: 2,
|
||||||
|
fish_name: "Cá nục",
|
||||||
|
catch_number: 496,
|
||||||
|
catch_unit: "kg",
|
||||||
|
fish_size: 125,
|
||||||
|
fish_rarity: 1,
|
||||||
|
fish_condition: "Còn sống",
|
||||||
|
gear_usage: "",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
sync: true,
|
||||||
|
};
|
||||||
|
|||||||
@@ -4,10 +4,27 @@ import { PolygonWithLabel } from "@/components/map/PolygonWithLabel";
|
|||||||
import type { PolylineWithLabelProps } from "@/components/map/PolylineWithLabel";
|
import type { PolylineWithLabelProps } from "@/components/map/PolylineWithLabel";
|
||||||
import { PolylineWithLabel } from "@/components/map/PolylineWithLabel";
|
import { PolylineWithLabel } from "@/components/map/PolylineWithLabel";
|
||||||
import SosButton from "@/components/map/SosButton";
|
import SosButton from "@/components/map/SosButton";
|
||||||
import { ENTITY, IOS_PLATFORM, LIGHT_THEME } from "@/constants";
|
import {
|
||||||
|
ENTITY,
|
||||||
|
EVENT_ALARM_DATA,
|
||||||
|
EVENT_BANZONE_DATA,
|
||||||
|
EVENT_ENTITY_DATA,
|
||||||
|
EVENT_GPS_DATA,
|
||||||
|
EVENT_TRACK_POINTS_DATA,
|
||||||
|
IOS_PLATFORM,
|
||||||
|
LIGHT_THEME,
|
||||||
|
} from "@/constants";
|
||||||
import { useColorScheme } from "@/hooks/use-color-scheme.web";
|
import { useColorScheme } from "@/hooks/use-color-scheme.web";
|
||||||
import { usePlatform } from "@/hooks/use-platform";
|
import { usePlatform } from "@/hooks/use-platform";
|
||||||
|
import {
|
||||||
|
getAlarmEventBus,
|
||||||
|
getBanzonesEventBus,
|
||||||
|
getEntitiesEventBus,
|
||||||
|
getGpsEventBus,
|
||||||
|
getTrackPointsEventBus,
|
||||||
|
} from "@/services/device_events";
|
||||||
import { getShipIcon } from "@/services/map_service";
|
import { getShipIcon } from "@/services/map_service";
|
||||||
|
import eventBus from "@/utils/eventBus";
|
||||||
import {
|
import {
|
||||||
convertWKTLineStringToLatLngArray,
|
convertWKTLineStringToLatLngArray,
|
||||||
convertWKTtoLatLngString,
|
convertWKTtoLatLngString,
|
||||||
@@ -39,74 +56,69 @@ export default function HomeScreen() {
|
|||||||
const scale = useRef(new Animated.Value(0)).current;
|
const scale = useRef(new Animated.Value(0)).current;
|
||||||
const opacity = useRef(new Animated.Value(1)).current;
|
const opacity = useRef(new Animated.Value(1)).current;
|
||||||
|
|
||||||
// console.log("Platform: ", platform);
|
useEffect(() => {
|
||||||
// console.log("Theme: ", theme);
|
getGpsEventBus();
|
||||||
|
getAlarmEventBus();
|
||||||
|
getEntitiesEventBus();
|
||||||
|
getBanzonesEventBus();
|
||||||
|
getTrackPointsEventBus();
|
||||||
|
const queryGpsData = (gpsData: Model.GPSResponse) => {
|
||||||
|
if (gpsData) {
|
||||||
|
// console.log("GPS Data: ", gpsData);
|
||||||
|
setGpsData(gpsData);
|
||||||
|
} else {
|
||||||
|
setGpsData(null);
|
||||||
|
setPolygonCoordinates([]);
|
||||||
|
setPolylineCoordinates(null);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const queryAlarmData = (alarmData: Model.AlarmResponse) => {
|
||||||
|
// console.log("Alarm Data: ", alarmData.alarms.length);
|
||||||
|
setAlarmData(alarmData);
|
||||||
|
};
|
||||||
|
const queryEntityData = (entityData: Model.TransformedEntity[]) => {
|
||||||
|
// console.log("Entities Length Data: ", entityData.length);
|
||||||
|
setEntityData(entityData);
|
||||||
|
};
|
||||||
|
const queryBanzonesData = (banzoneData: Model.Zone[]) => {
|
||||||
|
// console.log("Banzone Data: ", banzoneData.length);
|
||||||
|
|
||||||
// const [number, setNumber] = useState(0);
|
setBanzoneData(banzoneData);
|
||||||
|
};
|
||||||
|
const queryTrackPointsData = (TrackPointsData: Model.ShipTrackPoint[]) => {
|
||||||
|
// console.log("TrackPoints Data: ", TrackPointsData.length);
|
||||||
|
if (TrackPointsData && TrackPointsData.length > 0) {
|
||||||
|
setTrackPointsData(TrackPointsData);
|
||||||
|
} else {
|
||||||
|
setTrackPointsData(null);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// useEffect(() => {
|
eventBus.on(EVENT_GPS_DATA, queryGpsData);
|
||||||
// getGpsEventBus();
|
// console.log("Registering event handlers in HomeScreen");
|
||||||
// getAlarmEventBus();
|
eventBus.on(EVENT_GPS_DATA, queryGpsData);
|
||||||
// getEntitiesEventBus();
|
// console.log("Subscribed to EVENT_GPS_DATA");
|
||||||
// getBanzonesEventBus();
|
eventBus.on(EVENT_ALARM_DATA, queryAlarmData);
|
||||||
// getTrackPointsEventBus();
|
// console.log("Subscribed to EVENT_ALARM_DATA");
|
||||||
// const queryGpsData = (gpsData: Model.GPSResponse) => {
|
eventBus.on(EVENT_ENTITY_DATA, queryEntityData);
|
||||||
// if (gpsData) {
|
// console.log("Subscribed to EVENT_ENTITY_DATA");
|
||||||
// // console.log("GPS Data: ", gpsData);
|
eventBus.on(EVENT_TRACK_POINTS_DATA, queryTrackPointsData);
|
||||||
// setGpsData(gpsData);
|
// console.log("Subscribed to EVENT_TRACK_POINTS_DATA");
|
||||||
// } else {
|
eventBus.once(EVENT_BANZONE_DATA, queryBanzonesData);
|
||||||
// setGpsData(null);
|
// console.log("Subscribed once to EVENT_BANZONE_DATA");
|
||||||
// setPolygonCoordinates([]);
|
|
||||||
// setPolylineCoordinates(null);
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
// const queryAlarmData = (alarmData: Model.AlarmResponse) => {
|
|
||||||
// // console.log("Alarm Data: ", alarmData.alarms.length);
|
|
||||||
// setAlarmData(alarmData);
|
|
||||||
// };
|
|
||||||
// const queryEntityData = (entityData: Model.TransformedEntity[]) => {
|
|
||||||
// // console.log("Entities Length Data: ", entityData.length);
|
|
||||||
// setEntityData(entityData);
|
|
||||||
// };
|
|
||||||
// const queryBanzonesData = (banzoneData: Model.Zone[]) => {
|
|
||||||
// // console.log("Banzone Data: ", banzoneData.length);
|
|
||||||
|
|
||||||
// setBanzoneData(banzoneData);
|
return () => {
|
||||||
// };
|
// console.log("Unregistering event handlers in HomeScreen");
|
||||||
// const queryTrackPointsData = (TrackPointsData: Model.ShipTrackPoint[]) => {
|
eventBus.off(EVENT_GPS_DATA, queryGpsData);
|
||||||
// // console.log("TrackPoints Data: ", TrackPointsData.length);
|
// console.log("Unsubscribed EVENT_GPS_DATA");
|
||||||
// if (TrackPointsData && TrackPointsData.length > 0) {
|
eventBus.off(EVENT_ALARM_DATA, queryAlarmData);
|
||||||
// setTrackPointsData(TrackPointsData);
|
// console.log("Unsubscribed EVENT_ALARM_DATA");
|
||||||
// } else {
|
eventBus.off(EVENT_ENTITY_DATA, queryEntityData);
|
||||||
// setTrackPointsData(null);
|
// console.log("Unsubscribed EVENT_ENTITY_DATA");
|
||||||
// }
|
eventBus.off(EVENT_TRACK_POINTS_DATA, queryTrackPointsData);
|
||||||
// };
|
// console.log("Unsubscribed EVENT_TRACK_POINTS_DATA");
|
||||||
|
};
|
||||||
// eventBus.on(EVENT_GPS_DATA, queryGpsData);
|
}, []);
|
||||||
// // console.log("Registering event handlers in HomeScreen");
|
|
||||||
// eventBus.on(EVENT_GPS_DATA, queryGpsData);
|
|
||||||
// // console.log("Subscribed to EVENT_GPS_DATA");
|
|
||||||
// eventBus.on(EVENT_ALARM_DATA, queryAlarmData);
|
|
||||||
// // console.log("Subscribed to EVENT_ALARM_DATA");
|
|
||||||
// eventBus.on(EVENT_ENTITY_DATA, queryEntityData);
|
|
||||||
// // console.log("Subscribed to EVENT_ENTITY_DATA");
|
|
||||||
// eventBus.on(EVENT_TRACK_POINTS_DATA, queryTrackPointsData);
|
|
||||||
// // console.log("Subscribed to EVENT_TRACK_POINTS_DATA");
|
|
||||||
// eventBus.once(EVENT_BANZONE_DATA, queryBanzonesData);
|
|
||||||
// // console.log("Subscribed once to EVENT_BANZONE_DATA");
|
|
||||||
|
|
||||||
// return () => {
|
|
||||||
// // console.log("Unregistering event handlers in HomeScreen");
|
|
||||||
// eventBus.off(EVENT_GPS_DATA, queryGpsData);
|
|
||||||
// // console.log("Unsubscribed EVENT_GPS_DATA");
|
|
||||||
// eventBus.off(EVENT_ALARM_DATA, queryAlarmData);
|
|
||||||
// // console.log("Unsubscribed EVENT_ALARM_DATA");
|
|
||||||
// eventBus.off(EVENT_ENTITY_DATA, queryEntityData);
|
|
||||||
// // console.log("Unsubscribed EVENT_ENTITY_DATA");
|
|
||||||
// eventBus.off(EVENT_TRACK_POINTS_DATA, queryTrackPointsData);
|
|
||||||
// // console.log("Unsubscribed EVENT_TRACK_POINTS_DATA");
|
|
||||||
// };
|
|
||||||
// }, []);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setPolylineCoordinates(null);
|
setPolylineCoordinates(null);
|
||||||
@@ -162,7 +174,7 @@ export default function HomeScreen() {
|
|||||||
// foundPolygon = true;
|
// foundPolygon = true;
|
||||||
const coordinates = convertWKTtoLatLngString(geom_poly || "");
|
const coordinates = convertWKTtoLatLngString(geom_poly || "");
|
||||||
if (coordinates.length > 0) {
|
if (coordinates.length > 0) {
|
||||||
console.log("Polygon Coordinate: ", coordinates);
|
// console.log("Polygon Coordinate: ", coordinates);
|
||||||
setPolygonCoordinates(
|
setPolygonCoordinates(
|
||||||
coordinates.map((polygon) => ({
|
coordinates.map((polygon) => ({
|
||||||
coordinates: polygon.map((coord) => ({
|
coordinates: polygon.map((coord) => ({
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ const ButtonCreateNewHaulOrTrip: React.FC<StartButtonProps> = ({
|
|||||||
});
|
});
|
||||||
if (resp.status === 200) {
|
if (resp.status === 200) {
|
||||||
showSuccessToast("Bắt đầu chuyến đi thành công!");
|
showSuccessToast("Bắt đầu chuyến đi thành công!");
|
||||||
getTrip();
|
await getTrip();
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error stating trip :", error);
|
console.error("Error stating trip :", error);
|
||||||
@@ -125,7 +125,7 @@ const ButtonCreateNewHaulOrTrip: React.FC<StartButtonProps> = ({
|
|||||||
const resp = await queryStartNewHaul(body);
|
const resp = await queryStartNewHaul(body);
|
||||||
if (resp.status === 200) {
|
if (resp.status === 200) {
|
||||||
showSuccessToast("Bắt đầu mẻ lưới mới thành công!");
|
showSuccessToast("Bắt đầu mẻ lưới mới thành công!");
|
||||||
getTrip();
|
await getTrip();
|
||||||
} else {
|
} else {
|
||||||
showErrorToast("Tạo mẻ lưới mới thất bại!");
|
showErrorToast("Tạo mẻ lưới mới thất bại!");
|
||||||
}
|
}
|
||||||
@@ -173,7 +173,8 @@ const ButtonCreateNewHaulOrTrip: React.FC<StartButtonProps> = ({
|
|||||||
</IconButton>
|
</IconButton>
|
||||||
)}
|
)}
|
||||||
<CreateOrUpdateHaulModal
|
<CreateOrUpdateHaulModal
|
||||||
haulData={null}
|
fishingLog={trip?.fishing_logs?.find((f) => f.status === 0)!}
|
||||||
|
fishingLogIndex={trip?.fishing_logs?.length!}
|
||||||
isVisible={isFinishHaulModalOpen}
|
isVisible={isFinishHaulModalOpen}
|
||||||
onClose={function (): void {
|
onClose={function (): void {
|
||||||
setIsFinishHaulModalOpen(false);
|
setIsFinishHaulModalOpen(false);
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { useFishes } from "@/state/use-fish";
|
|||||||
import { useTrip } from "@/state/use-trip";
|
import { useTrip } from "@/state/use-trip";
|
||||||
import React, { useEffect, useRef, useState } from "react";
|
import React, { useEffect, useRef, useState } from "react";
|
||||||
import { Animated, Text, TouchableOpacity, View } from "react-native";
|
import { Animated, Text, TouchableOpacity, View } from "react-native";
|
||||||
import NetDetailModal from "./modal/NetDetailModal/NetDetailModal";
|
import CreateOrUpdateHaulModal from "./modal/CreateOrUpdateHaulModal";
|
||||||
import styles from "./style/NetListTable.styles";
|
import styles from "./style/NetListTable.styles";
|
||||||
|
|
||||||
const NetListTable: React.FC = () => {
|
const NetListTable: React.FC = () => {
|
||||||
@@ -17,8 +17,11 @@ const NetListTable: React.FC = () => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getFishSpecies();
|
getFishSpecies();
|
||||||
}, []);
|
}, []);
|
||||||
const data: Model.FishingLog[] = trip?.fishing_logs ?? [];
|
|
||||||
const tongSoMe = data.length;
|
// useEffect(() => {
|
||||||
|
// console.log("Trip thay đổi: ", trip?.fishing_logs?.length);
|
||||||
|
// }, [trip]);
|
||||||
|
// const data: Model.FishingLog[] = trip?.fishing_logs ?? [];
|
||||||
|
|
||||||
const handleToggle = () => {
|
const handleToggle = () => {
|
||||||
const toValue = collapsed ? contentHeight : 0;
|
const toValue = collapsed ? contentHeight : 0;
|
||||||
@@ -31,7 +34,7 @@ const NetListTable: React.FC = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleStatusPress = (id: string) => {
|
const handleStatusPress = (id: string) => {
|
||||||
const net = data.find((item) => item.fishing_log_id === id);
|
const net = trip?.fishing_logs?.find((item) => item.fishing_log_id === id);
|
||||||
if (net) {
|
if (net) {
|
||||||
setSelectedNet(net);
|
setSelectedNet(net);
|
||||||
setModalVisible(true);
|
setModalVisible(true);
|
||||||
@@ -47,7 +50,11 @@ const NetListTable: React.FC = () => {
|
|||||||
style={styles.headerRow}
|
style={styles.headerRow}
|
||||||
>
|
>
|
||||||
<Text style={styles.title}>Danh sách mẻ lưới</Text>
|
<Text style={styles.title}>Danh sách mẻ lưới</Text>
|
||||||
{collapsed && <Text style={styles.totalCollapsed}>{tongSoMe}</Text>}
|
{collapsed && (
|
||||||
|
<Text style={styles.totalCollapsed}>
|
||||||
|
{trip?.fishing_logs?.length}
|
||||||
|
</Text>
|
||||||
|
)}
|
||||||
<IconSymbol
|
<IconSymbol
|
||||||
name={collapsed ? "chevron.down" : "chevron.up"}
|
name={collapsed ? "chevron.down" : "chevron.up"}
|
||||||
size={16}
|
size={16}
|
||||||
@@ -60,8 +67,18 @@ const NetListTable: React.FC = () => {
|
|||||||
style={{ position: "absolute", opacity: 0, zIndex: -1000 }}
|
style={{ position: "absolute", opacity: 0, zIndex: -1000 }}
|
||||||
onLayout={(event) => {
|
onLayout={(event) => {
|
||||||
const height = event.nativeEvent.layout.height;
|
const height = event.nativeEvent.layout.height;
|
||||||
if (height > 0 && contentHeight === 0) {
|
// Update measured content height whenever it actually changes.
|
||||||
|
if (height > 0 && height !== contentHeight) {
|
||||||
setContentHeight(height);
|
setContentHeight(height);
|
||||||
|
// If the panel is currently expanded, animate to the new height so
|
||||||
|
// newly added/removed rows become visible immediately.
|
||||||
|
if (!collapsed) {
|
||||||
|
Animated.timing(animatedHeight, {
|
||||||
|
toValue: height,
|
||||||
|
duration: 200,
|
||||||
|
useNativeDriver: false,
|
||||||
|
}).start();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
@@ -72,7 +89,7 @@ const NetListTable: React.FC = () => {
|
|||||||
</View>
|
</View>
|
||||||
|
|
||||||
{/* Body */}
|
{/* Body */}
|
||||||
{data.map((item, index) => (
|
{trip?.fishing_logs?.map((item, index) => (
|
||||||
<View key={item.fishing_log_id} style={styles.row}>
|
<View key={item.fishing_log_id} style={styles.row}>
|
||||||
{/* Cột STT */}
|
{/* Cột STT */}
|
||||||
<Text style={styles.sttCell}>Mẻ {index + 1}</Text>
|
<Text style={styles.sttCell}>Mẻ {index + 1}</Text>
|
||||||
@@ -101,7 +118,7 @@ const NetListTable: React.FC = () => {
|
|||||||
</View>
|
</View>
|
||||||
|
|
||||||
{/* Body */}
|
{/* Body */}
|
||||||
{data.map((item, index) => (
|
{trip?.fishing_logs?.map((item, index) => (
|
||||||
<View key={item.fishing_log_id} style={styles.row}>
|
<View key={item.fishing_log_id} style={styles.row}>
|
||||||
{/* Cột STT */}
|
{/* Cột STT */}
|
||||||
<Text style={styles.sttCell}>Mẻ {index + 1}</Text>
|
<Text style={styles.sttCell}>Mẻ {index + 1}</Text>
|
||||||
@@ -120,23 +137,30 @@ const NetListTable: React.FC = () => {
|
|||||||
</View>
|
</View>
|
||||||
))}
|
))}
|
||||||
</Animated.View>
|
</Animated.View>
|
||||||
|
<CreateOrUpdateHaulModal
|
||||||
|
isVisible={modalVisible}
|
||||||
|
onClose={() => {
|
||||||
|
console.log("OnCLose");
|
||||||
|
setModalVisible(false);
|
||||||
|
}}
|
||||||
|
fishingLog={selectedNet}
|
||||||
|
fishingLogIndex={
|
||||||
|
selectedNet
|
||||||
|
? trip!.fishing_logs!.findIndex(
|
||||||
|
(item) => item.fishing_log_id === selectedNet.fishing_log_id
|
||||||
|
) + 1
|
||||||
|
: undefined
|
||||||
|
}
|
||||||
|
/>
|
||||||
{/* Modal chi tiết */}
|
{/* Modal chi tiết */}
|
||||||
<NetDetailModal
|
{/* <NetDetailModal
|
||||||
visible={modalVisible}
|
visible={modalVisible}
|
||||||
onClose={() => {
|
onClose={() => {
|
||||||
console.log("OnCLose");
|
console.log("OnCLose");
|
||||||
setModalVisible(false);
|
setModalVisible(false);
|
||||||
}}
|
}}
|
||||||
netData={selectedNet}
|
netData={selectedNet}
|
||||||
stt={
|
/> */}
|
||||||
selectedNet
|
|
||||||
? data.findIndex(
|
|
||||||
(item) => item.fishing_log_id === selectedNet.fishing_log_id
|
|
||||||
) + 1
|
|
||||||
: undefined
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,15 +1,26 @@
|
|||||||
import Select from "@/components/Select";
|
import Select from "@/components/Select";
|
||||||
|
import { IconSymbol } from "@/components/ui/icon-symbol";
|
||||||
import { useFishes } from "@/state/use-fish";
|
import { useFishes } from "@/state/use-fish";
|
||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { Controller, useFieldArray, useForm } from "react-hook-form";
|
import { Controller, useFieldArray, useForm } from "react-hook-form";
|
||||||
import { Button, FlatList, Modal, Text, TextInput, View } from "react-native";
|
import {
|
||||||
|
Modal,
|
||||||
|
ScrollView,
|
||||||
|
Text,
|
||||||
|
TextInput,
|
||||||
|
TouchableOpacity,
|
||||||
|
View,
|
||||||
|
} from "react-native";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
import { InfoSection } from "./NetDetailModal/components";
|
||||||
|
import styles from "./style/CreateOrUpdateHaulModal.styles";
|
||||||
|
|
||||||
interface CreateOrUpdateHaulModalProps {
|
interface CreateOrUpdateHaulModalProps {
|
||||||
isVisible: boolean;
|
isVisible: boolean;
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
haulData?: Model.FishingLogInfo[] | null;
|
fishingLog?: Model.FishingLog | null;
|
||||||
|
fishingLogIndex?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
const UNITS = ["con", "kg", "tấn"] as const;
|
const UNITS = ["con", "kg", "tấn"] as const;
|
||||||
@@ -49,9 +60,14 @@ const defaultItem = (): FormValues["fish"][number] => ({
|
|||||||
const CreateOrUpdateHaulModal: React.FC<CreateOrUpdateHaulModalProps> = ({
|
const CreateOrUpdateHaulModal: React.FC<CreateOrUpdateHaulModalProps> = ({
|
||||||
isVisible,
|
isVisible,
|
||||||
onClose,
|
onClose,
|
||||||
haulData,
|
fishingLog,
|
||||||
|
fishingLogIndex,
|
||||||
}) => {
|
}) => {
|
||||||
const [isCreateMode, setIsCreateMode] = React.useState(!haulData);
|
const [isCreateMode, setIsCreateMode] = React.useState(!fishingLog?.info);
|
||||||
|
const [isEditing, setIsEditing] = React.useState(false);
|
||||||
|
const [expandedFishIndices, setExpandedFishIndices] = React.useState<
|
||||||
|
number[]
|
||||||
|
>([]);
|
||||||
const { control, handleSubmit, formState, watch, reset } =
|
const { control, handleSubmit, formState, watch, reset } =
|
||||||
useForm<FormValues>({
|
useForm<FormValues>({
|
||||||
resolver: zodResolver(formSchema),
|
resolver: zodResolver(formSchema),
|
||||||
@@ -71,6 +87,12 @@ const CreateOrUpdateHaulModal: React.FC<CreateOrUpdateHaulModalProps> = ({
|
|||||||
keyName: "_id", // tránh đụng key
|
keyName: "_id", // tránh đụng key
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const handleToggleExpanded = (index: number) => {
|
||||||
|
setExpandedFishIndices((prev) =>
|
||||||
|
prev.includes(index) ? prev.filter((i) => i !== index) : [...prev, index]
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const onSubmit = (values: FormValues) => {
|
const onSubmit = (values: FormValues) => {
|
||||||
// Map form values to the FishingLogInfo-like shape the user requested
|
// Map form values to the FishingLogInfo-like shape the user requested
|
||||||
const mapped = values.fish.map((f) => {
|
const mapped = values.fish.map((f) => {
|
||||||
@@ -99,17 +121,21 @@ const CreateOrUpdateHaulModal: React.FC<CreateOrUpdateHaulModalProps> = ({
|
|||||||
// when modal closed, clear form to default
|
// when modal closed, clear form to default
|
||||||
reset({ fish: [defaultItem()] });
|
reset({ fish: [defaultItem()] });
|
||||||
setIsCreateMode(true);
|
setIsCreateMode(true);
|
||||||
|
setIsEditing(false);
|
||||||
|
setExpandedFishIndices([]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// when modal opened, populate based on haulData
|
// when modal opened, populate based on fishingLog
|
||||||
if (haulData === null) {
|
if (fishingLog?.info === null) {
|
||||||
// explicit null -> start with a single default item
|
// explicit null -> start with a single default item
|
||||||
reset({ fish: [defaultItem()] });
|
reset({ fish: [defaultItem()] });
|
||||||
setIsCreateMode(true);
|
setIsCreateMode(true);
|
||||||
} else if (Array.isArray(haulData) && haulData.length > 0) {
|
setIsEditing(true); // allow editing for new haul
|
||||||
|
setExpandedFishIndices([0]); // expand first item
|
||||||
|
} else if (Array.isArray(fishingLog?.info) && fishingLog?.info.length > 0) {
|
||||||
// map FishingLogInfo -> form rows
|
// map FishingLogInfo -> form rows
|
||||||
const mapped = haulData.map((h) => ({
|
const mapped = fishingLog.info.map((h) => ({
|
||||||
id: h.fish_species_id ?? -1,
|
id: h.fish_species_id ?? -1,
|
||||||
quantity: (h.catch_number as number) ?? 1,
|
quantity: (h.catch_number as number) ?? 1,
|
||||||
unit: (h.catch_unit as Unit) ?? (defaultItem().unit as Unit),
|
unit: (h.catch_unit as Unit) ?? (defaultItem().unit as Unit),
|
||||||
@@ -117,132 +143,212 @@ const CreateOrUpdateHaulModal: React.FC<CreateOrUpdateHaulModalProps> = ({
|
|||||||
}));
|
}));
|
||||||
reset({ fish: mapped as any });
|
reset({ fish: mapped as any });
|
||||||
setIsCreateMode(false);
|
setIsCreateMode(false);
|
||||||
|
setIsEditing(false); // view mode by default
|
||||||
|
setExpandedFishIndices([]); // all collapsed
|
||||||
} else {
|
} else {
|
||||||
// undefined or empty array -> default
|
// undefined or empty array -> default
|
||||||
reset({ fish: [defaultItem()] });
|
reset({ fish: [defaultItem()] });
|
||||||
setIsCreateMode(true);
|
setIsCreateMode(true);
|
||||||
|
setIsEditing(true); // allow editing for new haul
|
||||||
|
setExpandedFishIndices([0]); // expand first item
|
||||||
}
|
}
|
||||||
}, [isVisible, haulData, reset]);
|
}, [isVisible, fishingLog?.info, reset]);
|
||||||
const renderRow = ({ item, index }: { item: any; index: number }) => {
|
const renderRow = (item: any, index: number) => {
|
||||||
|
const isExpanded = expandedFishIndices.includes(index);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View
|
<View key={item._id} style={styles.fishCard}>
|
||||||
style={{
|
{/* Delete + Chevron buttons - top right corner */}
|
||||||
marginBottom: 12,
|
<View
|
||||||
padding: 12,
|
style={{
|
||||||
borderWidth: 1,
|
position: "absolute",
|
||||||
borderRadius: 8,
|
top: 0,
|
||||||
}}
|
right: 0,
|
||||||
>
|
zIndex: 9999,
|
||||||
<Text style={{ fontWeight: "600", marginBottom: 8 }}>
|
flexDirection: "row",
|
||||||
Loài cá #{index + 1}
|
alignItems: "center",
|
||||||
</Text>
|
padding: 8,
|
||||||
|
gap: 8,
|
||||||
{/* Species dropdown */}
|
}}
|
||||||
<Controller
|
pointerEvents="box-none"
|
||||||
control={control}
|
>
|
||||||
name={`fish.${index}.id`}
|
{isEditing && (
|
||||||
render={({ field: { value, onChange } }) => (
|
<TouchableOpacity
|
||||||
<View style={{ marginBottom: 8 }}>
|
onPress={() => remove(index)}
|
||||||
<Text style={{ marginBottom: 4 }}>Tên cá</Text>
|
style={{
|
||||||
<Select
|
backgroundColor: "#FF3B30",
|
||||||
options={fishSpecies!.map((fish) => ({
|
borderRadius: 8,
|
||||||
label: fish.name,
|
width: 40,
|
||||||
value: fish.id,
|
height: 40,
|
||||||
}))}
|
justifyContent: "center",
|
||||||
value={value}
|
alignItems: "center",
|
||||||
onChange={onChange}
|
shadowColor: "#000",
|
||||||
placeholder="Chọn loài cá"
|
shadowOpacity: 0.08,
|
||||||
/>
|
shadowRadius: 2,
|
||||||
{errors.fish?.[index]?.id && (
|
shadowOffset: { width: 0, height: 1 },
|
||||||
<Text style={{ color: "red" }}>
|
elevation: 2,
|
||||||
{errors.fish[index]?.id?.message as string}
|
}}
|
||||||
</Text>
|
hitSlop={{ top: 12, bottom: 12, left: 12, right: 12 }}
|
||||||
)}
|
activeOpacity={0.7}
|
||||||
</View>
|
>
|
||||||
|
<IconSymbol name="trash" size={24} color="#fff" />
|
||||||
|
</TouchableOpacity>
|
||||||
)}
|
)}
|
||||||
/>
|
<TouchableOpacity
|
||||||
|
onPress={() => handleToggleExpanded(index)}
|
||||||
{/* Quantity */}
|
style={{
|
||||||
<Controller
|
backgroundColor: "#007AFF",
|
||||||
control={control}
|
borderRadius: 8,
|
||||||
name={`fish.${index}.quantity`}
|
width: 40,
|
||||||
render={({ field: { value, onChange, onBlur } }) => (
|
height: 40,
|
||||||
<View style={{ marginBottom: 8 }}>
|
justifyContent: "center",
|
||||||
<Text style={{ marginBottom: 4 }}>Số lượng</Text>
|
alignItems: "center",
|
||||||
<TextInput
|
shadowColor: "#000",
|
||||||
keyboardType="numeric"
|
shadowOpacity: 0.08,
|
||||||
value={String(value ?? "")}
|
shadowRadius: 2,
|
||||||
onBlur={onBlur}
|
shadowOffset: { width: 0, height: 1 },
|
||||||
onChangeText={(t) =>
|
elevation: 2,
|
||||||
onChange(Number(t.replace(/,/g, ".")) || 0)
|
}}
|
||||||
}
|
hitSlop={{ top: 12, bottom: 12, left: 12, right: 12 }}
|
||||||
style={{ padding: 10, borderWidth: 1, borderRadius: 6 }}
|
activeOpacity={0.7}
|
||||||
/>
|
>
|
||||||
{errors.fish?.[index]?.quantity && (
|
<IconSymbol
|
||||||
<Text style={{ color: "red" }}>
|
name={isExpanded ? "chevron.up" : "chevron.down"}
|
||||||
{errors.fish[index]?.quantity?.message as string}
|
size={24}
|
||||||
</Text>
|
color="#fff"
|
||||||
)}
|
/>
|
||||||
</View>
|
</TouchableOpacity>
|
||||||
)}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{/* Unit dropdown */}
|
|
||||||
<Controller
|
|
||||||
control={control}
|
|
||||||
name={`fish.${index}.unit`}
|
|
||||||
render={({ field: { value, onChange } }) => (
|
|
||||||
<View style={{ marginBottom: 8 }}>
|
|
||||||
<Text style={{ marginBottom: 4 }}>Đơn vị</Text>
|
|
||||||
<Select
|
|
||||||
options={UNITS_OPTIONS.map((unit) => ({
|
|
||||||
label: unit.label,
|
|
||||||
value: unit.value,
|
|
||||||
}))}
|
|
||||||
value={value}
|
|
||||||
onChange={onChange}
|
|
||||||
placeholder="Chọn đơn vị"
|
|
||||||
/>
|
|
||||||
{errors.fish?.[index]?.unit && (
|
|
||||||
<Text style={{ color: "red" }}>
|
|
||||||
{errors.fish[index]?.unit?.message as string}
|
|
||||||
</Text>
|
|
||||||
)}
|
|
||||||
</View>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{/* Size (optional) */}
|
|
||||||
<Controller
|
|
||||||
control={control}
|
|
||||||
name={`fish.${index}.size`}
|
|
||||||
render={({ field: { value, onChange, onBlur } }) => (
|
|
||||||
<View style={{ marginBottom: 8 }}>
|
|
||||||
<Text style={{ marginBottom: 4 }}>
|
|
||||||
Kích thước (cm) — tùy chọn
|
|
||||||
</Text>
|
|
||||||
<TextInput
|
|
||||||
keyboardType="numeric"
|
|
||||||
value={value ? String(value) : ""}
|
|
||||||
onBlur={onBlur}
|
|
||||||
onChangeText={(t) =>
|
|
||||||
onChange(t ? Number(t.replace(/,/g, ".")) : undefined)
|
|
||||||
}
|
|
||||||
style={{ padding: 10, borderWidth: 1, borderRadius: 6 }}
|
|
||||||
/>
|
|
||||||
{errors.fish?.[index]?.size && (
|
|
||||||
<Text style={{ color: "red" }}>
|
|
||||||
{errors.fish[index]?.size?.message as string}
|
|
||||||
</Text>
|
|
||||||
)}
|
|
||||||
</View>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{/* Remove row */}
|
|
||||||
<View style={{ flexDirection: "row", justifyContent: "flex-end" }}>
|
|
||||||
<Button title="Xóa loài này" onPress={() => remove(index)} />
|
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
|
{/* Header - visible when collapsed */}
|
||||||
|
{!isExpanded && (
|
||||||
|
<View style={{ paddingRight: 100 }}>
|
||||||
|
{(() => {
|
||||||
|
const fishId = watch(`fish.${index}.id`);
|
||||||
|
const fishName = fishSpecies?.find((f) => f.id === fishId)?.name;
|
||||||
|
const quantity = watch(`fish.${index}.quantity`);
|
||||||
|
const unit = watch(`fish.${index}.unit`);
|
||||||
|
|
||||||
|
return fishName ? (
|
||||||
|
<View style={styles.fishCardHeaderContent}>
|
||||||
|
<Text style={styles.fishCardTitle}>{fishName}:</Text>
|
||||||
|
<Text style={styles.fishCardSubtitle}>
|
||||||
|
{quantity} {unit}
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
|
) : null;
|
||||||
|
})()}
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Form - visible when expanded */}
|
||||||
|
{isExpanded && (
|
||||||
|
<View style={{ paddingRight: 100 }}>
|
||||||
|
{/* Species dropdown */}
|
||||||
|
<Controller
|
||||||
|
control={control}
|
||||||
|
name={`fish.${index}.id`}
|
||||||
|
render={({ field: { value, onChange } }) => (
|
||||||
|
<View style={styles.fieldGroup}>
|
||||||
|
<Text style={styles.label}>Tên cá</Text>
|
||||||
|
<Select
|
||||||
|
options={fishSpecies!.map((fish) => ({
|
||||||
|
label: fish.name,
|
||||||
|
value: fish.id,
|
||||||
|
}))}
|
||||||
|
value={value}
|
||||||
|
onChange={onChange}
|
||||||
|
placeholder="Chọn loài cá"
|
||||||
|
disabled={!isEditing}
|
||||||
|
/>
|
||||||
|
{errors.fish?.[index]?.id && (
|
||||||
|
<Text style={styles.errorText}>
|
||||||
|
{errors.fish[index]?.id?.message as string}
|
||||||
|
</Text>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* Quantity */}
|
||||||
|
<Controller
|
||||||
|
control={control}
|
||||||
|
name={`fish.${index}.quantity`}
|
||||||
|
render={({ field: { value, onChange, onBlur } }) => (
|
||||||
|
<View style={styles.fieldGroup}>
|
||||||
|
<Text style={styles.label}>Số lượng</Text>
|
||||||
|
<TextInput
|
||||||
|
keyboardType="numeric"
|
||||||
|
value={String(value ?? "")}
|
||||||
|
onBlur={onBlur}
|
||||||
|
onChangeText={(t) =>
|
||||||
|
onChange(Number(t.replace(/,/g, ".")) || 0)
|
||||||
|
}
|
||||||
|
style={[styles.input, !isEditing && styles.inputDisabled]}
|
||||||
|
editable={isEditing}
|
||||||
|
/>
|
||||||
|
{errors.fish?.[index]?.quantity && (
|
||||||
|
<Text style={styles.errorText}>
|
||||||
|
{errors.fish[index]?.quantity?.message as string}
|
||||||
|
</Text>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* Unit dropdown */}
|
||||||
|
<Controller
|
||||||
|
control={control}
|
||||||
|
name={`fish.${index}.unit`}
|
||||||
|
render={({ field: { value, onChange } }) => (
|
||||||
|
<View style={styles.fieldGroup}>
|
||||||
|
<Text style={styles.label}>Đơn vị</Text>
|
||||||
|
<Select
|
||||||
|
options={UNITS_OPTIONS.map((unit) => ({
|
||||||
|
label: unit.label,
|
||||||
|
value: unit.value,
|
||||||
|
}))}
|
||||||
|
value={value}
|
||||||
|
onChange={onChange}
|
||||||
|
placeholder="Chọn đơn vị"
|
||||||
|
disabled={!isEditing}
|
||||||
|
/>
|
||||||
|
{errors.fish?.[index]?.unit && (
|
||||||
|
<Text style={styles.errorText}>
|
||||||
|
{errors.fish[index]?.unit?.message as string}
|
||||||
|
</Text>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* Size (optional) */}
|
||||||
|
<Controller
|
||||||
|
control={control}
|
||||||
|
name={`fish.${index}.size`}
|
||||||
|
render={({ field: { value, onChange, onBlur } }) => (
|
||||||
|
<View style={styles.fieldGroup}>
|
||||||
|
<Text style={styles.label}>Kích thước (cm) — tùy chọn</Text>
|
||||||
|
<TextInput
|
||||||
|
keyboardType="numeric"
|
||||||
|
value={value ? String(value) : ""}
|
||||||
|
onBlur={onBlur}
|
||||||
|
onChangeText={(t) =>
|
||||||
|
onChange(t ? Number(t.replace(/,/g, ".")) : undefined)
|
||||||
|
}
|
||||||
|
style={[styles.input, !isEditing && styles.inputDisabled]}
|
||||||
|
editable={isEditing}
|
||||||
|
/>
|
||||||
|
{errors.fish?.[index]?.size && (
|
||||||
|
<Text style={styles.errorText}>
|
||||||
|
{errors.fish[index]?.size?.message as string}
|
||||||
|
</Text>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@@ -254,29 +360,74 @@ const CreateOrUpdateHaulModal: React.FC<CreateOrUpdateHaulModalProps> = ({
|
|||||||
presentationStyle="pageSheet"
|
presentationStyle="pageSheet"
|
||||||
onRequestClose={onClose}
|
onRequestClose={onClose}
|
||||||
>
|
>
|
||||||
<Text>{isCreateMode ? "Create Haul" : "Update Haul"}</Text>
|
<View style={styles.container}>
|
||||||
<FlatList
|
{/* Header */}
|
||||||
data={fields}
|
<View style={styles.header}>
|
||||||
keyExtractor={(it) => it._id}
|
<Text style={styles.title}>
|
||||||
renderItem={renderRow}
|
{isCreateMode ? "Thêm mẻ cá" : "Chỉnh sửa mẻ cá"}
|
||||||
ListFooterComponent={
|
</Text>
|
||||||
<View style={{ marginTop: 8 }}>
|
<View style={styles.headerButtons}>
|
||||||
<Button
|
{isEditing ? (
|
||||||
title="Thêm loài cá"
|
<>
|
||||||
onPress={() => append(defaultItem())}
|
<TouchableOpacity
|
||||||
/>
|
onPress={() => {
|
||||||
|
setIsEditing(false);
|
||||||
|
reset(); // reset to previous values
|
||||||
|
}}
|
||||||
|
style={[styles.saveButton, { backgroundColor: "#6c757d" }]}
|
||||||
|
>
|
||||||
|
<Text style={styles.saveButtonText}>Hủy</Text>
|
||||||
|
</TouchableOpacity>
|
||||||
|
<TouchableOpacity
|
||||||
|
onPress={handleSubmit(onSubmit)}
|
||||||
|
style={styles.saveButton}
|
||||||
|
>
|
||||||
|
<Text style={styles.saveButtonText}>Lưu</Text>
|
||||||
|
</TouchableOpacity>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
!isCreateMode && (
|
||||||
|
<TouchableOpacity
|
||||||
|
onPress={() => setIsEditing(true)}
|
||||||
|
style={[styles.saveButton, { backgroundColor: "#17a2b8" }]}
|
||||||
|
>
|
||||||
|
<Text style={styles.saveButtonText}>Sửa</Text>
|
||||||
|
</TouchableOpacity>
|
||||||
|
)
|
||||||
|
)}
|
||||||
|
<TouchableOpacity onPress={onClose} style={styles.closeButton}>
|
||||||
|
<View style={styles.closeIconButton}>
|
||||||
|
<IconSymbol name="xmark" size={24} color="#fff" />
|
||||||
|
</View>
|
||||||
|
</TouchableOpacity>
|
||||||
</View>
|
</View>
|
||||||
}
|
</View>
|
||||||
/>
|
|
||||||
|
|
||||||
{errors.fish && (
|
{/* Content */}
|
||||||
<Text style={{ color: "red", marginTop: 8 }}>
|
<ScrollView style={styles.content}>
|
||||||
{(errors.fish as any)?.message}
|
{/* Info Section */}
|
||||||
</Text>
|
<InfoSection fishingLog={fishingLog!} stt={fishingLogIndex} />
|
||||||
)}
|
|
||||||
|
|
||||||
<View style={{ marginTop: 16 }}>
|
{/* Fish List */}
|
||||||
<Button title="Lưu thu hoạch" onPress={handleSubmit(onSubmit)} />
|
{fields.map((item, index) => renderRow(item, index))}
|
||||||
|
|
||||||
|
{/* Add Button - only show when editing */}
|
||||||
|
{isEditing && (
|
||||||
|
<TouchableOpacity
|
||||||
|
onPress={() => append(defaultItem())}
|
||||||
|
style={styles.addButton}
|
||||||
|
>
|
||||||
|
<Text style={styles.addButtonText}>+ Thêm loài cá</Text>
|
||||||
|
</TouchableOpacity>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Error Message */}
|
||||||
|
{errors.fish && (
|
||||||
|
<Text style={styles.errorText}>
|
||||||
|
{(errors.fish as any)?.message}
|
||||||
|
</Text>
|
||||||
|
)}
|
||||||
|
</ScrollView>
|
||||||
</View>
|
</View>
|
||||||
</Modal>
|
</Modal>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import {
|
|||||||
import styles from "../style/NetDetailModal.styles";
|
import styles from "../style/NetDetailModal.styles";
|
||||||
import { CatchSectionHeader } from "./components/CatchSectionHeader";
|
import { CatchSectionHeader } from "./components/CatchSectionHeader";
|
||||||
import { FishCardList } from "./components/FishCardList";
|
import { FishCardList } from "./components/FishCardList";
|
||||||
import { InfoSection } from "./components/InfoSection";
|
|
||||||
import { NotesSection } from "./components/NotesSection";
|
import { NotesSection } from "./components/NotesSection";
|
||||||
|
|
||||||
interface NetDetailModalProps {
|
interface NetDetailModalProps {
|
||||||
@@ -320,11 +319,11 @@ const NetDetailModal: React.FC<NetDetailModalProps> = ({
|
|||||||
{/* Content */}
|
{/* Content */}
|
||||||
<ScrollView style={styles.content}>
|
<ScrollView style={styles.content}>
|
||||||
{/* Thông tin chung */}
|
{/* Thông tin chung */}
|
||||||
<InfoSection
|
{/* <InfoSection
|
||||||
netData={netData ?? undefined}
|
netData={netData ?? undefined}
|
||||||
isCompleted={isCompleted}
|
isCompleted={isCompleted}
|
||||||
stt={stt}
|
stt={stt}
|
||||||
/>
|
/> */}
|
||||||
|
|
||||||
{/* Danh sách cá bắt được */}
|
{/* Danh sách cá bắt được */}
|
||||||
<CatchSectionHeader totalCatch={totalCatch} />
|
<CatchSectionHeader totalCatch={totalCatch} />
|
||||||
|
|||||||
@@ -3,53 +3,52 @@ import { Text, View } from "react-native";
|
|||||||
import styles from "../../style/NetDetailModal.styles";
|
import styles from "../../style/NetDetailModal.styles";
|
||||||
|
|
||||||
interface InfoSectionProps {
|
interface InfoSectionProps {
|
||||||
netData?: Model.FishingLog;
|
fishingLog?: Model.FishingLog;
|
||||||
isCompleted: boolean;
|
|
||||||
stt?: number;
|
stt?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const InfoSection: React.FC<InfoSectionProps> = ({
|
export const InfoSection: React.FC<InfoSectionProps> = ({
|
||||||
netData,
|
fishingLog,
|
||||||
isCompleted,
|
|
||||||
stt,
|
stt,
|
||||||
}) => {
|
}) => {
|
||||||
if (!netData) {
|
if (!fishingLog) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
const infoItems = [
|
const infoItems = [
|
||||||
{ label: "Số thứ tự", value: `Mẻ ${stt}` },
|
{ label: "Số thứ tự", value: `Mẻ ${stt}` },
|
||||||
{
|
{
|
||||||
label: "Trạng thái",
|
label: "Trạng thái",
|
||||||
value: netData.status === 1 ? "Đã hoàn thành" : "Chưa hoàn thành",
|
value: fishingLog.status === 1 ? "Đã hoàn thành" : "Chưa hoàn thành",
|
||||||
isStatus: true,
|
isStatus: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "Thời gian bắt đầu",
|
label: "Thời gian bắt đầu",
|
||||||
value: netData.start_at
|
value: fishingLog.start_at
|
||||||
? new Date(netData.start_at).toLocaleString()
|
? new Date(fishingLog.start_at).toLocaleString()
|
||||||
: "Chưa cập nhật",
|
: "Chưa cập nhật",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "Thời gian kết thúc",
|
label: "Thời gian kết thúc",
|
||||||
value: netData.start_at
|
value:
|
||||||
? new Date(netData.end_at).toLocaleString()
|
fishingLog.end_at !== "0001-01-01T00:00:00Z"
|
||||||
: "Chưa cập nhật",
|
? new Date(fishingLog.end_at).toLocaleString()
|
||||||
|
: "-",
|
||||||
},
|
},
|
||||||
// {
|
// {
|
||||||
// label: "Vị trí hạ thu",
|
// label: "Vị trí hạ thu",
|
||||||
// value: netData.viTriHaThu || "Chưa cập nhật",
|
// value: fishingLog.viTriHaThu || "Chưa cập nhật",
|
||||||
// },
|
// },
|
||||||
// {
|
// {
|
||||||
// label: "Vị trí thu lưới",
|
// label: "Vị trí thu lưới",
|
||||||
// value: netData.viTriThuLuoi || "Chưa cập nhật",
|
// value: fishingLog.viTriThuLuoi || "Chưa cập nhật",
|
||||||
// },
|
// },
|
||||||
// {
|
// {
|
||||||
// label: "Độ sâu hạ thu",
|
// label: "Độ sâu hạ thu",
|
||||||
// value: netData.doSauHaThu || "Chưa cập nhật",
|
// value: fishingLog.doSauHaThu || "Chưa cập nhật",
|
||||||
// },
|
// },
|
||||||
// {
|
// {
|
||||||
// label: "Độ sâu thu lưới",
|
// label: "Độ sâu thu lưới",
|
||||||
// value: netData.doSauThuLuoi || "Chưa cập nhật",
|
// value: fishingLog.doSauThuLuoi || "Chưa cập nhật",
|
||||||
// },
|
// },
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,176 @@
|
|||||||
|
import { StyleSheet } from "react-native";
|
||||||
|
|
||||||
|
const styles = StyleSheet.create({
|
||||||
|
container: {
|
||||||
|
flex: 1,
|
||||||
|
backgroundColor: "#f5f5f5",
|
||||||
|
},
|
||||||
|
header: {
|
||||||
|
flexDirection: "row",
|
||||||
|
justifyContent: "space-between",
|
||||||
|
alignItems: "center",
|
||||||
|
paddingHorizontal: 20,
|
||||||
|
paddingTop: 30,
|
||||||
|
paddingBottom: 16,
|
||||||
|
backgroundColor: "#fff",
|
||||||
|
borderBottomWidth: 1,
|
||||||
|
borderBottomColor: "#eee",
|
||||||
|
},
|
||||||
|
title: {
|
||||||
|
fontSize: 22,
|
||||||
|
fontWeight: "700",
|
||||||
|
color: "#000",
|
||||||
|
flex: 1,
|
||||||
|
},
|
||||||
|
headerButtons: {
|
||||||
|
flexDirection: "row",
|
||||||
|
gap: 12,
|
||||||
|
alignItems: "center",
|
||||||
|
},
|
||||||
|
closeButton: {
|
||||||
|
padding: 4,
|
||||||
|
},
|
||||||
|
closeIconButton: {
|
||||||
|
backgroundColor: "#FF3B30",
|
||||||
|
borderRadius: 10,
|
||||||
|
padding: 10,
|
||||||
|
justifyContent: "center",
|
||||||
|
alignItems: "center",
|
||||||
|
},
|
||||||
|
saveButton: {
|
||||||
|
backgroundColor: "#007bff",
|
||||||
|
borderRadius: 8,
|
||||||
|
paddingHorizontal: 20,
|
||||||
|
paddingVertical: 10,
|
||||||
|
justifyContent: "center",
|
||||||
|
alignItems: "center",
|
||||||
|
},
|
||||||
|
saveButtonText: {
|
||||||
|
color: "#fff",
|
||||||
|
fontSize: 16,
|
||||||
|
fontWeight: "600",
|
||||||
|
},
|
||||||
|
content: {
|
||||||
|
flex: 1,
|
||||||
|
padding: 16,
|
||||||
|
marginBottom: 15,
|
||||||
|
},
|
||||||
|
fishCard: {
|
||||||
|
backgroundColor: "#fff",
|
||||||
|
borderRadius: 12,
|
||||||
|
padding: 16,
|
||||||
|
marginBottom: 16,
|
||||||
|
shadowColor: "#000",
|
||||||
|
shadowOpacity: 0.05,
|
||||||
|
shadowRadius: 4,
|
||||||
|
shadowOffset: { width: 0, height: 2 },
|
||||||
|
elevation: 2,
|
||||||
|
},
|
||||||
|
|
||||||
|
fishCardHeaderContent: {
|
||||||
|
flexDirection: "row",
|
||||||
|
alignItems: "center",
|
||||||
|
gap: 8,
|
||||||
|
},
|
||||||
|
fishCardTitle: {
|
||||||
|
fontSize: 16,
|
||||||
|
fontWeight: "700",
|
||||||
|
color: "#000",
|
||||||
|
},
|
||||||
|
fishCardSubtitle: {
|
||||||
|
fontSize: 14,
|
||||||
|
color: "#666",
|
||||||
|
fontWeight: "500",
|
||||||
|
},
|
||||||
|
fieldGroup: {
|
||||||
|
marginBottom: 14,
|
||||||
|
},
|
||||||
|
label: {
|
||||||
|
fontSize: 14,
|
||||||
|
fontWeight: "600",
|
||||||
|
color: "#333",
|
||||||
|
marginBottom: 6,
|
||||||
|
},
|
||||||
|
input: {
|
||||||
|
borderWidth: 1,
|
||||||
|
borderColor: "#ddd",
|
||||||
|
borderRadius: 8,
|
||||||
|
paddingHorizontal: 12,
|
||||||
|
paddingVertical: 10,
|
||||||
|
fontSize: 16,
|
||||||
|
backgroundColor: "#fff",
|
||||||
|
color: "#000",
|
||||||
|
},
|
||||||
|
inputDisabled: {
|
||||||
|
backgroundColor: "#f5f5f5",
|
||||||
|
color: "#999",
|
||||||
|
borderColor: "#eee",
|
||||||
|
},
|
||||||
|
errorText: {
|
||||||
|
color: "#dc3545",
|
||||||
|
fontSize: 12,
|
||||||
|
marginTop: 4,
|
||||||
|
fontWeight: "500",
|
||||||
|
},
|
||||||
|
buttonRow: {
|
||||||
|
flexDirection: "row",
|
||||||
|
justifyContent: "flex-end",
|
||||||
|
gap: 8,
|
||||||
|
marginTop: 12,
|
||||||
|
},
|
||||||
|
removeButton: {
|
||||||
|
backgroundColor: "#dc3545",
|
||||||
|
borderRadius: 8,
|
||||||
|
paddingHorizontal: 16,
|
||||||
|
paddingVertical: 8,
|
||||||
|
justifyContent: "center",
|
||||||
|
alignItems: "center",
|
||||||
|
},
|
||||||
|
removeButtonText: {
|
||||||
|
color: "#fff",
|
||||||
|
fontSize: 14,
|
||||||
|
fontWeight: "600",
|
||||||
|
},
|
||||||
|
addButton: {
|
||||||
|
backgroundColor: "#28a745",
|
||||||
|
borderRadius: 8,
|
||||||
|
paddingHorizontal: 20,
|
||||||
|
paddingVertical: 12,
|
||||||
|
marginTop: 16,
|
||||||
|
justifyContent: "center",
|
||||||
|
alignItems: "center",
|
||||||
|
alignSelf: "flex-start",
|
||||||
|
},
|
||||||
|
addButtonText: {
|
||||||
|
color: "#fff",
|
||||||
|
fontSize: 14,
|
||||||
|
fontWeight: "600",
|
||||||
|
},
|
||||||
|
footerSection: {
|
||||||
|
paddingHorizontal: 16,
|
||||||
|
paddingVertical: 16,
|
||||||
|
backgroundColor: "#fff",
|
||||||
|
borderTopWidth: 1,
|
||||||
|
borderTopColor: "#eee",
|
||||||
|
},
|
||||||
|
saveButtonLarge: {
|
||||||
|
backgroundColor: "#007bff",
|
||||||
|
borderRadius: 8,
|
||||||
|
paddingVertical: 14,
|
||||||
|
justifyContent: "center",
|
||||||
|
alignItems: "center",
|
||||||
|
},
|
||||||
|
saveButtonLargeText: {
|
||||||
|
color: "#fff",
|
||||||
|
fontSize: 16,
|
||||||
|
fontWeight: "700",
|
||||||
|
},
|
||||||
|
emptyStateText: {
|
||||||
|
textAlign: "center",
|
||||||
|
color: "#999",
|
||||||
|
fontSize: 14,
|
||||||
|
marginTop: 20,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default styles;
|
||||||
4
controller/typings.d.ts
vendored
4
controller/typings.d.ts
vendored
@@ -152,8 +152,8 @@ declare namespace Model {
|
|||||||
interface FishingLog {
|
interface FishingLog {
|
||||||
fishing_log_id: string;
|
fishing_log_id: string;
|
||||||
trip_id: string;
|
trip_id: string;
|
||||||
start_at: Date; // ISO datetime
|
start_at: string; // ISO datetime
|
||||||
end_at: Date; // ISO datetime
|
end_at: string; // ISO datetime
|
||||||
start_lat: number;
|
start_lat: number;
|
||||||
start_lon: number;
|
start_lon: number;
|
||||||
haul_lat: number;
|
haul_lat: number;
|
||||||
|
|||||||
@@ -162,3 +162,11 @@ export function stopEvents() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function startEvents() {
|
||||||
|
getGpsEventBus();
|
||||||
|
getAlarmEventBus();
|
||||||
|
getEntitiesEventBus();
|
||||||
|
getTrackPointsEventBus();
|
||||||
|
getBanzonesEventBus();
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user