Skip to content

Commit d085d84

Browse files
committed
fix(tutorial): tutorial is shown even after cookie is dropped
but since cookie injector does not refresh on cookie value change
1 parent 5d5c7c7 commit d085d84

File tree

4 files changed

+43
-36
lines changed

4 files changed

+43
-36
lines changed

components/diffActionBar.vue

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,10 @@ import ToggleInSync from './buttons/toggleInSync.vue'
3737
import NextDiff from './buttons/nextDiff.vue'
3838
import CopyLink from './buttons/copyLink.vue'
3939
import { putToClipboard } from '~/helpers/utils'
40-
interface Data {
41-
comparator: HTMLElement | null
42-
comparer: HTMLElement | null
43-
copied: Boolean
44-
treeWalker: TreeWalker | null
45-
}
40+
import { DiffActionBarData } from '~/helpers/types'
4641
export default Vue.extend({
4742
components: { PrevDiff, NextDiff, ToggleInSync, CopyLink },
48-
data(): Data {
43+
data(): DiffActionBarData {
4944
return {
5045
copied: false,
5146
comparator: null,

helpers/driverjsTutorials.ts

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
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-
1+
import { Cookies, Tutorial, TutorialsMetadata, TutorialMetadata } from './types'
2+
// Need this to keep track of latest value of cookie otherwise users sees same tutorial untill they refresh the page after the cookie is dropped
3+
const _cookies: Partial<Cookies> = {}
164
const labelsTutorial: Tutorial[] = [
175
{
186
element: '#lhsLabel',
@@ -100,28 +88,29 @@ const tutorialsMetadata: TutorialsMetadata = {
10088
}
10189

10290
export default async function showTutorials(
103-
cookies: Record<string, boolean>,
91+
cookies: Cookies,
10492
route: string,
10593
isDarkMode: boolean
10694
) {
10795
const { default: Driver } = await import('driver.js')
108-
const possibleTutorialsToShow = tutorialsMetadata[route]
96+
const possibleTutorialsToShow: TutorialMetadata[] = tutorialsMetadata[route]
10997
let finalTutorial: Tutorial[] = []
110-
const cookiesToSet: string[] = []
98+
const cookiesToSet: TutorialMetadata[] = []
11199
const driver = new Driver({
112100
closeBtnText: 'Skip',
113101
className: 'dark:filter dark:invert',
114102
stageBackground: isDarkMode ? 'hsl(221deg 50% 90% / 0.5)' : '#ffffff',
115103
onReset: () => {
116-
cookiesToSet.forEach((x) => {
117-
document.cookie = `${x}=true; max-age=31536000; path=/;`
104+
cookiesToSet.forEach((x: TutorialMetadata) => {
105+
_cookies[x.cookieName] = true
106+
document.cookie = `${x.cookieName}=true; max-age=31536000; path=/;`
118107
})
119108
},
120109
})
121110
possibleTutorialsToShow.forEach((x) => {
122-
if (!cookies[x.cookieName]) {
111+
if (!cookies[x.cookieName] && !_cookies[x.cookieName]) {
123112
finalTutorial = finalTutorial.concat(x.tutorial)
124-
cookiesToSet.push(x.cookieName)
113+
cookiesToSet.push(x)
125114
}
126115
})
127116
if (finalTutorial.length) {

helpers/types.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
export interface Cookies {
2+
isDarkMode: boolean
3+
isSkipTutorial: boolean
4+
isSkipScrollInSyncTutorial: boolean
5+
isSkipBackButtonPersistsDataTutorial: boolean
6+
isSkipSubmitKbdShortcutTutorial: boolean
7+
}
8+
9+
export interface Tutorial {
10+
element: string
11+
popover: {
12+
title: string
13+
description: string
14+
}
15+
}
16+
17+
export interface TutorialMetadata {
18+
tutorial: Tutorial[]
19+
cookieName: keyof Cookies
20+
}
21+
22+
export type TutorialsMetadata = Record<string, TutorialMetadata[]>
23+
24+
export interface DiffActionBarData {
25+
comparator: HTMLElement | null
26+
comparer: HTMLElement | null
27+
copied: Boolean
28+
treeWalker: TreeWalker | null
29+
}

plugins/cookie-injector.client.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,8 @@ import isSkipTutorialCookie from '~/helpers/isSkipTutorialCookie'
44
import isSkipScrollInSyncTutorial from '~/helpers/isSkipScrollInSyncTutorial'
55
import isSkipBackButtonPersistsDataTutorial from '~/helpers/isSkipBackButtonPersistsDataTutorial'
66
import isSkipSubmitKbdShortcutTutorial from '~/helpers/isSkipSubmitKbdShortcutTutorial'
7+
import { Cookies } from '~/helpers/types'
78

8-
interface Cookies {
9-
isDarkMode: boolean
10-
isSkipTutorial: boolean
11-
isSkipScrollInSyncTutorial: boolean
12-
isSkipBackButtonPersistsDataTutorial: boolean
13-
isSkipSubmitKbdShortcutTutorial: boolean
14-
}
159
declare module 'vue/types/vue' {
1610
interface Vue {
1711
$cookies: Cookies

0 commit comments

Comments
 (0)