@@ -17,6 +17,8 @@ import SdocHooks from "../../../api/SdocHooks.ts";
1717import SdocRenderer from "../../../components/SourceDocument/SdocRenderer.tsx" ;
1818import SdocTagsRenderer from "../../../components/SourceDocument/SdocTagRenderer.tsx" ;
1919import ContentContainerLayout from "../../../layouts/ContentLayouts/ContentContainerLayout.tsx" ;
20+ import { useAppDispatch , useAppSelector } from "../../../plugins/ReduxHooks.ts" ;
21+ import { DuplicateFinderActions } from "./duplicateFinderSlice.ts" ;
2022
2123interface DuplicateDocumentData {
2224 sdocId : string ;
@@ -47,15 +49,26 @@ function ProjectDuplicateDocuments() {
4749 const [ maxDifferentWords , setMaxDifferentWords ] = useState < number > ( 10 ) ;
4850 const [ rowSelection , setRowSelection ] = useState < MRT_RowSelectionState > ( { } ) ;
4951
52+ // global client state
53+ const dispatch = useAppDispatch ( ) ;
54+ const lastDuplicateFinderJobId = useAppSelector ( ( state ) => state . duplicateFinder . lastDuplicateFinderJobId ) ;
55+
5056 // actions
51- const startDuplicateFinderJobMutation = JobHooks . useStartDuplicateFinderJob ( ) ;
57+ const { mutate : startDuplicateFinderJob , isPending } = JobHooks . useStartDuplicateFinderJob ( ) ;
5258 const handleClickFindDuplicateTextDocuments = ( ) => {
53- startDuplicateFinderJobMutation . mutate ( {
54- requestBody : {
55- project_id : projectId ,
56- max_different_words : maxDifferentWords ,
59+ startDuplicateFinderJob (
60+ {
61+ requestBody : {
62+ project_id : projectId ,
63+ max_different_words : maxDifferentWords ,
64+ } ,
5765 } ,
58- } ) ;
66+ {
67+ onSuccess : ( data ) => {
68+ dispatch ( DuplicateFinderActions . setLastDuplicateFinderJobId ( data . job_id ) ) ;
69+ } ,
70+ } ,
71+ ) ;
5972 } ;
6073 const deleteDocumentsMutation = SdocHooks . useDeleteDocuments ( ) ;
6174 const handleDeleteClick = ( sdocIds : number [ ] ) => {
@@ -66,12 +79,19 @@ function ProjectDuplicateDocuments() {
6679 {
6780 onSuccess : ( ) => {
6881 setRowSelection ( { } ) ;
69- startDuplicateFinderJobMutation . mutate ( {
70- requestBody : {
71- project_id : projectId ,
72- max_different_words : maxDifferentWords ,
82+ startDuplicateFinderJob (
83+ {
84+ requestBody : {
85+ project_id : projectId ,
86+ max_different_words : maxDifferentWords ,
87+ } ,
7388 } ,
74- } ) ;
89+ {
90+ onSuccess : ( data ) => {
91+ dispatch ( DuplicateFinderActions . setLastDuplicateFinderJobId ( data . job_id ) ) ;
92+ } ,
93+ } ,
94+ ) ;
7595 } ,
7696 } ,
7797 ) ;
@@ -89,10 +109,7 @@ function ProjectDuplicateDocuments() {
89109 } ;
90110
91111 // job data
92- const duplicateFinderJob = JobHooks . usePollDuplicateFinderJob (
93- startDuplicateFinderJobMutation . data ?. job_id ,
94- undefined ,
95- ) ;
112+ const duplicateFinderJob = JobHooks . usePollDuplicateFinderJob ( lastDuplicateFinderJobId , undefined ) ;
96113
97114 // computed
98115 const data = useMemo ( ( ) => {
@@ -139,7 +156,7 @@ function ProjectDuplicateDocuments() {
139156 state : {
140157 rowSelection, //pass our managed row selection state to the table to use
141158 isLoading :
142- startDuplicateFinderJobMutation . isPending ||
159+ isPending ||
143160 duplicateFinderJob . isLoading ||
144161 ( duplicateFinderJob . data && duplicateFinderJob . data . status !== JobStatus . FINISHED ) ,
145162 } ,
@@ -227,7 +244,7 @@ function ProjectDuplicateDocuments() {
227244 sx = { { ml : 1 } }
228245 onClick = { handleClickFindDuplicateTextDocuments }
229246 loading = {
230- startDuplicateFinderJobMutation . isPending ||
247+ isPending ||
231248 duplicateFinderJob . isLoading ||
232249 ( duplicateFinderJob . data && duplicateFinderJob . data . status !== JobStatus . FINISHED )
233250 }
0 commit comments