fix: resolve backend TS compilation errors, startup order, and add clipboard paste upload
- Fix products.service.ts: ingredients -> ingredientList (Prisma relation name) - Fix seed-blogs.ts: template literal refactor (array join) to avoid esbuild parse error - Fix seed-custom.ts: category string -> connectOrCreate relation - Add start-dev.js: sequential startup (backend first, then frontends) - Add Ctrl+V paste upload to admin MediaSelector component - Create missing images/vets/ and images/slider/ directories
This commit is contained in:
1 parent
0ea6c6d271
commit
cd17a532d9
6 files changed
+153
-50
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import { useState, useEffect, useRef } from 'react';
|
||||
import { X, Upload, Image as ImageIcon, Trash2, CheckCircle2 } from 'lucide-react';
|
||||
import { X, Upload, Image as ImageIcon, Trash2, CheckCircle2, Clipboard } from 'lucide-react';
|
||||
import api from '../../services/api';
|
||||
import Spinner from './Spinner';
|
||||
|
||||
@@ -21,7 +21,9 @@ export default function MediaSelector({ isOpen, onClose, onSelect, multiple = fa
|
||||
const [mediaList, setMediaList] = useState<Media[]>([]);
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [isUploading, setIsUploading] = useState(false);
|
||||
const [pasteStatus, setPasteStatus] = useState<string | null>(null);
|
||||
const fileInputRef = useRef<HTMLInputElement>(null);
|
||||
const pasteTimerRef = useRef<ReturnType<typeof setTimeout>>();
|
||||
|
||||
useEffect(() => {
|
||||
if (isOpen) {
|
||||
@@ -29,6 +31,44 @@ export default function MediaSelector({ isOpen, onClose, onSelect, multiple = fa
|
||||
}
|
||||
}, [isOpen]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isOpen) return;
|
||||
|
||||
const handlePaste = (e: ClipboardEvent) => {
|
||||
const items = e.clipboardData?.items;
|
||||
if (!items) return;
|
||||
|
||||
for (const item of Array.from(items)) {
|
||||
if (item.type.startsWith('image/')) {
|
||||
e.preventDefault();
|
||||
setPasteStatus('در حال آپلود از کلیپبورد...');
|
||||
const file = item.getAsFile();
|
||||
if (!file) continue;
|
||||
const formData = new FormData();
|
||||
formData.append('file', file, `clipboard-${Date.now()}.png`);
|
||||
api.post('/admin/media/upload', formData, {
|
||||
headers: { 'Content-Type': 'multipart/form-data' }
|
||||
}).then(() => {
|
||||
setPasteStatus('آپلود موفق!');
|
||||
fetchMedia();
|
||||
}).catch(() => {
|
||||
setPasteStatus('خطا در آپلود');
|
||||
}).finally(() => {
|
||||
if (pasteTimerRef.current) clearTimeout(pasteTimerRef.current);
|
||||
pasteTimerRef.current = setTimeout(() => setPasteStatus(null), 3000);
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
document.addEventListener('paste', handlePaste);
|
||||
return () => {
|
||||
document.removeEventListener('paste', handlePaste);
|
||||
if (pasteTimerRef.current) clearTimeout(pasteTimerRef.current);
|
||||
};
|
||||
}, [isOpen]);
|
||||
|
||||
const fetchMedia = async () => {
|
||||
try {
|
||||
setIsLoading(true);
|
||||
@@ -100,8 +140,19 @@ export default function MediaSelector({ isOpen, onClose, onSelect, multiple = fa
|
||||
|
||||
{/* Toolbar */}
|
||||
<div className="p-4 border-b border-gray-100 flex justify-between items-center bg-white">
|
||||
<p className="text-sm font-bold text-gray-600">{mediaList.length} فایل موجود</p>
|
||||
<div>
|
||||
<div className="flex items-center gap-3">
|
||||
<p className="text-sm font-bold text-gray-600">{mediaList.length} فایل موجود</p>
|
||||
{pasteStatus && (
|
||||
<span className={`text-xs px-2 py-1 rounded-full font-medium ${pasteStatus.includes('موفق') ? 'bg-green-100 text-green-700' : pasteStatus.includes('خطا') ? 'bg-red-100 text-red-700' : 'bg-blue-100 text-blue-700'}`}>
|
||||
{pasteStatus}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex items-center gap-3">
|
||||
<span className="text-xs text-gray-400 hidden sm:flex items-center gap-1">
|
||||
<Clipboard className="w-3.5 h-3.5" />
|
||||
Ctrl+V برای چسباندن تصویر
|
||||
</span>
|
||||
<input
|
||||
type="file"
|
||||
ref={fileInputRef}
|
||||
|
||||
Reference in new issue
Block a user