fix: reorder hooks to resolve handleSync declaration order
This commit is contained in:
@@ -61,6 +61,12 @@ export default function Home() {
|
||||
const [comparisonModal, setComparisonModal] = useState<{ show: boolean, newItem: any, existingItem: any, existingId: number | null }>({ show: false, newItem: null, existingItem: null, existingId: null });
|
||||
const [comparisonLoading, setComparisonLoading] = useState(false);
|
||||
|
||||
const { syncing, handleSync } = useSync({
|
||||
isOnline,
|
||||
currentUser,
|
||||
onInventoryUpdate: setInventory
|
||||
});
|
||||
|
||||
const {
|
||||
mode,
|
||||
setMode,
|
||||
@@ -106,12 +112,6 @@ export default function Home() {
|
||||
onInventoryUpdate: setInventory
|
||||
});
|
||||
|
||||
const { syncing, handleSync } = useSync({
|
||||
isOnline,
|
||||
currentUser,
|
||||
onInventoryUpdate: setInventory
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (!localStorage.getItem('inventory_token')) {
|
||||
window.location.href = '/login';
|
||||
@@ -163,22 +163,6 @@ export default function Home() {
|
||||
}
|
||||
};
|
||||
|
||||
const handleSync = useCallback(async () => {
|
||||
if (!isOnline || !currentUser) return;
|
||||
setSyncing(true);
|
||||
try {
|
||||
const result = await syncOfflineOperations(currentUser.id);
|
||||
if (result.success > 0) {
|
||||
toast.success(`Synced ${result.success} operations!`);
|
||||
}
|
||||
await loadInventory();
|
||||
} catch (error) {
|
||||
console.error("Sync failed", error);
|
||||
} finally {
|
||||
setSyncing(false);
|
||||
}
|
||||
}, [isOnline, currentUser]);
|
||||
|
||||
const handleOnboardingComplete = async (itemData: any) => {
|
||||
try {
|
||||
if (itemData.part_number) {
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user