Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
handleJoyrideCallback = data => {
const { action, index, status, type } = data;
if ([EVENTS.STEP_AFTER, EVENTS.TARGET_NOT_FOUND].includes(type)) {
// Update state to advance the tour
this.setState({ stepIndex: index + (action === ACTIONS.PREV ? -1 : 1) });
}
else if ([STATUS.FINISHED, STATUS.SKIPPED].includes(status)) {
// Need to set our running state to false, so we can restart if we click start again.
this.setState({ run: false });
this.registerEvent(status)
}
console.groupCollapsed(type);
console.log(data); //eslint-disable-line no-console
console.groupEnd();
};
const { action, index, type, status, step } = data;
const { actions } = step || {};
const { prev, next } = actions || {};
if ([STATUS.FINISHED, STATUS.SKIPPED].includes(status)) {
// Need to set our running state to false, so we can restart if we click start again.
handleStateChange({ open: false, stepIndex: 0, stepsKey: '' });
} else if (data.action === 'close' || data.type === 'tour:end') {
handleStateChange({
stepIndex: 0,
open: false
});
} else if (
[
EVENTS.STEP_AFTER,
EVENTS.TARGET_NOT_FOUND,
EVENTS.TOUR_START
].includes(type)
) {
const newStepIndex = index + (action === ACTIONS.PREV ? -1 : 1);
// Update state to advance the tour
let delay = 400;
if (action === 'prev' && prev) {
prev();
}
if (action === 'next' && next) {
next();
}
if (action === 'start' && prev && index === 0) {
setTimeout(() => {
this.setState({
...this.state,
run: true
});
}, 250);
return;
}
this.doStep(callbackProps);
} else if (callbackProps.type === EVENTS.TARGET_NOT_FOUND) {
// TODO: add a DOM event listener to wait for it to become
// available???
log.warn("Not found: ", callbackProps);
this.doStep(callbackProps);
}
}
endGuide();
}
} else if ([EVENTS.STEP_AFTER].includes(type)) {
const newStepIndex = index + (action === ACTIONS.PREV ? -1 : 1);
if (action !== ACTIONS.PREV && !readyToProceed(newStepIndex)) {
// we are not ready to proceed to the next step. Reset the current step.
// The stop/start of the guide is needed to reset the Joyride events, or it will
// be somewhere in between steps, statewise.
setRunGuide(false);
setStepIndex(index);
setTimeout(() => setRunGuide(true), 100);
} else {
// Update state to advance the guide
setStepIndex(newStepIndex);
}
} else if ([EVENTS.TARGET_NOT_FOUND].includes(type)) {
// The target could not be found. Go to next step.
const newStepIndex = index + 1;
setStepIndex(newStepIndex);
}
};
handleJoyrideCallback = data => {
const { action, index, status, type } = data;
//console.log(data)
const centerDiv = (element)=>{
const elementRect = element.getBoundingClientRect();
const absoluteElementTop = elementRect.top + window.pageYOffset;
const middle = absoluteElementTop - (window.innerHeight / 2);
window.scrollTo(0, middle);
}
if ([EVENTS.STEP_AFTER, EVENTS.TARGET_NOT_FOUND].includes(type)) {
if (action === ACTIONS.NEXT || action === ACTIONS.PREV) {
let t = null
if (action === ACTIONS.NEXT){
t = this.state.steps[index + 1]
} else if (action === ACTIONS.PREV) {
t = this.state.steps[index - 1]
}
if(!t) return
const a = document.querySelector(t.target)
centerDiv(a)
}