Diff of /src/hooks/usePipeline.ts [000000] .. [d6876d]

Switch to unified view

a b/src/hooks/usePipeline.ts
1
import { useCallback } from 'react';
2
import { useDispatch, useSelector } from 'react-redux';
3
import { AppDispatch, RootState } from '../store/store';
4
import { 
5
  runExperiment, 
6
  monitorExperiment, 
7
  stopExperiment, 
8
  clearError 
9
} from '../store/slices/pipelineSlice';
10
import { ExperimentConfig, GeneAssembly, UsePipelineResult } from '../types';
11
12
export const usePipeline = (): UsePipelineResult => {
13
  const dispatch = useDispatch<AppDispatch>();
14
  const { isProcessing, error } = useSelector((state: RootState) => state.pipeline);
15
16
  const startPipeline = useCallback(
17
    async (config: { experimentConfig: ExperimentConfig; assembly: GeneAssembly }) => {
18
      try {
19
        await dispatch(runExperiment({ 
20
          config: config.experimentConfig, 
21
          assembly: config.assembly 
22
        })).unwrap();
23
        // Start monitoring the experiment
24
        const experimentId = config.experimentConfig.id;
25
        await dispatch(monitorExperiment(experimentId)).unwrap();
26
      } catch (error) {
27
        console.error('Pipeline execution failed:', error);
28
      }
29
    },
30
    [dispatch]
31
  );
32
33
  const stopPipelineExecution = useCallback(
34
    async (id: string) => {
35
      try {
36
        await dispatch(stopExperiment(id)).unwrap();
37
      } catch (error) {
38
        console.error('Failed to stop pipeline:', error);
39
      }
40
    },
41
    [dispatch]
42
  );
43
44
  const clearPipelineError = useCallback(() => {
45
    dispatch(clearError());
46
  }, [dispatch]);
47
48
  return {
49
    isProcessing,
50
    error,
51
    startPipeline,
52
    stopPipeline: stopPipelineExecution,
53
    clearError: clearPipelineError,
54
  };
55
};
56
57
// Selector hooks for different pipeline results
58
export const useExperimentResults = () => {
59
  return useSelector((state: RootState) => state.pipeline.activeExperiments);
60
};
61
62
export const useGenomicAnalyses = () => {
63
  return useSelector((state: RootState) => state.pipeline.genomicAnalyses);
64
};
65
66
export const useSimulationResults = () => {
67
  return useSelector((state: RootState) => state.pipeline.simulations);
68
};
69
70
// Export for module resolution
71
export default usePipeline;