@@ -122,25 +122,55 @@ const HistoryPanel: React.FC<HistoryPanelProps> = ({ isOpen, onClose }) => {
122
122
// const { todayBatches, past7DaysBatches, past30DaysBatches } = categorizeBatches();
123
123
124
124
const deleteBatchFromHistory = ( batchId : string ) => {
125
-
125
+ // Get the current URL path
126
+ const currentPath = window . location . pathname ;
127
+
128
+ // Check if the current URL contains the batch ID being deleted
129
+ const isCurrentBatch = currentPath . includes ( `/batch-view/${ batchId } ` ) ||
130
+ currentPath . includes ( `/batch-process/${ batchId } ` ) ;
131
+
126
132
const headers = {
127
133
"Content-Type" : "application/json" ,
128
134
"user_id" : "<authenticated_user_id>"
129
135
} ;
136
+
130
137
try {
131
138
dispatch ( deleteBatch ( { batchId, headers } ) ) . unwrap ( ) ;
132
139
const updatedBatchHistory = batchHistory . filter ( batch => batch . batch_id !== batchId ) ;
133
140
setBatchHistory ( updatedBatchHistory ) ;
141
+
142
+ // If the deleted batch is the current one, navigate to home page
143
+ if ( isCurrentBatch ) {
144
+ onClose ( ) ; // Close the panel first
145
+ requestAnimationFrame ( ( ) => {
146
+ navigate ( '/' ) ; // Navigate to homepage
147
+ } ) ;
148
+ }
134
149
} catch ( error ) {
135
150
console . error ( "Batch deletion failed:" , error ) ;
136
151
}
137
152
} ;
138
153
139
154
const deleteAllBatchesFromHistory = async ( ) => {
155
+ // Get the current URL path
156
+ const currentPath = window . location . pathname ;
157
+
158
+ // Check if the current URL contains "/batch-view/" or "/batch-process/"
159
+ const isViewingBatch = currentPath . includes ( "/batch-view/" ) ||
160
+ currentPath . includes ( "/batch-process/" ) ;
161
+
140
162
try {
141
163
const headers = { "Content-Type" : "application/json" , user_id : "<authenticated_user_id>" } ;
142
164
await dispatch ( deleteAllBatches ( { headers } ) ) . unwrap ( ) ;
143
165
setBatchHistory ( [ ] ) ;
166
+
167
+ // If the user is currently viewing any batch, navigate to home page
168
+ if ( isViewingBatch ) {
169
+ onClose ( ) ; // Close the panel first
170
+ requestAnimationFrame ( ( ) => {
171
+ navigate ( '/' ) ; // Navigate to homepage
172
+ } ) ;
173
+ }
144
174
} catch ( error ) {
145
175
setError ( "Failed to clear batch history. Please try again later." ) ;
146
176
setTimeout ( ( ) => {
0 commit comments