From 2079561eb145cdd4a54bc84f22f551bc4910c67e Mon Sep 17 00:00:00 2001 From: Sayaka Ono Date: Thu, 5 Dec 2024 17:51:56 -0800 Subject: [PATCH] Revert "LF-4558 Add useAnimalInventoryItemCount hook" This reverts commit ffcc55c10f0bc9bd6b2d5cfa821a6caf709886d2. --- .../src/hooks/useAnimalInventoryItemCount.ts | 42 ------------------- 1 file changed, 42 deletions(-) delete mode 100644 packages/webapp/src/hooks/useAnimalInventoryItemCount.ts diff --git a/packages/webapp/src/hooks/useAnimalInventoryItemCount.ts b/packages/webapp/src/hooks/useAnimalInventoryItemCount.ts deleted file mode 100644 index 273a08ef12..0000000000 --- a/packages/webapp/src/hooks/useAnimalInventoryItemCount.ts +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2024 LiteFarm.org - * This file is part of LiteFarm. - * - * LiteFarm is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * LiteFarm is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details, see . - */ - -import { useMemo } from 'react'; -import useQueries from './api/useQueries'; -import { useGetAnimalBatchesQuery, useGetAnimalsQuery } from '../store/api/apiSlice'; -import { Animal, AnimalBatch } from '../store/api/types'; - -const getCount = (animalOrBatch: (Animal | AnimalBatch)[]) => { - return animalOrBatch.filter((entity) => !entity.animal_removal_reason_id).length; -}; - -const useAnimalInventoryItemCount = (): number | undefined => { - const { data, isLoading, isError } = useQueries([ - { label: 'animals', hook: useGetAnimalsQuery }, - { label: 'batches', hook: useGetAnimalBatchesQuery }, - ]); - - const count = useMemo(() => { - if (isLoading || isError) { - return undefined; - } - - return getCount([...data.animals, ...data.batches]); - }, [data.animals, data.batches, isLoading, isError]); - - return count; -}; - -export default useAnimalInventoryItemCount;