Skip to content

Commit 62710d3

Browse files
committed
Tutorial driver "fixed"
1 parent c6637d9 commit 62710d3

File tree

2 files changed

+84
-85
lines changed

2 files changed

+84
-85
lines changed
Lines changed: 82 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,102 @@
1+
import { goto } from '$app/navigation';
12
import { driver } from 'driver.js';
2-
import type { DriveStep, Driver } from 'driver.js';
3+
import type { Driver } from 'driver.js';
34
import 'driver.js/dist/driver.css';
5+
import { _ } from 'svelte-i18n';
6+
import { get } from 'svelte/store';
47

58
// hazer un singletone para el tutorial
69
let tutorialDriver: Driver;
10+
let currentStep = 0;
711

8-
function StartTutorial(steps: DriveStep[], currentStep: number = 0) {
12+
const TUTORIAL_DELAY = 750;
13+
14+
export function StartTutorial(selectedStep: number = 0) {
915
if (tutorialDriver) {
1016
tutorialDriver.destroy();
11-
return tutorialDriver;
1217
}
1318

1419
tutorialDriver = driver({
1520
animate: true,
1621
smoothScroll: true,
1722
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+
}
2276
}
2377
}
24-
});
78+
];
79+
80+
tutorialDriver.setSteps(driverSteps);
81+
tutorialDriver.drive(selectedStep);
82+
}
2583

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+
}
2890

29-
return tutorialDriver;
91+
function goPrevTutorial(duration: number = TUTORIAL_DELAY) {
92+
setTimeout(() => {
93+
currentStep = currentStep - 1;
94+
tutorialDriver?.movePrevious();
95+
}, duration);
3096
}
3197

32-
export default StartTutorial;
98+
_.subscribe(() => {
99+
if (tutorialDriver) {
100+
StartTutorial(currentStep);
101+
}
102+
});

frontend/src/routes/+page.svelte

Lines changed: 2 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,14 @@
11
<script lang="ts">
22
import onwebsite from '$lib/detection/onwebsite';
33
import { _ } from 'svelte-i18n';
4-
import { goto } from '$app/navigation';
5-
import StartTutorial from '$lib/tutorial/driver';
4+
import { StartTutorial } from '$lib/tutorial/driver';
65
import type { Driver } from 'driver.js';
76
8-
const TUTORIAL_DELAY = 750;
9-
10-
let tutorialDriver: Driver;
11-
let currentStep = 0;
12-
13-
function goNextTutorial(duration: number = TUTORIAL_DELAY) {
14-
setTimeout(() => {
15-
tutorialDriver.moveNext();
16-
currentStep++;
17-
}, duration);
18-
}
19-
20-
function goPrevTutorial(duration: number = TUTORIAL_DELAY) {
21-
setTimeout(() => {
22-
tutorialDriver.movePrevious();
23-
currentStep--;
24-
}, duration);
25-
}
26-
27-
let tutorialSteps = [
28-
{
29-
element: '#tutorial-config-btn',
30-
popover: {
31-
title: $_('tutorial_config_title'),
32-
description: $_('tutorial_config_description'),
33-
onNextClick: () => {
34-
goto('/mode/config');
35-
goNextTutorial();
36-
}
37-
}
38-
},
39-
{
40-
element: '#tutorial-language',
41-
popover: {
42-
title: $_('tutorial_language_title'),
43-
description: $_('tutorial_language_description'),
44-
onNextClick: () => goNextTutorial,
45-
onPrevClick: () => {
46-
goto('/');
47-
goPrevTutorial();
48-
}
49-
}
50-
},
51-
{
52-
element: '#tutorial-stun-card',
53-
popover: {
54-
title: $_('tutorial_stun_title'),
55-
description: $_('tutorial_stun_description'),
56-
onNextClick: () => {
57-
goto('/mode/config/advanced/stun');
58-
goNextTutorial();
59-
}
60-
}
61-
},
62-
{
63-
element: '#tutorial-group-server',
64-
popover: {
65-
title: $_('tutorial_group_server_title'),
66-
description: $_('tutorial_group_server_description'),
67-
onPrevClick: () => {
68-
goto('/mode/config');
69-
goPrevTutorial();
70-
},
71-
onNextClick: () => {
72-
goto('/mode/config');
73-
goNextTutorial();
74-
}
75-
}
76-
}
77-
];
787
</script>
798

809
<button
8110
on:click={() => {
82-
tutorialDriver = StartTutorial(tutorialSteps);
11+
StartTutorial();
8312
}}
8413
class="btn btn-primary text-white"
8514
>

0 commit comments

Comments
 (0)