Skip to content

Commit

Permalink
feat: automatically assign the first result of the assignments
Browse files Browse the repository at this point in the history
close #1477
  • Loading branch information
hamed-musallam committed Apr 19, 2022
1 parent fd365f3 commit d3d8ad1
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/component/panels/AutomaticAssignment/useGetAssignments.ts
Expand Up @@ -10,7 +10,9 @@ import { useCallback, useMemo, useState } from 'react';
import { Datum1D } from '../../../data/types/data1d';
import { Datum2D } from '../../../data/types/data2d/Datum2D';
import { useChartData } from '../../context/ChartContext';
import { useDispatch } from '../../context/DispatchContext';
import { useAlert } from '../../elements/popup/Alert';
import { SET_AUTOMATIC_ASSIGNMENTS } from '../../reducer/types/Types';

export interface AutoAssignmentsData {
score: number;
Expand All @@ -33,6 +35,7 @@ function mapSpectra(data: (Datum1D | Datum2D)[]) {
}

export function useGetAssignments() {
const dispatch = useDispatch();
const { data, molecules } = useChartData();
const alert = useAlert();
const [assignments, setAssignments] = useState<AutoAssignmentsData[]>([]);
Expand All @@ -49,10 +52,15 @@ export function useGetAssignments() {
},
{ minScore: 0 },
);
dispatch({
type: SET_AUTOMATIC_ASSIGNMENTS,
payload: { assignments: result[0].assignment },
});

hideLoading();
setAssignments(result);
})();
}, [alert, data, molecules]);
}, [alert, data, dispatch, molecules]);

return useMemo(
() => ({
Expand Down

0 comments on commit d3d8ad1

Please sign in to comment.