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        92013x 92013x 92013x 92013x   93125x 93250x     44966x 44966x 459x 14x 45425x     2088x 2088x 323x 1044x 2411x       44959x 44959x 455x 1718x 45414x    
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);
  };
}