feat: tính năng offline cho upload ảnh và tải bản đồ
This commit is contained in:
@@ -2,6 +2,7 @@ import React, { useEffect, useState, useRef } from 'react';
|
||||
import { io, Socket } from 'socket.io-client';
|
||||
import { Capacitor } from '@capacitor/core';
|
||||
import { BACKEND_URL } from '@/utils/backendEndpoint';
|
||||
import { queueOfflineUpload } from '@/utils/offlineQueue';
|
||||
import {
|
||||
Compass,
|
||||
Users,
|
||||
@@ -287,6 +288,37 @@ export const MemberDashboard: React.FC<MemberDashboardProps> = ({
|
||||
}
|
||||
setIsLocating(false);
|
||||
|
||||
// ── OFFLINE GUARD ──────────────────────────────────────────────────────────
|
||||
if (!navigator.onLine) {
|
||||
try {
|
||||
const token = localStorage.getItem('token') || '';
|
||||
const formFields: Record<string, string> = {};
|
||||
if (attachedLocation) {
|
||||
formFields['latitude'] = attachedLocation.latitude.toString();
|
||||
formFields['longitude'] = attachedLocation.longitude.toString();
|
||||
}
|
||||
|
||||
await queueOfflineUpload({
|
||||
endpoint: `${BACKEND_URL}/api/v1/tours/${tourId}/photos`,
|
||||
authToken: token,
|
||||
fileBlob: file,
|
||||
fileName: file.name,
|
||||
formFields,
|
||||
});
|
||||
|
||||
notify({
|
||||
title: 'Ảnh đã được lưu tạm ngoại tuyến 📦',
|
||||
message: 'Kết nối lại mạng, ảnh sẽ tự động được tải lên tour.',
|
||||
type: 'info',
|
||||
});
|
||||
} catch (err) {
|
||||
notify({ title: 'Lỗi', message: 'Không thể lưu ảnh ngoại tuyến.', type: 'error' });
|
||||
} finally {
|
||||
if (cameraInputRef.current) cameraInputRef.current.value = '';
|
||||
}
|
||||
return;
|
||||
}
|
||||
// ── ONLINE PATH ───────────────────────────────────────────────────────────────
|
||||
// Upload photo to tour
|
||||
setIsUploading(true);
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user