sửa l fix xcall api getTrip

This commit is contained in:
Tran Anh Tuan
2025-11-06 17:45:03 +07:00
parent aabd1109b2
commit 1b748285c9
5 changed files with 29 additions and 33 deletions

View File

@@ -247,7 +247,7 @@ export async function login(body: Model.LoginRequestBody) {
```typescript ```typescript
export async function fetchGpsData() { export async function fetchGpsData() {
return api.get<Model.GPSResonse>(API_GET_GPS); return api.get<Model.GPSResponse>(API_GET_GPS);
} }
``` ```
@@ -388,7 +388,7 @@ export default function TabLayout() {
1. **State management:** 1. **State management:**
```typescript ```typescript
const [gpsData, setGpsData] = useState<Model.GPSResonse | null>(null); const [gpsData, setGpsData] = useState<Model.GPSResponse | null>(null);
``` ```
2. **Fetch GPS data:** 2. **Fetch GPS data:**

View File

@@ -30,19 +30,11 @@ import {
convertWKTtoLatLngString, convertWKTtoLatLngString,
} from "@/utils/geom"; } from "@/utils/geom";
import { useEffect, useRef, useState } from "react"; import { useEffect, useRef, useState } from "react";
import { import { Animated, Image as RNImage, StyleSheet, View } from "react-native";
Animated,
Image as RNImage,
StyleSheet,
View
} from "react-native";
import MapView, { Circle, Marker } from "react-native-maps"; import MapView, { Circle, Marker } from "react-native-maps";
export default function HomeScreen() { export default function HomeScreen() {
const [gpsData, setGpsData] = useState<Model.GPSResonse | null>( const [gpsData, setGpsData] = useState<Model.GPSResponse | null>(null);
null
);
const [alarmData, setAlarmData] = useState<Model.AlarmResponse | null>(null); const [alarmData, setAlarmData] = useState<Model.AlarmResponse | null>(null);
const [entityData, setEntityData] = useState< const [entityData, setEntityData] = useState<
Model.TransformedEntity[] | null Model.TransformedEntity[] | null
@@ -54,9 +46,8 @@ export default function HomeScreen() {
const [circleRadius, setCircleRadius] = useState(100); const [circleRadius, setCircleRadius] = useState(100);
const [zoomLevel, setZoomLevel] = useState(10); const [zoomLevel, setZoomLevel] = useState(10);
const [isFirstLoad, setIsFirstLoad] = useState(true); const [isFirstLoad, setIsFirstLoad] = useState(true);
const [polylineCoordinates, setPolylineCoordinates] = useState< const [polylineCoordinates, setPolylineCoordinates] =
PolylineWithLabelProps | null useState<PolylineWithLabelProps | null>(null);
>(null);
const [polygonCoordinates, setPolygonCoordinates] = useState< const [polygonCoordinates, setPolygonCoordinates] = useState<
PolygonWithLabelProps[] PolygonWithLabelProps[]
>([]); >([]);
@@ -76,7 +67,7 @@ export default function HomeScreen() {
getEntitiesEventBus(); getEntitiesEventBus();
getBanzonesEventBus(); getBanzonesEventBus();
getTrackPointsEventBus(); getTrackPointsEventBus();
const queryGpsData = (gpsData: Model.GPSResonse) => { const queryGpsData = (gpsData: Model.GPSResponse) => {
if (gpsData) { if (gpsData) {
// console.log("GPS Data: ", gpsData); // console.log("GPS Data: ", gpsData);
setGpsData(gpsData); setGpsData(gpsData);
@@ -182,7 +173,6 @@ export default function HomeScreen() {
label: zone?.zone_name ?? "", label: zone?.zone_name ?? "",
content: zone?.message ?? "", content: zone?.message ?? "",
}); });
} }
} else if (geom_type === 1) { } else if (geom_type === 1) {
// foundPolygon = true; // foundPolygon = true;
@@ -293,8 +283,9 @@ export default function HomeScreen() {
return ( return (
<View <View
// edges={["top"]} // edges={["top"]}
style={styles.container}> style={styles.container}
>
<MapView <MapView
onMapReady={handleMapReady} onMapReady={handleMapReady}
onRegionChangeComplete={handleRegionChangeComplete} onRegionChangeComplete={handleRegionChangeComplete}
@@ -351,7 +342,9 @@ export default function HomeScreen() {
return ( return (
<PolygonWithLabel <PolygonWithLabel
key={`polygon-${index}-${gpsData?.lat || 0}-${gpsData?.lon || 0}`} key={`polygon-${index}-${gpsData?.lat || 0}-${
gpsData?.lon || 0
}`}
coordinates={polygon.coordinates} coordinates={polygon.coordinates}
label={polygon.label} label={polygon.label}
content={polygon.content} content={polygon.content}
@@ -367,7 +360,11 @@ export default function HomeScreen() {
)} )}
{gpsData !== null && ( {gpsData !== null && (
<Marker <Marker
key={platform === IOS_PLATFORM ? `${gpsData.lat}-${gpsData.lon}` : "gps-data"} key={
platform === IOS_PLATFORM
? `${gpsData.lat}-${gpsData.lon}`
: "gps-data"
}
coordinate={{ coordinate={{
latitude: gpsData.lat, latitude: gpsData.lat,
longitude: gpsData.lon, longitude: gpsData.lon,
@@ -412,10 +409,11 @@ export default function HomeScreen() {
height: 32, height: 32,
transform: [ transform: [
{ {
rotate: `${typeof gpsData.h === "number" && !isNaN(gpsData.h) rotate: `${
typeof gpsData.h === "number" && !isNaN(gpsData.h)
? gpsData.h ? gpsData.h
: 0 : 0
}deg`, }deg`,
}, },
], ],
}} }}
@@ -425,7 +423,7 @@ export default function HomeScreen() {
</Marker> </Marker>
)} )}
</MapView> </MapView>
<View className="absolute top-14 right-2 shadow-md"> <View className="absolute top-14 right-2 shadow-md">
<SosButton /> <SosButton />
</View> </View>

View File

@@ -5,17 +5,15 @@ import CrewListTable from "@/components/tripInfo/CrewListTable";
import FishingToolsTable from "@/components/tripInfo/FishingToolsList"; import FishingToolsTable from "@/components/tripInfo/FishingToolsList";
import NetListTable from "@/components/tripInfo/NetListTable"; import NetListTable from "@/components/tripInfo/NetListTable";
import TripCostTable from "@/components/tripInfo/TripCostTable"; import TripCostTable from "@/components/tripInfo/TripCostTable";
import { useTrip } from "@/state/use-trip";
import { useEffect } from "react";
import { Platform, ScrollView, StyleSheet, Text, View } from "react-native"; import { Platform, ScrollView, StyleSheet, Text, View } from "react-native";
import { SafeAreaView } from "react-native-safe-area-context"; import { SafeAreaView } from "react-native-safe-area-context";
export default function TripInfoScreen() { export default function TripInfoScreen() {
const { trip, getTrip } = useTrip(); // const { trip, getTrip } = useTrip();
useEffect(() => { // useEffect(() => {
getTrip(); // getTrip();
}, []); // }, []);
return ( return (
<SafeAreaView style={styles.safeArea} edges={["top", "left", "right"]}> <SafeAreaView style={styles.safeArea} edges={["top", "left", "right"]}>
<View style={styles.header}> <View style={styles.header}>

View File

@@ -30,7 +30,7 @@ const ButtonCreateNewHaulOrTrip: React.FC<StartButtonProps> = ({
const { trip, getTrip } = useTrip(); const { trip, getTrip } = useTrip();
useEffect(() => { useEffect(() => {
getTrip(); getTrip();
}, [trip === null]); }, []);
const checkHaulFinished = () => { const checkHaulFinished = () => {
return trip?.fishing_logs?.some((h) => h.status === 0); return trip?.fishing_logs?.some((h) => h.status === 0);

View File

@@ -13,7 +13,7 @@ export const useTrip = create<Trip>((set) => ({
getTrip: async () => { getTrip: async () => {
try { try {
const response = await queryTrip(); const response = await queryTrip();
console.log("Trip fetching: ", response.data); console.log("Trip fetching API");
set({ trip: response.data, loading: false }); set({ trip: response.data, loading: false });
} catch (error) { } catch (error) {