All files / src/hooks/cache useResultSummaryRefresh.ts

87.5% Statements 7/8
100% Branches 1/1
100% Functions 1/1
100% Lines 5/5

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                  22x           20659x 20659x     14x     20763x    
import { api } from "@/api/apiStore.gen.ts";
import { useAppDispatch } from "@/store/hooks.ts";
 
type ResultSummaryRefreshTarget = {
  scenarioId: number;
  simulationObjectId: number;
};
 
function resultSummaryTag(target: ResultSummaryRefreshTarget) {
  return {
    type: "ResultSummaries" as never,
    id: `${target.scenarioId}:${target.simulationObjectId}`,
  };
}
 
export function useResultSummaryRefresh() {
  const dispatch = useAppDispatch();
 
  const refreshResultSummaries = (targets: ResultSummaryRefreshTarget[]) => {
    dispatch(api.util.invalidateTags(targets.map(resultSummaryTag)));
  };
 
  return { refreshResultSummaries };
}