Build [v1.10.11]

This commit is contained in:
2026-04-15 20:57:01 +03:00
parent 99ad87f994
commit 572422b677
12 changed files with 113 additions and 145 deletions

View File

@@ -16,33 +16,14 @@ import {
Trash2,
AlertTriangle,
X,
History,
LayoutGrid,
Wifi,
WifiOff,
ChevronRight,
ChevronDown,
Edit2,
RefreshCw,
CloudOff,
Sparkles,
Smartphone,
CheckCircle2,
User,
ArrowDownCircle,
ArrowUpCircle,
Settings,
Lock,
Shield,
Key,
LogOut,
UserPlus,
Tag,
ArrowRight,
ArrowLeft,
Search,
Printer,
Download
Search
} from 'lucide-react';
import { generateBarcode128, getQRCodeURL } from '@/lib/labels';
import { clsx, type ClassValue } from 'clsx';
@@ -87,23 +68,20 @@ export default function Home() {
window.location.href = '/login';
return;
}
setMounted(true);
setIsOnline(navigator.onLine);
const savedUser = localStorage.getItem('inventory_user');
if (savedUser) {
setCurrentUser(JSON.parse(savedUser));
}
// Initial categories fetch
// Initial data fetch
inventoryApi.getCategories().then(c => setCategories(c)).catch(() => { });
}, []);
loadInventory();
preloadOCR();
useEffect(() => {
if (!localStorage.getItem('inventory_token')) {
window.location.href = '/login';
return;
}
setMounted(true);
setIsOnline(navigator.onLine);
const handleOnline = () => {
setIsOnline(true);
handleSync(); // Auto-sync pending ops when back online
@@ -121,9 +99,6 @@ export default function Home() {
}
}, 30000);
loadInventory();
preloadOCR();
return () => {
window.removeEventListener('online', handleOnline);
window.removeEventListener('offline', handleOffline);
@@ -157,7 +132,7 @@ export default function Home() {
const handleOnboardingComplete = async (itemData: any) => {
try {
if (itemData.part_number) {
itemData.part_number = itemData.part_number.toUpperCase();
itemData.part_number = itemData.part_number.toLowerCase();
}
// 1. Add to local DB cache
await db.items.add(itemData);
@@ -198,9 +173,9 @@ export default function Home() {
setLastScanned(barcode);
setShowScanner(false);
const upperBarcode = barcode.toUpperCase();
const normalizedBarcode = barcode.toLowerCase();
const item = await db.items.where('barcode').equals(barcode)
.or('part_number').equals(upperBarcode).first();
.or('part_number').equals(normalizedBarcode).first();
if (!item) {
toast.error(`Item ${barcode} not found in catalog.`);
@@ -230,7 +205,7 @@ export default function Home() {
const onOCRMatch = useCallback(async (text: string) => {
// 1. Clean and normalize
const cleanText = text.toUpperCase().replace(/[^A-Z0-9\s/+-]/g, ' ');
const cleanText = text.toLowerCase().replace(/[^a-z0-9\s/+-]/g, ' ');
// Garbage Filter: Ignore noisy strings (measurements like 0.11, dates like 2024-07-25)
// We only keep tokens that are at least 3 chars AND not just decimals
@@ -258,7 +233,7 @@ export default function Home() {
// [BOX SCANNING LOGIC] Prioritize checking if this is a known box
const possibleBoxItems = inventory.filter(item => {
if (!item.box_label) return false;
const boxText = item.box_label.toUpperCase().replace(/[^A-Z0-9\s/+-]/g, ' ');
const boxText = item.box_label.toLowerCase().replace(/[^a-z0-9\s/+-]/g, ' ');
// Exact or Partial include match for box label
if (cleanText.includes(boxText)) return true;
// Strong token matching (for words >= 4 chars)
@@ -286,11 +261,11 @@ export default function Home() {
for (const item of inventory) {
let score = 0;
const pn = (item.part_number || '').toUpperCase();
const sn = (item.serial_number || '').toUpperCase();
const name = item.name.toUpperCase();
const category = item.category.toUpperCase();
const ocrKey = (item.ocr_text || '').toUpperCase().replace(/[^A-Z0-9\s/+-]/g, ' ');
const pn = (item.part_number || '').toLowerCase();
const sn = (item.serial_number || '').toLowerCase();
const name = item.name.toLowerCase();
const category = item.category.toLowerCase();
const ocrKey = (item.ocr_text || '').toLowerCase().replace(/[^a-z0-9\s/+-]/g, ' ');
// Priority 0: Exact OCR Key match (Heuristic provided by AI)
if (ocrKey && cleanText.includes(ocrKey)) score += 1000;
@@ -333,7 +308,7 @@ export default function Home() {
try {
const updated = { ...selectedItem, ...editedItem };
// Normalize PN
if (updated.part_number) updated.part_number = updated.part_number.toUpperCase();
if (updated.part_number) updated.part_number = updated.part_number.toLowerCase();
await db.items.update(selectedItem.id!, updated);
@@ -459,8 +434,8 @@ export default function Home() {
/>
</div>
<div>
<h1 className="text-2xl md:text-3xl font-black tracking-tight text-white leading-tight">Admin Control</h1>
<p className="text-xs md:text-sm text-slate-400 font-bold tracking-tight mt-1 uppercase tracking-widest leading-relaxed">System Configuration & Security</p>
<h1 className="text-2xl md:text-3xl font-black tracking-tight text-white leading-tight">Inventory Control</h1>
<p className="text-xs md:text-sm text-slate-400 font-bold tracking-tight mt-1 leading-relaxed">Check-in, Check-out & Trash Operations</p>
</div>
</div>
@@ -576,7 +551,7 @@ export default function Home() {
<h3 className="text-xl font-black tracking-tight flex items-center gap-2">
{isEditing ? "Edit Metadata" : selectedItem.name}
{!isEditing && (
<span className="text-[11px] bg-slate-800 text-slate-400 px-2 py-0.5 rounded-md font-black uppercase tracking-tight shadow-sm border border-slate-700/50">
<span className="text-[11px] bg-slate-800 text-slate-400 px-2 py-0.5 rounded-md font-black tracking-tight shadow-sm border border-slate-700/50">
In Stock: {selectedItem.quantity}
</span>
)}
@@ -617,7 +592,7 @@ export default function Home() {
<div className="space-y-4 mb-8">
<div>
<div className="bg-slate-900/80 py-2.5 px-4 rounded-[1.2rem] border border-slate-800 focus-within:border-primary/50 transition-colors group">
<label className="text-xs text-slate-400 font-bold mb-0.5 block group-focus-within:text-primary transition-colors tracking-tight uppercase">Item Name</label>
<label className="text-xs text-slate-400 font-bold mb-0.5 block group-focus-within:text-primary transition-colors tracking-tight">Item Name</label>
<textarea
value={editedItem.name || ''}
onChange={(e) => setEditedItem({ ...editedItem, name: e.target.value })}
@@ -731,7 +706,7 @@ export default function Home() {
/>
</div>
<div className="bg-slate-900/80 py-2.5 px-4 rounded-[1.2rem] border border-slate-800 focus-within:border-primary/50 transition-colors group">
<label className="text-xs text-slate-400 font-bold mb-0.5 block group-focus-within:text-primary transition-colors tracking-tight uppercase">OCR Matching Key</label>
<label className="text-xs text-slate-400 font-bold mb-0.5 block group-focus-within:text-primary transition-colors tracking-tight">OCR Matching Key</label>
<textarea
value={editedItem.ocr_text || ''}
onChange={e => setEditedItem({ ...editedItem, ocr_text: e.target.value })}
@@ -774,7 +749,7 @@ export default function Home() {
</button>
<div className="text-center">
<span className="text-xs font-black tabular-nums">{adjustQty}</span>
<span className="text-[10px] text-primary/80 font-bold uppercase tracking-tight">Units</span>
<span className="text-[10px] text-primary/80 font-bold tracking-tight">Units</span>
</div>
<button
onClick={() => setAdjustQty(adjustQty + 1)}
@@ -858,7 +833,7 @@ export default function Home() {
>
<div className="flex-1 min-w-0">
<p className="text-sm font-black text-white">{item.name}</p>
<p className="text-xs text-slate-400 font-bold uppercase tracking-widest mt-1">Part #: {item.part_number || 'N/A'}</p>
<p className="text-xs text-slate-400 font-bold mt-1">Part #: {item.part_number || 'N/A'}</p>
</div>
<ChevronRight size={18} className="text-slate-600 group-hover:text-primary" />
</button>