|
| 1 | +import { goto } from '$app/navigation'; |
1 | 2 | import { driver } from 'driver.js'; |
2 | | -import type { DriveStep, Driver } from 'driver.js'; |
| 3 | +import type { Driver } from 'driver.js'; |
3 | 4 | import 'driver.js/dist/driver.css'; |
| 5 | +import { _ } from 'svelte-i18n'; |
| 6 | +import { get } from 'svelte/store'; |
4 | 7 |
|
5 | 8 | // hazer un singletone para el tutorial |
6 | 9 | let tutorialDriver: Driver; |
| 10 | +let currentStep = 0; |
7 | 11 |
|
8 | | -function StartTutorial(steps: DriveStep[], currentStep: number = 0) { |
| 12 | +const TUTORIAL_DELAY = 750; |
| 13 | + |
| 14 | +export function StartTutorial(selectedStep: number = 0) { |
9 | 15 | if (tutorialDriver) { |
10 | 16 | tutorialDriver.destroy(); |
11 | | - return tutorialDriver; |
12 | 17 | } |
13 | 18 |
|
14 | 19 | tutorialDriver = driver({ |
15 | 20 | animate: true, |
16 | 21 | smoothScroll: true, |
17 | 22 | stagePadding: 1, |
18 | | - stageRadius: 1, |
19 | | - onDestroyStarted: () => { |
20 | | - if (!tutorialDriver.hasNextStep() || confirm('Are you sure?')) { |
21 | | - tutorialDriver.destroy(); |
| 23 | + stageRadius: 1 |
| 24 | + }); |
| 25 | + |
| 26 | + const driverSteps = [ |
| 27 | + { |
| 28 | + element: '#tutorial-config-btn', |
| 29 | + popover: { |
| 30 | + title: get(_)('tutorial_config_title'), |
| 31 | + description: get(_)('tutorial_config_description'), |
| 32 | + onNextClick: () => { |
| 33 | + goto('/mode/config'); |
| 34 | + goNextTutorial(); |
| 35 | + } |
| 36 | + } |
| 37 | + }, |
| 38 | + { |
| 39 | + element: '#tutorial-language', |
| 40 | + popover: { |
| 41 | + title: get(_)('tutorial_language_title'), |
| 42 | + description: get(_)('tutorial_language_description'), |
| 43 | + onNextClick: () => { |
| 44 | + goNextTutorial(); |
| 45 | + }, |
| 46 | + onPrevClick: () => { |
| 47 | + goto('/'); |
| 48 | + goPrevTutorial(); |
| 49 | + } |
| 50 | + } |
| 51 | + }, |
| 52 | + { |
| 53 | + element: '#tutorial-stun-card', |
| 54 | + popover: { |
| 55 | + title: get(_)('tutorial_stun_title'), |
| 56 | + description: get(_)('tutorial_stun_description'), |
| 57 | + onNextClick: () => { |
| 58 | + goto('/mode/config/advanced/stun'); |
| 59 | + goNextTutorial(); |
| 60 | + } |
| 61 | + } |
| 62 | + }, |
| 63 | + { |
| 64 | + element: '#tutorial-group-server', |
| 65 | + popover: { |
| 66 | + title: get(_)('tutorial_group_server_title'), |
| 67 | + description: get(_)('tutorial_group_server_description'), |
| 68 | + onPrevClick: () => { |
| 69 | + goto('/mode/config'); |
| 70 | + goPrevTutorial(); |
| 71 | + }, |
| 72 | + onNextClick: () => { |
| 73 | + goto('/mode/config'); |
| 74 | + goNextTutorial(); |
| 75 | + } |
22 | 76 | } |
23 | 77 | } |
24 | | - }); |
| 78 | + ]; |
| 79 | + |
| 80 | + tutorialDriver.setSteps(driverSteps); |
| 81 | + tutorialDriver.drive(selectedStep); |
| 82 | +} |
25 | 83 |
|
26 | | - tutorialDriver.setSteps(steps); |
27 | | - tutorialDriver.drive(currentStep); |
| 84 | +function goNextTutorial(duration: number = TUTORIAL_DELAY) { |
| 85 | + setTimeout(() => { |
| 86 | + currentStep = currentStep + 1; |
| 87 | + tutorialDriver?.moveNext(); |
| 88 | + }, duration); |
| 89 | +} |
28 | 90 |
|
29 | | - return tutorialDriver; |
| 91 | +function goPrevTutorial(duration: number = TUTORIAL_DELAY) { |
| 92 | + setTimeout(() => { |
| 93 | + currentStep = currentStep - 1; |
| 94 | + tutorialDriver?.movePrevious(); |
| 95 | + }, duration); |
30 | 96 | } |
31 | 97 |
|
32 | | -export default StartTutorial; |
| 98 | +_.subscribe(() => { |
| 99 | + if (tutorialDriver) { |
| 100 | + StartTutorial(currentStep); |
| 101 | + } |
| 102 | +}); |
0 commit comments