fix: sửa lỗi notification và giao diện chat trên android

This commit is contained in:
2026-06-27 11:33:07 +07:00
parent ee42bfcefa
commit fee2aed2e6
68 changed files with 134 additions and 9 deletions
+37 -1
View File
@@ -1,6 +1,7 @@
import React, { useState, useEffect, useRef } from 'react';
import { io, Socket } from 'socket.io-client';
import { Capacitor } from '@capacitor/core';
import { Camera, CameraResultType, CameraSource } from '@capacitor/camera';
import { Send, MessageSquare, Loader2, Image as ImageIcon, MapPin, Download, X } from 'lucide-react';
import { useNotification } from '@/hooks/useNotification';
@@ -255,6 +256,41 @@ export const TourChat: React.FC<TourChatProps> = ({ tourId, embedded = false })
});
};
// Handle Native Image Selection (Camera or Library)
const handleNativePhotoSelect = async () => {
try {
const image = await Camera.getPhoto({
quality: 90,
allowEditing: false,
resultType: CameraResultType.Uri,
source: CameraSource.Prompt, // Prompt selection
saveToGallery: true, // Auto-save original photo to device gallery
promptLabelHeader: 'Chọn hình ảnh',
promptLabelPhoto: 'Chọn từ thư viện',
promptLabelPicture: 'Chụp ảnh mới (Camera)'
});
if (image && image.webPath) {
setImagePreview(image.webPath);
// Convert Capacitor webPath resource back to standard File instance
const response = await fetch(image.webPath);
const blob = await response.blob();
const file = new File([blob], `photo.${image.format}`, { type: `image/${image.format}` });
setSelectedImage(file);
}
} catch (error: any) {
console.error('Lỗi chọn ảnh native:', error);
if (error?.message !== 'User cancelled photos app' && error?.message !== 'User cancelled camera') {
notify({
title: 'Lỗi',
message: 'Không thể truy cập máy ảnh hoặc thư viện ảnh.',
type: 'error'
});
}
}
};
// Handle Image Selection
const handleImageChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const file = e.target.files?.[0];
@@ -609,7 +645,7 @@ export const TourChat: React.FC<TourChatProps> = ({ tourId, embedded = false })
{/* Attach photo button */}
<button
type="button"
onClick={() => fileInputRef.current?.click()}
onClick={Capacitor.isNativePlatform() ? handleNativePhotoSelect : () => fileInputRef.current?.click()}
className="p-2.5 bg-white border border-gray-200 hover:bg-gray-50 text-gray-500 rounded-xl transition-all shadow-sm active:scale-95 flex items-center justify-center shrink-0"
title="Đính kèm hình ảnh"
>