|
|
import { |
|
|
GUIDED_TOUR_UPDATE, |
|
|
GUIDED_TOUR_PAUSE, |
|
|
GUIDED_TOUR_RESUME, |
|
|
} from 'calypso/state/action-types'; |
|
|
import { savePreference } from 'calypso/state/preferences/actions'; |
|
|
import { getPreference } from 'calypso/state/preferences/selectors'; |
|
|
|
|
|
import 'calypso/state/guided-tours/init'; |
|
|
import 'calypso/state/ui/init'; |
|
|
|
|
|
export function quitGuidedTour( { tour, stepName, finished } ) { |
|
|
const quitAction = { |
|
|
type: GUIDED_TOUR_UPDATE, |
|
|
shouldShow: false, |
|
|
shouldReallyShow: false, |
|
|
tour, |
|
|
stepName, |
|
|
finished, |
|
|
}; |
|
|
|
|
|
return ( dispatch, getState ) => { |
|
|
dispatch( addSeenGuidedTour( getState, tour, finished ) ); |
|
|
dispatch( quitAction ); |
|
|
}; |
|
|
} |
|
|
|
|
|
export function nextGuidedTourStep( { tour, stepName } ) { |
|
|
return { |
|
|
type: GUIDED_TOUR_UPDATE, |
|
|
tour, |
|
|
stepName, |
|
|
isPaused: false, |
|
|
}; |
|
|
} |
|
|
|
|
|
export function requestGuidedTour( tour ) { |
|
|
return nextGuidedTourStep( { tour, stepName: 'init' } ); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function addSeenGuidedTour( getState, tourName, finished = false ) { |
|
|
return savePreference( 'guided-tours-history', [ |
|
|
...getPreference( getState(), 'guided-tours-history' ), |
|
|
{ |
|
|
timestamp: Date.now(), |
|
|
tourName, |
|
|
finished, |
|
|
}, |
|
|
] ); |
|
|
} |
|
|
|
|
|
export function resetGuidedToursHistory() { |
|
|
return savePreference( 'guided-tours-history', [] ); |
|
|
} |
|
|
|
|
|
export function pauseGuidedTour() { |
|
|
return { |
|
|
type: GUIDED_TOUR_PAUSE, |
|
|
isPaused: true, |
|
|
}; |
|
|
} |
|
|
|
|
|
export function resumeGuidedTour() { |
|
|
return { |
|
|
type: GUIDED_TOUR_RESUME, |
|
|
isPaused: false, |
|
|
}; |
|
|
} |
|
|
|