Skip to content

Commit

Permalink
Tutorial driver "fixed"
Browse files Browse the repository at this point in the history
  • Loading branch information
PiterWeb committed Sep 10, 2024
1 parent c6637d9 commit 62710d3
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 85 deletions.
94 changes: 82 additions & 12 deletions frontend/src/lib/tutorial/driver.ts
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);
}
});
75 changes: 2 additions & 73 deletions frontend/src/routes/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,85 +1,14 @@
<script lang="ts">
import onwebsite from '$lib/detection/onwebsite';
import { _ } from 'svelte-i18n';
import { goto } from '$app/navigation';
import StartTutorial from '$lib/tutorial/driver';
import { StartTutorial } from '$lib/tutorial/driver';
import type { Driver } from 'driver.js';
const TUTORIAL_DELAY = 750;
let tutorialDriver: Driver;
let currentStep = 0;
function goNextTutorial(duration: number = TUTORIAL_DELAY) {
setTimeout(() => {
tutorialDriver.moveNext();
currentStep++;
}, duration);
}
function goPrevTutorial(duration: number = TUTORIAL_DELAY) {
setTimeout(() => {
tutorialDriver.movePrevious();
currentStep--;
}, duration);
}
let tutorialSteps = [
{
element: '#tutorial-config-btn',
popover: {
title: $_('tutorial_config_title'),
description: $_('tutorial_config_description'),
onNextClick: () => {
goto('/mode/config');
goNextTutorial();
}
}
},
{
element: '#tutorial-language',
popover: {
title: $_('tutorial_language_title'),
description: $_('tutorial_language_description'),
onNextClick: () => goNextTutorial,
onPrevClick: () => {
goto('/');
goPrevTutorial();
}
}
},
{
element: '#tutorial-stun-card',
popover: {
title: $_('tutorial_stun_title'),
description: $_('tutorial_stun_description'),
onNextClick: () => {
goto('/mode/config/advanced/stun');
goNextTutorial();
}
}
},
{
element: '#tutorial-group-server',
popover: {
title: $_('tutorial_group_server_title'),
description: $_('tutorial_group_server_description'),
onPrevClick: () => {
goto('/mode/config');
goPrevTutorial();
},
onNextClick: () => {
goto('/mode/config');
goNextTutorial();
}
}
}
];
</script>

<button
on:click={() => {
tutorialDriver = StartTutorial(tutorialSteps);
StartTutorial();
}}
class="btn btn-primary text-white"
>
Expand Down

0 comments on commit 62710d3

Please sign in to comment.