|
| 1 | +interface Tutorial { |
| 2 | + element: string |
| 3 | + popover: { |
| 4 | + title: string |
| 5 | + description: string |
| 6 | + } |
| 7 | +} |
| 8 | + |
| 9 | +interface TutorialMetadata { |
| 10 | + tutorial: Tutorial[] |
| 11 | + cookieName: string |
| 12 | +} |
| 13 | + |
| 14 | +type TutorialsMetadata = Record<string, TutorialMetadata[]> |
| 15 | + |
| 16 | +const labelsTutorial: Tutorial[] = [ |
| 17 | + { |
| 18 | + element: '#lhsLabel', |
| 19 | + popover: { |
| 20 | + title: 'New feature', |
| 21 | + description: 'Now you can add custom labels to text blocks', |
| 22 | + }, |
| 23 | + }, |
| 24 | + { |
| 25 | + element: '#rhsLabel', |
| 26 | + popover: { |
| 27 | + title: 'New feature', |
| 28 | + description: 'Now you can add custom labels to text blocks', |
| 29 | + }, |
| 30 | + }, |
| 31 | +] |
| 32 | + |
| 33 | +const actionBarTutorial: Tutorial[] = [ |
| 34 | + { |
| 35 | + element: '#toggleScrollInSyncSection', |
| 36 | + popover: { |
| 37 | + title: 'Scroll In Sync', |
| 38 | + description: 'Now you can choose to scroll both sides in sync.', |
| 39 | + }, |
| 40 | + }, |
| 41 | + { |
| 42 | + element: '#nextDiffSection', |
| 43 | + popover: { |
| 44 | + title: 'Travel through diff hunks', |
| 45 | + description: 'Now you can move between next and previous diff hunks.', |
| 46 | + }, |
| 47 | + }, |
| 48 | + { |
| 49 | + element: '#prevDiffSection', |
| 50 | + popover: { |
| 51 | + title: 'Travel through diff hunks', |
| 52 | + description: 'Now you can move between next and previous diff hunks.', |
| 53 | + }, |
| 54 | + }, |
| 55 | +] |
| 56 | + |
| 57 | +const backButtonTutorial: Tutorial[] = [ |
| 58 | + { |
| 59 | + element: '#backToDataLink', |
| 60 | + popover: { |
| 61 | + title: 'Go back to edit screen', |
| 62 | + description: |
| 63 | + 'Now your data persists between the page navigation. Only if you have clicked on "Compare" button', |
| 64 | + }, |
| 65 | + }, |
| 66 | +] |
| 67 | + |
| 68 | +const tutorialsMetadata: TutorialsMetadata = { |
| 69 | + '/v1/diff': [ |
| 70 | + { |
| 71 | + tutorial: actionBarTutorial, |
| 72 | + cookieName: 'isSkipScrollInSyncTutorial', |
| 73 | + }, |
| 74 | + { |
| 75 | + tutorial: backButtonTutorial, |
| 76 | + cookieName: 'isSkipBackButtonPersistsDataTutorial', |
| 77 | + }, |
| 78 | + ], |
| 79 | + '/': [ |
| 80 | + { |
| 81 | + tutorial: labelsTutorial, |
| 82 | + cookieName: 'isSkipTutorial', |
| 83 | + }, |
| 84 | + ], |
| 85 | +} |
| 86 | + |
| 87 | +export default async function showTutorials( |
| 88 | + cookies: Record<string, boolean>, |
| 89 | + route: string, |
| 90 | + isDarkMode: boolean |
| 91 | +) { |
| 92 | + const { default: Driver } = await import('driver.js') |
| 93 | + const possibleTutorialsToShow = tutorialsMetadata[route] |
| 94 | + let finalTutorial: Tutorial[] = [] |
| 95 | + const cookiesToSet: string[] = [] |
| 96 | + const driver = new Driver({ |
| 97 | + closeBtnText: 'Skip', |
| 98 | + className: 'dark:filter dark:invert', |
| 99 | + stageBackground: isDarkMode ? 'hsl(221deg 50% 90% / 0.5)' : '#ffffff', |
| 100 | + onReset: () => { |
| 101 | + cookiesToSet.forEach((x) => { |
| 102 | + document.cookie = `${x}=true; max-age=31536000; path=/;` |
| 103 | + }) |
| 104 | + }, |
| 105 | + }) |
| 106 | + possibleTutorialsToShow.forEach((x) => { |
| 107 | + if (!cookies[x.cookieName]) { |
| 108 | + finalTutorial = finalTutorial.concat(x.tutorial) |
| 109 | + cookiesToSet.push(x.cookieName) |
| 110 | + } |
| 111 | + }) |
| 112 | + driver.defineSteps(finalTutorial) |
| 113 | + driver.start() |
| 114 | +} |
0 commit comments