All files / src/hooks recycleData.ts

83.33% Statements 30/36
75% Branches 6/8
76.92% Functions 10/13
100% Lines 21/21

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        29085x 29085x 29085x 29085x   30593x 30763x     12947x 12947x 668x 73x 13615x     3198x 3198x 345x 1540x 3543x       12940x 12940x 665x 12874x 13605x    
import { useCoreRecycledataListQuery } from "@/api/apiStore.gen";
import { useCurrentGroupId } from "./flowsheetObjects";
import { useFlowsheetId } from "./project";
 
export function useRecycleData() {
  const projectId = useFlowsheetId();
  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);
  };
}