Skip to content

Commit 38fdebd

Browse files
committed
suggestions by @sisou
- Renamed some vars - Refactored some code - Reestructured lifecycle and steps
1 parent 6d2e05c commit 38fdebd

File tree

9 files changed

+254
-154
lines changed

9 files changed

+254
-154
lines changed

src/App.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ export default defineComponent({
4949
5050
const { activeMobileColumn } = useActiveMobileColumn();
5151
52-
const { accountInfos, state: accountState, removeTour } = useAccountStore();
52+
const { accountInfos, state: accountState, setTour } = useAccountStore();
5353
if (!['root', 'transactions'].includes(context.root.$route.name as string)
54-
&& accountState.tour?.name === 'onboarding') {
55-
removeTour();
54+
&& accountState.tour === 'onboarding') {
55+
setTour(null);
5656
}
5757
const showTour = computed(() => !!accountState.tour);
5858

src/components/BtcTransactionList.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
</RecycleScroller>
6363

6464
<div v-else-if="!searchString" class="empty-state flex-column">
65-
<h2 class="nq-h1">{{ $t('Nothing here yet') }}</h2>
65+
<h2 class="nq-h1">{{ $t('Your transactions will appear here') }}</h2>
6666
<!-- <span>{{ $t('Receive some free NIM to get started.') }}</span>
6767
6868
<a v-if="isMainnet"

src/components/Tour.vue

Lines changed: 50 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
<button @click="tour.previousStep" v-if="!isMobile">
3535
{{ $t("Previous step") }}
3636
</button>
37-
<button class="right" @click="alert"
37+
<button class="right" @click="tour.steps[tour.currentStep].button.fn()"
3838
v-if="tour.steps[tour.currentStep].button">
3939
{{ $t(tour.steps[tour.currentStep].button.text) }}
4040
</button>
@@ -48,7 +48,7 @@
4848
</template>
4949
</v-tour>
5050
<transition name="fade">
51-
<div class="tour-control-bar">
51+
<div class="tour-control-bar" v-if="isMobile">
5252
<button @click="endTour()">
5353
{{ $t("End Tour") }}
5454
</button>
@@ -117,17 +117,23 @@ export default defineComponent({
117117
() => $network.consensus !== 'established',
118118
);
119119
120-
const { state: tourStore, removeTour } = useAccountStore();
120+
const { state: tourStore, setTour } = useAccountStore();
121121
122122
let tour: VueTour.Tour | null = null;
123123
const steps: TourSteps<any> = useTour(tourStore.tour, context) || {};
124124
125125
// Initial state
126126
const loading = ref(true);
127-
const currentStep: Ref<TourStepIndex> = ref(8);
127+
const currentStep: Ref<TourStepIndex> = ref(0);
128128
const nSteps: Ref<number> = ref(0);
129129
const disableNextStep = ref(true);
130130
131+
let unmounted: (
132+
(args?: { goingForward: boolean, ending?: boolean }) => Promise<null>)
133+
| Promise<null>
134+
| ((args?: { goingForward: boolean, ending?: boolean }) => null)
135+
| null = null;
136+
131137
onMounted(() => {
132138
tourSetup();
133139
@@ -137,14 +143,22 @@ export default defineComponent({
137143
});
138144
139145
async function tourSetup() {
146+
await context.root.$nextTick(); // to ensure the DOM is ready
147+
140148
// Update state
141149
nSteps.value = Object.keys(steps).length;
142150
disableNextStep.value = currentStep.value >= nSteps.value - 1
143-
|| !!steps[currentStep.value].ui.disabledNextStep;
151+
|| !!steps[currentStep.value].ui.isNextStepDisabled;
152+
153+
if (steps[currentStep.value].lifecycle?.created) {
154+
await steps[currentStep.value].lifecycle!.created!({ goToNextStep, goingForward: true });
155+
}
144156
145157
_addAttributes(steps[currentStep.value].ui, currentStep.value);
146-
// eslint-disable-next-line no-unused-expressions
147-
steps[currentStep.value].lifecycle?.onMountedStep?.(goToNextStep);
158+
159+
if (steps[currentStep.value].lifecycle?.mounted) {
160+
unmounted = await steps[currentStep.value].lifecycle!.mounted!({ goToNextStep, goingForward: true });
161+
}
148162
149163
if (context.root.$route.path !== steps[currentStep.value].path) {
150164
context.root.$router.push(steps[currentStep.value].path);
@@ -163,11 +177,9 @@ export default defineComponent({
163177
const app = document.querySelector('#app main') as HTMLDivElement;
164178
165179
if (loading.value || disconnected.value) {
166-
// eslint-disable-next-line no-unused-expressions
167-
app?.setAttribute('data-non-interactable', '');
180+
app!.setAttribute('data-non-interactable', '');
168181
} else {
169-
// eslint-disable-next-line no-unused-expressions
170-
app?.removeAttribute('data-non-interactable');
182+
app!.removeAttribute('data-non-interactable');
171183
}
172184
});
173185
@@ -189,19 +201,21 @@ export default defineComponent({
189201
) {
190202
const goingForward = futureStepIndex > currentStepIndex;
191203
192-
const { path: currentPage, lifecycle: currentLifecycle } = steps[currentStepIndex];
204+
const { path: currentPage } = steps[currentStepIndex];
193205
const { path: futurePage, ui: futureUI, lifecycle: futureLifecycle } = steps[futureStepIndex];
194206
195207
loading.value = true;
196208
tour!.stop();
197-
await sleep(500);
198209
199-
// changePage
200-
if (!goingForward && currentLifecycle && currentLifecycle.prepareDOMPrevPage) {
201-
await currentLifecycle.prepareDOMPrevPage();
202-
} else if (goingForward && currentLifecycle && currentLifecycle.prepareDOMNextPage) {
203-
await currentLifecycle.prepareDOMNextPage();
204-
} else if (futurePage !== currentPage) {
210+
if (unmounted) {
211+
await (await unmounted)!({ goingForward });
212+
}
213+
214+
if (futureLifecycle?.created) {
215+
await (futureLifecycle.created!)({ goToNextStep, goingForward });
216+
}
217+
218+
if (futurePage !== currentPage && context.root.$route.fullPath !== futurePage) {
205219
try {
206220
// Default prepare DOM
207221
context.root.$router.push(futurePage);
@@ -224,30 +238,32 @@ export default defineComponent({
224238
// FIXME Instead of doing tour!.end and tour!.start, we could also use .nextStep() or previsousStep()
225239
// The problem with this solution is that some animations glitch the UI so it needs further
226240
// investigation
227-
// eslint-disable-next-line no-unused-expressions
228241
// goingForward ? tour!.nextStep() : tour!.previousStep();
229242
230243
// onMountedStep
231244
loading.value = false;
232-
disableNextStep.value = futureStepIndex >= nSteps.value - 1 || !!futureUI.disabledNextStep;
245+
disableNextStep.value = futureStepIndex >= nSteps.value - 1 || !!futureUI.isNextStepDisabled;
233246
234-
// eslint-disable-next-line no-unused-expressions
235-
futureLifecycle?.onMountedStep?.(goToNextStep);
247+
if (futureLifecycle?.mounted) {
248+
unmounted = await futureLifecycle!.mounted!({ goToNextStep, goingForward });
249+
} else {
250+
unmounted = null;
251+
}
236252
237253
currentStep.value = futureStepIndex;
238254
}
239255
240256
function _addAttributes(uiConfig: TourStep['ui'], stepIndex: TourStepIndex) {
241-
const elementsWithOpacity = uiConfig.elementsWithOpacity || [];
242-
const elementsWithoutInteractivity = uiConfig.elementsWithoutInteractivity || [];
257+
const fadedElements = uiConfig.fadedElements || [];
258+
const disabledElements = uiConfig.disabledElements || [];
243259
244-
elementsWithoutInteractivity.forEach((element) => {
260+
disabledElements.forEach((element) => {
245261
const el = document.querySelector(element);
246262
if (!el) return;
247263
el.setAttribute('data-non-interactable', stepIndex.toString());
248264
});
249265
250-
elementsWithOpacity.forEach((element) => {
266+
fadedElements.forEach((element) => {
251267
const el = document.querySelector(element);
252268
if (!el) return;
253269
el.setAttribute('data-opacified', stepIndex.toString());
@@ -265,14 +281,18 @@ export default defineComponent({
265281
});
266282
}
267283
268-
function endTour() {
284+
async function endTour() {
269285
_removeAttributes(currentStep.value);
270286
271-
// If user finalizes tour while it is loading, allow then interaction
287+
if (unmounted) {
288+
await (await unmounted)!({ ending: true, goingForward: false });
289+
}
290+
291+
// If user finalizes tour while it is loading, allow interaction again
272292
const app = document.querySelector('#app main') as HTMLDivElement;
273293
app.removeAttribute('data-non-interactable');
274294
275-
removeTour();
295+
setTour(null);
276296
}
277297
278298
// TODO REMOVE ME - Simulate tx

src/components/TransactionList.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
</RecycleScroller>
7272

7373
<div v-else-if="!searchString" class="empty-state flex-column">
74-
<h2 class="nq-h1">{{ $t('Nothing here yet') }}</h2>
74+
<h2 class="nq-h1">{{ $t('Your transactions will appear here') }}</h2>
7575
<span>{{ $t('Receive some free NIM to get started.') }}</span>
7676

7777
<a v-if="isMainnet"
Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
<template>
2-
<svg width="99" height="95" viewBox="0 0 99 95" fill="none" xmlns="http://www.w3.org/2000/svg">
3-
<path d="M87.3427 19H88.1111C88.9702 19 89.6667 19.7462 89.6667 20.6667V21.5C89.6667 22.8807 90.7113 24 92 24C93.2887 24 94.3333 22.8807 94.3333 21.5V20.6667C94.3333 19.7462 95.0298 19 95.8889 19H96.6667C97.9553 19 99 17.8807 99 16.5C99 15.1193 97.9553 14 96.6667 14H95.8889C95.0298 14 94.3333 13.2538 94.3333 12.3333V11.5C94.3333 10.1193 93.2887 9 92 9C90.7113 9 89.6667 10.1193 89.6667 11.5V12.3333C89.6667 13.2538 88.9702 14 88.1111 14H87.3333C86.0447 14 85 15.1193 85 16.5C85 17.8807 86.0447 19 87.3333 19H87.3427Z" fill="#21BCA5"/>
4-
<path d="M88.676 36.6667H87.8889V36.6667C87.0298 36.6667 86.3333 35.9702 86.3333 35.1111V35.1111V34.3333C86.3333 33.0447 85.2887 32 84 32C82.7113 32 81.6667 33.0447 81.6667 34.3333V35.1111C81.6667 35.9702 80.9702 36.6667 80.1111 36.6667H79.3333V36.6667C78.0447 36.6667 77 37.7113 77 39C77 40.2887 78.0447 41.3333 79.3333 41.3333H80.1111V41.3333C80.9702 41.3333 81.6667 42.0298 81.6667 42.8889V43.6667V43.6667C81.6667 44.9553 82.7113 46 84 46C85.2887 46 86.3333 44.9553 86.3333 43.6667V42.8889V42.8889C86.3333 42.0298 87.0298 41.3333 87.8889 41.3333H88.6667V41.3333C89.9553 41.3333 91 40.2887 91 39C91 37.7113 89.9553 36.6667 88.6667 36.6667H88.676Z" fill="#21BCA5"/>
5-
<path d="M73.6 9.99999V9.99999C69.6257 9.99448 66.4053 6.63986 66.4 2.5C66.4 1.11929 65.3255 0 64 0C62.6745 0 61.6 1.11929 61.6 2.5V2.50005C61.5947 6.63991 58.3742 9.99451 54.4 10V10C53.0745 10 52 11.1193 52 12.5C52 13.8807 53.0745 15 54.4 15V15C58.3743 15.0055 61.5947 18.3601 61.6 22.5V22.5C61.6 23.8807 62.6745 25 64 25C65.3255 25 66.4 23.8807 66.4 22.5V22.5C66.4053 18.3601 69.6258 15.0055 73.6 15V15C74.9255 15 76 13.8807 76 12.5C76 11.1193 74.9255 9.99999 73.6 9.99999L73.6 9.99999ZM65.6704 13.1267V13.1267C65.2921 13.4741 64.9351 13.8459 64.6016 14.24V14.24C64.3104 14.5861 63.8049 14.6207 63.4727 14.3174C63.4463 14.2933 63.4215 14.2674 63.3984 14.24V14.24C63.0649 13.8459 62.7079 13.4741 62.3296 13.1267V13.1267C61.9974 12.8233 61.9641 12.2968 62.2553 11.9507C62.2784 11.9232 62.3033 11.8974 62.3296 11.8733V11.8733C62.7079 11.5259 63.0649 11.1541 63.3984 10.76V10.76C63.6896 10.4139 64.1951 10.3793 64.5273 10.6826C64.5537 10.7067 64.5785 10.7325 64.6016 10.76V10.76C64.9351 11.1541 65.2921 11.5259 65.6704 11.8733V11.8733C66.0026 12.1767 66.0359 12.7032 65.7447 13.0493C65.7216 13.0767 65.6968 13.1026 65.6704 13.1267V13.1267Z" fill="#21BCA5"/>
6-
<path d="M21.889 19.5625L19.296 18.0536L19.2938 18.0576L21.889 19.5625ZM3.98473 50.4375L6.57766 51.9464L6.57995 51.9424L3.98473 50.4375ZM3.98473 57.5625L6.57995 56.0575L6.57765 56.0536L3.98473 57.5625ZM21.889 88.4375L19.2938 89.9425L19.296 89.9464L21.889 88.4375ZM70.111 88.4375L72.704 89.9464L72.7063 89.9425L70.111 88.4375ZM88.3725 62.9268C89.2036 61.4935 88.7155 59.6578 87.2822 58.8267C85.8489 57.9955 84.0132 58.4836 83.182 59.9169L88.3725 62.9268ZM38 19C39.6569 19 41 17.6569 41 16C41 14.3431 39.6569 13 38 13V19ZM28.0958 13C24.5509 13 21.1611 14.8486 19.296 18.0536L24.4819 21.0714C25.2428 19.7639 26.6274 19 28.0958 19V13ZM19.2938 18.0576L1.38952 48.9326L6.57995 51.9424L24.4842 21.0674L19.2938 18.0576ZM1.39181 48.9286C-0.463938 52.1176 -0.463938 55.8824 1.39181 59.0714L6.57765 56.0536C5.80745 54.7301 5.80745 53.2699 6.57765 51.9464L1.39181 48.9286ZM1.38952 59.0674L19.2938 89.9425L24.4842 86.9325L6.57995 56.0576L1.38952 59.0674ZM19.296 89.9464C21.1611 93.1514 24.5509 95 28.0958 95V89C26.6274 89 25.2428 88.2361 24.4819 86.9286L19.296 89.9464ZM28.0958 95H63.9042V89H28.0958V95ZM63.9042 95C67.4491 95 70.8389 93.1514 72.704 89.9464L67.5181 86.9286C66.7572 88.2361 65.3726 89 63.9042 89V95ZM38 13H28.0958V19H38V13ZM72.7063 89.9425L88.3725 62.9268L83.182 59.9169L67.5158 86.9325L72.7063 89.9425Z" fill="#21BCA5"/>
7-
</svg>
2+
<svg width="99" height="95" fill="none" xmlns="http://www.w3.org/2000/svg">
3+
<path d="M87.343 19h.768c.86 0 1.556.746 1.556 1.667v.833c0 1.38 1.044 2.5 2.333 2.5 1.289 0 2.333-1.12 2.333-2.5v-.833c0-.92.697-1.667 1.556-1.667h.778C97.955 19 99 17.88 99 16.5S97.955 14 96.667 14h-.778c-.86 0-1.556-.746-1.556-1.667V11.5C94.333 10.12 93.29 9 92 9c-1.289 0-2.333 1.12-2.333 2.5v.833c0 .92-.697 1.667-1.556 1.667h-.778C86.045 14 85 15.12 85 16.5s1.045 2.5 2.333 2.5h.01ZM88.676 36.667h-.787c-.86 0-1.556-.697-1.556-1.556v-.778a2.333 2.333 0 1 0-4.666 0v.778c0 .86-.697 1.556-1.556 1.556h-.778a2.333 2.333 0 1 0 0 4.666h.778c.86 0 1.556.697 1.556 1.556v.778a2.333 2.333 0 1 0 4.666 0v-.778c0-.86.697-1.556 1.556-1.556h.778a2.333 2.333 0 1 0 0-4.666h.009ZM73.6 10c-3.974-.006-7.195-3.36-7.2-7.5C66.4 1.12 65.325 0 64 0s-2.4 1.12-2.4 2.5c-.005 4.14-3.226 7.495-7.2 7.5-1.325 0-2.4 1.12-2.4 2.5s1.075 2.5 2.4 2.5c3.974.005 7.195 3.36 7.2 7.5 0 1.38 1.075 2.5 2.4 2.5 1.326 0 2.4-1.12 2.4-2.5.005-4.14 3.226-7.495 7.2-7.5 1.326 0 2.4-1.12 2.4-2.5S74.925 10 73.6 10Zm-7.93 3.127c-.378.347-.735.719-1.068 1.113a.778.778 0 0 1-1.204 0 12.29 12.29 0 0 0-1.068-1.113.858.858 0 0 1 0-1.254c.378-.347.735-.719 1.068-1.113a.778.778 0 0 1 1.204 0c.333.394.69.766 1.068 1.113a.858.858 0 0 1 0 1.254ZM21.889 19.563l-2.593-1.51-.002.005 2.595 1.505ZM3.985 50.438l2.593 1.508.002-.004-2.595-1.505Zm0 7.124 2.595-1.505-.002-.003-2.593 1.508Zm17.904 30.876-2.595 1.504.002.004 2.593-1.508Zm48.222 0 2.593 1.508.002-.004-2.595-1.504Zm18.261-25.511a3 3 0 0 0-5.19-3.01l5.19 3.01ZM38 19a3 3 0 1 0 0-6v6Zm-9.904-6a10.17 10.17 0 0 0-8.8 5.054l5.186 3.017A4.17 4.17 0 0 1 28.096 19v-6Zm-8.802 5.058L1.39 48.933l5.19 3.01 17.904-30.876-5.19-3.01ZM1.392 48.928c-1.856 3.19-1.856 6.954 0 10.143l5.186-3.017c-.77-1.324-.77-2.784 0-4.108L1.392 48.93Zm-.002 10.14 17.904 30.874 5.19-3.01L6.58 56.059l-5.19 3.01Zm17.906 30.878a10.17 10.17 0 0 0 8.8 5.054v-6a4.17 4.17 0 0 1-3.614-2.071l-5.186 3.017Zm8.8 5.054h35.808v-6H28.096v6Zm35.808 0a10.17 10.17 0 0 0 8.8-5.054l-5.186-3.017A4.17 4.17 0 0 1 63.904 89v6ZM38 13h-9.904v6H38v-6Zm34.706 76.942 15.666-27.015-5.19-3.01-15.666 27.016 5.19 3.01Z" fill="currentColor"/>
4+
</svg>
85
</template>

src/components/modals/Modal.vue

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<div class="swipe-bar"></div>
1010
</div>
1111
<slot/>
12-
<CloseButton v-if="showCloseIcon" class="top-right" :class="{'inverse': closeButtonInverse}" @click="close"/>
12+
<CloseButton v-if="showCloseButton" class="top-right" :class="{'inverse': closeButtonInverse}" @click="close"/>
1313
<transition name="fade">
1414
<div v-if="showOverlay" class="cover"></div>
1515
</transition>
@@ -64,14 +64,12 @@ export default defineComponent({
6464
type: Boolean,
6565
default: true,
6666
},
67-
showCloseIcon: {
67+
showCloseButton: {
6868
type: Boolean,
6969
default: true,
7070
},
7171
},
7272
setup(props, context) {
73-
const { showCloseIcon } = props;
74-
7573
function close() {
7674
if (props.showOverlay) {
7775
context.emit('close-overlay');

src/components/modals/StartOnBoardingTourModal.vue

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<Modal class="start-onboarding-tour-modal" :showCloseIcon="false">
2+
<Modal class="start-onboarding-tour-modal" :showCloseButton="false">
33
<!-- TODO: Add nimiq SVG logo in the background -->
44

55
<!-- TODO: Add language selector and dark mode switcher -->
@@ -32,6 +32,7 @@
3232
</template>
3333

3434
<script lang="ts">
35+
import { useAccountStore } from '@/stores/Account';
3536
import { PageHeader } from '@nimiq/vue-components';
3637
import { defineComponent } from '@vue/composition-api';
3738
import GreenNimiqLogoOutlineWithStars from '../icons/GreenNimiqLogoOutlineWithStars.vue';
@@ -40,15 +41,9 @@ import Modal from './Modal.vue';
4041
export default defineComponent({
4142
setup(props, context) {
4243
function startTour() {
43-
context.root.$router.push({
44-
name: 'root',
45-
params: {
46-
// It has to be a string since it is a value encapsulated in Location.params
47-
// which is Dictionary<string>. Using a 'false' value will lead to the same
48-
// behaviour
49-
doOnboardingTour: 'true',
50-
},
51-
});
44+
const { setTour } = useAccountStore();
45+
setTour('onboarding');
46+
context.root.$router.push('/');
5247
}
5348
5449
return {
@@ -81,6 +76,10 @@ export default defineComponent({
8176
align-items: center;
8277
max-width: 175px;
8378
79+
::v-deep svg {
80+
color: var(--nimiq-green);
81+
}
82+
8483
// TODO Add correct dimensions
8584
8685
p {

0 commit comments

Comments
 (0)