@@ -10,19 +10,22 @@ const QUERY_TYPE_LOAD = 'QUERY_TYPE_LOAD';
1010const QUERY_TYPE_PREVIOUS = 'QUERY_TYPE_PREVIOUS' ;
1111const QUERY_TYPE_NEXT = 'QUERY_TYPE_NEXT' ;
1212
13- export const TimeTravelControl = ( limit = 5 ) => {
13+ export const useTimeTravel = ( limit = 5 ) => {
1414 const { woqlClient, branch, chosenCommit, setHead} = WOQLClientObj ( )
1515 if ( ! woqlClient ) return ""
1616 const dataProduct = woqlClient . db ( )
1717
1818 const [ report , setError ] = useState ( false )
1919 // type Date
20- const currentDay = new Date ( )
21- if ( chosenCommit && chosenCommit . time ) currentDay . setTime ( chosenCommit . time * 1000 )
20+ const startcurrentDay = new Date ( )
21+ // If there is a commit selected I add 6 second to the time
22+ // because the query is less then or he not get the selected one
23+ if ( chosenCommit && chosenCommit . time ) startcurrentDay . setTime ( ( chosenCommit . time * 1000 ) + 6000 )
2224 //Unix timestamp (in seconds)
23- const currentStartTime = Math . floor ( + currentDay / 1000 ) //currentDay.unix();
25+ const currentStartTime = Math . floor ( + startcurrentDay / 1000 )
2426 const [ olderCommit , setOlderCommit ] = useState ( true ) ;
2527 const [ currentPage , setCurrentPage ] = useState ( 0 ) ;
28+ const [ currentDay , setUpdateCurrentDay ] = useState ( startcurrentDay ) ;
2629 const [ startTime , setUpdateStartTime ] = useState ( currentStartTime ) ;
2730 const [ gotoPosition , setGotoPosition ] = useState ( null ) ;
2831 const [ reloadQuery , setReloadQuery ] = useState ( 0 ) ;
@@ -87,6 +90,8 @@ export const TimeTravelControl = (limit=5) => {
8790 else queryObj = WOQL . lib ( ) . commits ( branch , limit , currentPage ) ;
8891 }
8992 const tmpWoqlClient = woqlClient . copy ( )
93+ // I should reset the commit or I see only a subset of commits
94+ tmpWoqlClient . ref ( null )
9095
9196 tmpWoqlClient . query ( queryObj ) . then ( ( result ) => {
9297 if ( result . bindings ) {
@@ -214,16 +219,21 @@ export const TimeTravelControl = (limit=5) => {
214219 // setReloadQuery(Date.now());
215220 }
216221
217- const setStartTime = ( date ) => {
222+ const setStartTime = ( date , resetday ) => {
218223 setCurrentPage ( 0 ) ;
219224 setGotoPosition ( null )
220225 //setCurrentCommit(null)
221- const unixTime = ( Math . floor ( + date / 1000 ) + 86400 ) //time.add(1,'day').unix();
226+ const unixTime = ( Math . floor ( + date / 1000 ) + 86400 )
222227 if ( unixTime !== startTime ) setDataProviderValues ( { dataProvider :[ ] , selectedValue :0 } ) ;
223228 if ( chosenCommit && chosenCommit . time ) {
224229 //reset the commit
225230 setHead ( branch , { } )
226231 }
232+ if ( resetday ) {
233+ const tmpCurrentDay = new Date ( )
234+ tmpCurrentDay . setTime ( date )
235+ setUpdateCurrentDay ( tmpCurrentDay + 6000 )
236+ }
227237 setUpdateStartTime ( unixTime )
228238 }
229239
0 commit comments