All files / src/hooks recycleData.ts

100% Statements 16/16
100% Branches 2/2
100% Functions 10/10
100% Lines 13/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35          24908x 24908x 24908x     24908x       9208x 9208x 76x         837x 837x 378x           9198x 9198x 9132x      
import { useCoreRecycledataListQuery } from "@/api/apiStore.gen";
import { useCurrentGroupId } from "./flowsheetObjects";
import { useProjectId } from "./project";
 
export function useRecycleData() {
  const projectId = useProjectId();
  const groupId = useCurrentGroupId();
  const { data: recycleData } = useCoreRecycledataListQuery({
    group: groupId,
  });
  return recycleData || [];
}
 
export function useObjectRecycleData() {
  const recycleData = useRecycleData();
  return (simulationObjectId: number) => {
    return recycleData.find((r) => r.simulationObject === simulationObjectId);
  };
}
 
export function useObjectConnectedToRecycle() {
  const recycleData = useRecycleData();
  return (simulationObjectId: number) => {
    return recycleData.some((r) => r.tearObject === simulationObjectId);
  };
}
 
// Returns the object itself instead of just truth value
export function useSimObjectConnectedToRecycle() {
  const recycleData = useRecycleData();
  return (simulationObjectId: number) => {
    return recycleData.find((r) => r.tearObject === simulationObjectId);
  };
}