-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
84 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,102 @@ | ||
import { goto } from '$app/navigation'; | ||
import { driver } from 'driver.js'; | ||
import type { DriveStep, Driver } from 'driver.js'; | ||
import type { Driver } from 'driver.js'; | ||
import 'driver.js/dist/driver.css'; | ||
import { _ } from 'svelte-i18n'; | ||
import { get } from 'svelte/store'; | ||
|
||
// hazer un singletone para el tutorial | ||
let tutorialDriver: Driver; | ||
let currentStep = 0; | ||
|
||
function StartTutorial(steps: DriveStep[], currentStep: number = 0) { | ||
const TUTORIAL_DELAY = 750; | ||
|
||
export function StartTutorial(selectedStep: number = 0) { | ||
if (tutorialDriver) { | ||
tutorialDriver.destroy(); | ||
return tutorialDriver; | ||
} | ||
|
||
tutorialDriver = driver({ | ||
animate: true, | ||
smoothScroll: true, | ||
stagePadding: 1, | ||
stageRadius: 1, | ||
onDestroyStarted: () => { | ||
if (!tutorialDriver.hasNextStep() || confirm('Are you sure?')) { | ||
tutorialDriver.destroy(); | ||
stageRadius: 1 | ||
}); | ||
|
||
const driverSteps = [ | ||
{ | ||
element: '#tutorial-config-btn', | ||
popover: { | ||
title: get(_)('tutorial_config_title'), | ||
description: get(_)('tutorial_config_description'), | ||
onNextClick: () => { | ||
goto('/mode/config'); | ||
goNextTutorial(); | ||
} | ||
} | ||
}, | ||
{ | ||
element: '#tutorial-language', | ||
popover: { | ||
title: get(_)('tutorial_language_title'), | ||
description: get(_)('tutorial_language_description'), | ||
onNextClick: () => { | ||
goNextTutorial(); | ||
}, | ||
onPrevClick: () => { | ||
goto('/'); | ||
goPrevTutorial(); | ||
} | ||
} | ||
}, | ||
{ | ||
element: '#tutorial-stun-card', | ||
popover: { | ||
title: get(_)('tutorial_stun_title'), | ||
description: get(_)('tutorial_stun_description'), | ||
onNextClick: () => { | ||
goto('/mode/config/advanced/stun'); | ||
goNextTutorial(); | ||
} | ||
} | ||
}, | ||
{ | ||
element: '#tutorial-group-server', | ||
popover: { | ||
title: get(_)('tutorial_group_server_title'), | ||
description: get(_)('tutorial_group_server_description'), | ||
onPrevClick: () => { | ||
goto('/mode/config'); | ||
goPrevTutorial(); | ||
}, | ||
onNextClick: () => { | ||
goto('/mode/config'); | ||
goNextTutorial(); | ||
} | ||
} | ||
} | ||
}); | ||
]; | ||
|
||
tutorialDriver.setSteps(driverSteps); | ||
tutorialDriver.drive(selectedStep); | ||
} | ||
|
||
tutorialDriver.setSteps(steps); | ||
tutorialDriver.drive(currentStep); | ||
function goNextTutorial(duration: number = TUTORIAL_DELAY) { | ||
setTimeout(() => { | ||
currentStep = currentStep + 1; | ||
tutorialDriver?.moveNext(); | ||
}, duration); | ||
} | ||
|
||
return tutorialDriver; | ||
function goPrevTutorial(duration: number = TUTORIAL_DELAY) { | ||
setTimeout(() => { | ||
currentStep = currentStep - 1; | ||
tutorialDriver?.movePrevious(); | ||
}, duration); | ||
} | ||
|
||
export default StartTutorial; | ||
_.subscribe(() => { | ||
if (tutorialDriver) { | ||
StartTutorial(currentStep); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters