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          24763x 24763x 24763x     24763x       9303x 9303x 72x         633x 633x 290x           9294x 9294x 9231x      
import { useCoreRecycledataListQuery } from "@/api/apiStore.gen";
import { useProjectId } from "./project";
import { useCurrentGroupId } from "./flowsheetObjects";
 
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);
  };
}