fill data API NetDetail
This commit is contained in:
@@ -14,38 +14,11 @@ import { FishCardList } from "./components/FishCardList";
|
||||
import { InfoSection } from "./components/InfoSection";
|
||||
import { NotesSection } from "./components/NotesSection";
|
||||
|
||||
// ---------------------------
|
||||
// 🧩 Interface
|
||||
// ---------------------------
|
||||
interface FishCatch {
|
||||
fish_species_id: number;
|
||||
fish_name: string;
|
||||
catch_number: number;
|
||||
catch_unit: string;
|
||||
fish_size: number;
|
||||
fish_rarity: number;
|
||||
fish_condition: string;
|
||||
gear_usage: string;
|
||||
}
|
||||
|
||||
interface NetDetail {
|
||||
id: string;
|
||||
stt: string;
|
||||
trangThai: string;
|
||||
thoiGianBatDau?: string;
|
||||
thoiGianKetThuc?: string;
|
||||
viTriHaThu?: string;
|
||||
viTriThuLuoi?: string;
|
||||
doSauHaThu?: string;
|
||||
doSauThuLuoi?: string;
|
||||
catchList?: FishCatch[];
|
||||
ghiChu?: string;
|
||||
}
|
||||
|
||||
interface NetDetailModalProps {
|
||||
visible: boolean;
|
||||
onClose: () => void;
|
||||
netData: NetDetail | null;
|
||||
netData: Model.FishingLog | null;
|
||||
stt?: number;
|
||||
}
|
||||
|
||||
// ---------------------------
|
||||
@@ -55,9 +28,12 @@ const NetDetailModal: React.FC<NetDetailModalProps> = ({
|
||||
visible,
|
||||
onClose,
|
||||
netData,
|
||||
stt,
|
||||
}) => {
|
||||
const [isEditing, setIsEditing] = useState(false);
|
||||
const [editableCatchList, setEditableCatchList] = useState<FishCatch[]>([]);
|
||||
const [editableCatchList, setEditableCatchList] = useState<
|
||||
Model.FishingLogInfo[]
|
||||
>([]);
|
||||
const [selectedFishIndex, setSelectedFishIndex] = useState<number | null>(
|
||||
null
|
||||
);
|
||||
@@ -74,8 +50,8 @@ const NetDetailModal: React.FC<NetDetailModalProps> = ({
|
||||
|
||||
// Khởi tạo dữ liệu khi netData thay đổi
|
||||
React.useEffect(() => {
|
||||
if (netData?.catchList) {
|
||||
setEditableCatchList(netData.catchList);
|
||||
if (netData?.info) {
|
||||
setEditableCatchList(netData.info);
|
||||
}
|
||||
}, [netData]);
|
||||
|
||||
@@ -93,7 +69,7 @@ const NetDetailModal: React.FC<NetDetailModalProps> = ({
|
||||
|
||||
// if (!netData) return null;
|
||||
|
||||
const isCompleted = netData?.trangThai === "Đã hoàn thành";
|
||||
const isCompleted = netData?.status === 2; // ví dụ: status=2 là hoàn thành
|
||||
|
||||
// Danh sách tên cá có sẵn
|
||||
const fishNameOptions = [
|
||||
@@ -210,7 +186,7 @@ const NetDetailModal: React.FC<NetDetailModalProps> = ({
|
||||
|
||||
const handleCancel = () => {
|
||||
setIsEditing(false);
|
||||
setEditableCatchList(netData?.catchList || []);
|
||||
setEditableCatchList(netData?.info || []);
|
||||
};
|
||||
|
||||
const handleToggleExpanded = (index: number) => {
|
||||
@@ -221,7 +197,7 @@ const NetDetailModal: React.FC<NetDetailModalProps> = ({
|
||||
|
||||
const updateCatchItem = (
|
||||
index: number,
|
||||
field: keyof FishCatch,
|
||||
field: keyof Model.FishingLogInfo,
|
||||
value: string | number
|
||||
) => {
|
||||
setEditableCatchList((prev) =>
|
||||
@@ -245,7 +221,7 @@ const NetDetailModal: React.FC<NetDetailModalProps> = ({
|
||||
};
|
||||
|
||||
const handleAddNewFish = () => {
|
||||
const newFish: FishCatch = {
|
||||
const newFish: Model.FishingLogInfo = {
|
||||
fish_species_id: 0,
|
||||
fish_name: "",
|
||||
catch_number: 0,
|
||||
@@ -289,7 +265,8 @@ const NetDetailModal: React.FC<NetDetailModalProps> = ({
|
||||
|
||||
// Chỉ tính tổng số lượng cá có đơn vị là 'kg'
|
||||
const totalCatch = editableCatchList.reduce(
|
||||
(sum, item) => (item.catch_unit === "kg" ? sum + item.catch_number : sum),
|
||||
(sum, item) =>
|
||||
item.catch_unit === "kg" ? sum + (item.catch_number ?? 0) : sum,
|
||||
0
|
||||
);
|
||||
|
||||
@@ -346,6 +323,7 @@ const NetDetailModal: React.FC<NetDetailModalProps> = ({
|
||||
<InfoSection
|
||||
netData={netData ?? undefined}
|
||||
isCompleted={isCompleted}
|
||||
stt={stt}
|
||||
/>
|
||||
|
||||
{/* Danh sách cá bắt được */}
|
||||
@@ -375,7 +353,7 @@ const NetDetailModal: React.FC<NetDetailModalProps> = ({
|
||||
/>
|
||||
|
||||
{/* Ghi chú */}
|
||||
<NotesSection ghiChu={netData?.ghiChu} />
|
||||
<NotesSection ghiChu={netData?.weather_description} />
|
||||
</ScrollView>
|
||||
</View>
|
||||
</Modal>
|
||||
|
||||
Reference in New Issue
Block a user