11import React , { useEffect , useState } from 'react' ;
22import Modal from './ParentModal' ;
3+ import ConfirmModal from './ConfirmModal' ;
34import './settings.css' ;
45import { actionType as T } from '../../reducer' ;
56import GA from '../../graph-builder/graph-actions' ;
@@ -21,6 +22,8 @@ const HistoryModal = ({ superState, dispatcher }) => {
2122 return res ;
2223 } ;
2324 const [ filterAction , setFilterAction ] = useState ( mapActionToTrue ( ) ) ;
25+ const [ restoreConfirmOpen , setRestoreConfirmOpen ] = useState ( false ) ;
26+ const [ pendingRestoreIndex , setPendingRestoreIndex ] = useState ( null ) ;
2427
2528 const getLabelFromID = ( x ) => {
2629 if ( superState . curGraphInstance ) {
@@ -71,20 +74,33 @@ const HistoryModal = ({ superState, dispatcher }) => {
7174 [ GA . SET_BENDW ] : 'EdgeBend' ,
7275 } ;
7376
74- const restoreState = ( index ) => {
75- // eslint-disable-next-line no-alert
76- if ( window . confirm ( 'Are you sure to restore the selected state?' ) ) {
77- let tempCurState = curState ;
78- while ( index > tempCurState ) {
79- superState . curGraphInstance . undoSingleAction ( ) ;
80- tempCurState += 1 ;
81- }
82- while ( index < tempCurState ) {
83- superState . curGraphInstance . redoSingleAction ( ) ;
84- tempCurState -= 1 ;
85- }
86- setcurState ( tempCurState ) ;
77+ const doRestore = ( index ) => {
78+ let tempCurState = curState ;
79+ while ( index > tempCurState ) {
80+ superState . curGraphInstance . undoSingleAction ( ) ;
81+ tempCurState += 1 ;
82+ }
83+ while ( index < tempCurState ) {
84+ superState . curGraphInstance . redoSingleAction ( ) ;
85+ tempCurState -= 1 ;
8786 }
87+ setcurState ( tempCurState ) ;
88+ } ;
89+
90+ const restoreState = ( index ) => {
91+ setPendingRestoreIndex ( index ) ;
92+ setRestoreConfirmOpen ( true ) ;
93+ } ;
94+
95+ const handleRestoreConfirm = ( ) => {
96+ doRestore ( pendingRestoreIndex ) ;
97+ setRestoreConfirmOpen ( false ) ;
98+ setPendingRestoreIndex ( null ) ;
99+ } ;
100+
101+ const handleRestoreCancel = ( ) => {
102+ setRestoreConfirmOpen ( false ) ;
103+ setPendingRestoreIndex ( null ) ;
88104 } ;
89105 const prefixTid = ( tid , str , authorName , index , hash ) => {
90106 const DT = new Date ( parseInt ( tid , 10 ) ) ;
@@ -127,11 +143,19 @@ const HistoryModal = ({ superState, dispatcher }) => {
127143
128144 const close = ( ) => dispatcher ( { type : T . SET_HISTORY_MODAL , payload : false } ) ;
129145 return (
130- < Modal
131- ModelOpen = { superState . viewHistory }
132- closeModal = { close }
133- title = "History"
134- >
146+ < >
147+ < ConfirmModal
148+ isOpen = { restoreConfirmOpen }
149+ title = "Restore State"
150+ message = "Are you sure you want to restore the selected state?"
151+ onConfirm = { handleRestoreConfirm }
152+ onCancel = { handleRestoreCancel }
153+ />
154+ < Modal
155+ ModelOpen = { superState . viewHistory }
156+ closeModal = { close }
157+ title = "History"
158+ >
135159 < div className = "hist-container" >
136160 < fieldset >
137161 < legend > Filters</ legend >
@@ -168,7 +192,8 @@ const HistoryModal = ({ superState, dispatcher }) => {
168192 </ table >
169193 </ div >
170194 </ div >
171- </ Modal >
195+ </ Modal >
196+ </ >
172197 ) ;
173198} ;
174199
0 commit comments