Skip to content

Commit 26cf761

Browse files
committed
refactor(tutor-setup): clean up loading animation and optimize code
Remove unused `isLoadingTextLooping` state variable and related checks in the loading animation logic. Cache the sample course import flag to avoid repeated form data lookups. Add a 2-second delay before fading out the loading screen.
1 parent b86da08 commit 26cf761

1 file changed

Lines changed: 4 additions & 6 deletions

File tree

assets/src/js/admin-dashboard/tutor-setup.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ document.addEventListener('DOMContentLoaded', () => {
5757
const loadingTextElement = onboardWrapper.querySelector('.tutor-onboard-loading-text');
5858
const loadingText = loadingTextElement?.dataset.text || loadingTextElement?.textContent?.trim() || '';
5959
let loadingTextTimer = null;
60-
let isLoadingTextLooping = false;
6160
let isSubmitting = false;
6261

6362
const handleReloadHotkeys = (event) => {
@@ -87,8 +86,6 @@ document.addEventListener('DOMContentLoaded', () => {
8786
};
8887

8988
const stopLoadingTextAnimation = () => {
90-
isLoadingTextLooping = false;
91-
9289
if (loadingTextTimer) {
9390
clearTimeout(loadingTextTimer);
9491
loadingTextTimer = null;
@@ -105,10 +102,9 @@ document.addEventListener('DOMContentLoaded', () => {
105102
}
106103

107104
let dotsCount = 0;
108-
isLoadingTextLooping = true;
109105

110106
const animateDots = () => {
111-
if (!loadingTextElement || !isLoadingTextLooping) {
107+
if (!loadingTextElement) {
112108
return;
113109
}
114110

@@ -194,6 +190,7 @@ document.addEventListener('DOMContentLoaded', () => {
194190
const loadingScreen = submitButton?.dataset.screen || __('Loading...', 'tutor');
195191
isSubmitting = true;
196192
toggleReloadProtection(true);
193+
const loadSampleCourse = formData.get('tutor_onboard_load_sample_course');
197194

198195
if (submitButton) {
199196
submitButton.disabled = true;
@@ -203,7 +200,7 @@ document.addEventListener('DOMContentLoaded', () => {
203200
const loadingTextAnimation = startLoadingTextAnimation();
204201

205202
try {
206-
if (formData.get('tutor_onboard_load_sample_course')) {
203+
if (loadSampleCourse) {
207204
const importSuccess = await importSampleCourses();
208205
if (!importSuccess) {
209206
tutor_toast(__('Sample course import failed.', 'tutor'), '', 'error');
@@ -228,6 +225,7 @@ document.addEventListener('DOMContentLoaded', () => {
228225
submitButton.disabled = false;
229226
}
230227
await loadingTextAnimation;
228+
await wait(2000);
231229
await fadeOutLoadingScreen();
232230
toggleReloadProtection(false);
233231
location.href = _tutorOnboardObject.tutor_welcome_page;

0 commit comments

Comments
 (0)