From 40d9dbb3b63bb99a57ee2fcea86209c7a8b16875 Mon Sep 17 00:00:00 2001 From: HarvelsX <90945793+HarvelsX@users.noreply.github.com> Date: Tue, 19 Dec 2023 17:51:54 +0300 Subject: [PATCH] Fix using Fuse.js; --- .../auction/PurchaseComponent/PurchaseComponent.tsx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/pages/auction/PurchaseComponent/PurchaseComponent.tsx b/src/pages/auction/PurchaseComponent/PurchaseComponent.tsx index 09eccf5..ba8639a 100644 --- a/src/pages/auction/PurchaseComponent/PurchaseComponent.tsx +++ b/src/pages/auction/PurchaseComponent/PurchaseComponent.tsx @@ -82,14 +82,15 @@ const PurchaseComponent: React.FC = ({ } const { slots } = store.getState().slots; - const { search } = new Fuse(slots, { + const fuse = new Fuse(slots, { includeScore: true, - shouldSort: true, + threshold: 0.8, + ignoreLocation: true, keys: ['name'], }); - const match = search(message)[0]; - return match.score && match.score > 0.4 ? { ...match.item, index: match.refIndex } : null; + const match = fuse.search(message)[0]; + return (match && { ...match.item, index: match.refIndex }) ?? null; // eslint-disable-next-line react-hooks/exhaustive-deps }, []);